I have a problem with my pagination system (wordpress). It's on my search page (display results), currently, the search system include only 2 post types, and the search system works fine, but clearly impossible to create a pagination system. I just want to create a simple previous and next page nav with the number of the current page.
<div class="contenu cont-menu fixed-cont aff">
<div class="page p-spe">Résults :
<span class="blue"><?php the_search_query(); ?></span></div>
<div class="nombre"><?php global $wp_query; echo ' ' .
$wp_query->found_posts . ' Result(s)'; ?></div>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<article class="article-menu">
<div class="article-menu a-m-sp">
<a href="<?php the_permalink(); ?>">
<span class="rollover r2"> </span>
<?php the_post_thumbnail(array(226,150)); ?>
</a>
<div class="right p-special">
<h2 class="h2-article-menu h2-ma"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?></a></h2>
<p class="date"><?php the_time('j F Y'); ?></p>
<?php the_excerpt(); ?>
Know more
</div>
</div>
<div class="sep sp-s"> </div>
</article>
<?php endwhile; ?>
<nav class="nav-pages">
<?php previous_posts_link('« Previous') ?>
<span class="nombre-pages"><?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
echo $paged.' / '.$wp_query->max_num_pages;
?></span>
<?php next_posts_link('Next »') ?>
</nav>
<?php
$wp_query = null;
$wp_query = $temp; // Reset
?>
<?php else : ?>
<div class="aucun-resultat">
<?php _e( 'No results' ); ?>
</div>
<?php endif; ?>
<?php
get_footer();
?>
So i add the pages nav just after the endwhile of the search results. I don't know why my system doesn't work. I'm a wordpress beginner, thank you for your help. Bernard
You don't need a custom query for this. Just add paginate_links() which generates pagination with arrows and numbers (can be configured to display as you wish).
http://codex.wordpress.org/Function_Reference/paginate_links
I update my post, because I made a pagination for 1 post type and It works fine. But now I would like to do a pagination of 2 post types. How i can change this code to make it works ?
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('showposts=4&post_type=dossiers'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
Related
I cannot get my posts to display on a category page.
It finds if the posts are within and category and displays content fine.. But the loop I am using does not bring in the posts.. Any help would be great.
<?php if (is_category(array(4, 5, 6))) { ?>
<?php if (have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>
<div class="case-study-box">
<a href="<?php the_permalink(); ?>">
<div class="post-img ripple-me" style="background-image: url(<?php the_field('thumbnail_image'); ?>)">
</div>
</a>
<div class="post-intro">
<span><?php the_category(' '); ?></span>
<?php the_title('<h4>', '</h4>'); ?>
Read more
</div>
</div>
<!--Close .case-study-box -->
<?php endwhile; else: ?>
<?php endif; ?>
<?php } else { ?>
I have a website that on the homepage contains images/sliders standard page content etc. Once the page loads, it scrolls nice and smoothly. But I have a section about half way down that queries and displays WordPress Posts (see code below). When I view it in Google Chrome, while scrolling in that section, the website becomes laggy/skips and doesn't smoothy scroll like the rest of the home page.
Is there a way or something to include that will have WordPress query the posts faster or better or is there another reason as to why scrolling in that section becomes laggy?
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('no_found_rows=true&showposts=6&post_status=publish' . '&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="newspagearticle full">
<div class="newsthumb">
<?php the_post_thumbnail( 'category-thumb' ); ?>
</div>
<div class="homenewsheader">
<div class="newsdate">
<div><?php the_time('M') ?></div>
<?php the_time('d'); ?>
</div>
<h2>
<a class="readmore" href="<?php the_permalink() ?>">
<?php
$thetitle = $post->post_title; /* or you can use get_the_title() */
$getlength = strlen($thetitle);
$thelength = 200;
echo substr($thetitle, 0, $thelength);
if ($getlength > $thelength) echo "...";
?>
</a>
</h2>
</div>
<div style="clear:both;"></div>
<?php the_excerpt(); ?>
</div><!-- /newspagearticle -->
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
I'm building a theme and on my category.php page I want to show several full posts (let's say 3, but need to be able to change this to 2 or 1 easily), and then the rest of the posts in the category as title links.
I have quite a bit of HTML in my loop for styling my posts and adding custom fields so sorry about all the code, but this is what my category.php page looks like now. I've tried a few things that haven't worked so have edited this to show my original code which just has a normal list of posts. I'm somewhat new to editing The Loop so would appreciate as much explanation/clarity as possible.
<?php
/**
* The template for displaying Category Archive pages.
*/
get_header(); ?>
<div id="primary" class="<?php
$category = get_the_category();
echo $category[0]->cat_name;
?>">
<div id="feature-container" class="full-width-container">
<div class="full-width-container content-page" id="tagline-wrapper">
<div id="left-black"></div>
<div class="page-width-container">
<div id="tagline-box">
<h1 class="category-title">Transactions</h1>
</div>
</div>
</div>
</div>
<div id="content-wrapper">
<div id="project-menu" class="page-width-container">
<?php wp_nav_menu( array( 'theme_location' => 'project-types' ) ); ?>
</div>
<div id="content" role="main" >
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="story-container" class="module-container">
<div class="our-story">
<div class="story-image">
<?php
// check if the post has a Post Thumbnail assigned to it.
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
</div>
<div class="story-text">
<article class="post" id="post-<?php the_ID(); ?>">
<div class="entry-container">
<h2><?php the_title(); ?></h2>
<div class="project-details">
<p><span class="details-location"><?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, '_project-location', true);
wp_reset_query();
?></span><br />
<span class="details-funding"><?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, '_funding-type', true);
wp_reset_query();
?> | <?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, '_funding-source', true);
wp_reset_query();
?></span><br />
<span class="details-value"><?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, '_project-value', true);
wp_reset_query();
?></span></p>
</div>
<div class="entry">
<?php the_content(); ?>
<?php wp_link_pages(array('before' => __('Pages: ','html5reset'), 'next_or_number' => 'number')); ?>
</div>
<?php edit_post_link(__('Edit this entry','html5reset'), '<p>', '</p>'); ?>
</div>
</article>
</div>
</div>
</div>
<?php endwhile; endif; ?>
</div><!-- #content -->
</div>
</div><!-- #primary -->
<?php get_footer(); ?>
You can achive above thing using following code:
First you have to loop all post and and put counter when it reach more then 2 its stop to print a content.but title will be there always.
<?php $countPost=1;?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post">
<h2 id="post-<?php the_ID(); ?>">
<?php the_title(); ?></h2>
<?php if($countPost>2) : /*Condition for Content*/
the_content();
endif;
?>
</div>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft">
<?php posts_nav_link('','','« Previous Entries') ?>
</div>
<div class="alignright">
<?php posts_nav_link('','Next Entries »','') ?>
</div>
</div>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center"><?php _e("Sorry, but you are looking for something that isn't here."); ?></p>
<?php endif; ?>
</div>
For more details please refer :
https://codex.wordpress.org/The_Loop_in_Action
I figured out a bit of a workaround solution on my own, although it relies on using plugins/widgets which isn't what I'd prefer.
I simply set the Reading settings to display 2 posts, and then below the Loop I added a widget area and used the Recent Posts Extended widget to display a list of titles/links. This widget allows you to skip a certain amount of posts in the list, so I set it to start at post #3. There was no option to show posts from the current category only, so I had to use the Widget Context plugin as well and make individual widgets with a specific category to show on each corresponding category page. As I said, a bit of a convoluted solution, but the end result is exactly what I wanted to achieve.
I created a page template at http://www.durgeshsound.com/gallery/
Here my pagination buttons are not working. this issue arises when permalink format is http://www.testsite.com/sample-post/
But when I set permalink format to default for example http://testsite.com/?p=123 then it starts working
and creates a working pagination link like this http://www.durgeshsound.com/?page_id=81&paged=2.
I want this format http://www.testsite.com/sample-post/ in the links.
here is what i tried for custom page template
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('post_type=gallery&posts_per_page=9&paged=' . $paged); ?>
<?php if (have_posts()) : while (have_posts()) : the_post();
if ( get_post_gallery() ) :
$gallery = get_post_gallery( get_the_ID(), false );
?>
<?php the_post_thumbnail('large'); ?>
<?php the_title( ); ?>
<?php
endif;
endwhile; endif;
?>
<?php kriesi_pagination(); ?>
<?php get_sidebar('gallery'); ?>
<?php get_footer(); ?>
Please help.
Below is custom Page : Replace $cat with your resp. ID
<ul class="clearfix">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$recentPosts = new WP_Query();
$recentPosts->query("cat=$cat&showposts=10&paged=".$paged); ?>
<?php if($recentPosts){ ?>
<?php if ( $recentPosts->have_posts() ): while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<li id="post-<?php the_ID(); ?>" <?php post_class('interview-list'); ?>>
<div class="video-thumb">
<a href="<?php the_permalink(); ?>" rel="bookmark"><?php if(has_post_thumbnail()) {
the_post_thumbnail(array(500,393));
}else {
echo '<img src="'.get_bloginfo("template_url").'/images/no-image.jpg" width="500px" height="393px"/>';
}
?> </a>
</div>
<div class="image-con">
<div class="int-title">
<?php the_title(); ?>
</div>
</div>
</li>
<?php endwhile; ?>
<?php else: ?>
<h2 class="post-title">No Photos</h2>
<?php endif; ?>
<div class="older-link"><?php next_posts_link('« Older Entries', $recentPosts->max_num_pages) ?></div>
<div class="newer-link"><?php previous_posts_link('Newer Entries »') ?></div>
<?php } ?>
</ul>
On both the front page and the blog page - the sidebar shows the most recent post, which I find doesn't look very good duplicated against the same post expanded on the main page.
This is my code for the sidebar:
<div class="blog-sidebar">
<?php query_posts('showposts=5'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="blog-sidebar-feature">
<?php if ( has_post_thumbnail() ) { ?>
<div class="blog-sidebar-image"><?php the_post_thumbnail('medium'); ?></div>
<?php
}
?>
<div class="blog-sidebar-content">
<p class="date"><?php the_time('F j, Y') ?></p>
<h3 <strong><?php
foreach((get_the_category()) as $category) {
echo $category->cat_name . ' ';
}
?></strong></h3>
<h2 <p><a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php the_title();
?></a></p></h2><?php echo get_excerpt(166); ?>
</div>
</div>
<?php endwhile;?>
<br />
<?php wp_pagenavi(); ?>
</div>
and the relevant code for how the blog appears on the home page:
<div class="blog-sidebar">
<div class="blog-sidebar-feature">
<?php query_posts('orderby=date&order=DESC&showposts=2'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php if ( has_post_thumbnail() ) { ?>
<div class="blog-sidebar-image"><?php the_post_thumbnail('medium'); ?></div>
<?php
}
?>
<div class="blog-sidebar-content">
<p class="date"><?php the_time('F j, Y') ?></p>
<h3 <strong><?php
foreach((get_the_category()) as $category) {
echo $category->cat_name . ' ';
}
?></strong></h3>
<h2 <p><a href="<?php the_permalink() ?>"
rel="bookmark" title=""><?php the_title(); ?></a></p></h2><?php echo get_excerpt(166); ?>
</div>
<?php endwhile;?>
</div>
</div>
<div id="connect">
<?php query_posts('page_id=1');
while (have_posts()): the_post();
the_content();
endwhile;
wp_reset_query(); ?>
</div>
Is there any way to remove only the most recent post from the sidebar when it appears in full on the main container? Thanks in advance for any help.
UPDATE V2
So you do want recent posts, just not the post currently showing in the main content.
UPDATE V3:
This should work now. I had to change arguments of query_posts to array to make it work.
Try it now:
<?
global $wp_query;
$skip_posts=array();
if (is_single()) //only exclude posts when single post is shown
$skip_posts[]=$wp_query->post->ID;
?>
<?php query_posts( array( 'showposts'=>5,'post__not_in'=>$skip_posts)); ?>
<?php query_posts('posts_per_page=5&offset=1'); ?>
Thanks to 850010 for all the help, I went back and had a look at the offset rule and the 'array' wasn't needed. Deceptively simple.