I'm have two loops on my index page. One fetches the latest posts from the 'work' category and the other fetches the latest from the 'blog' category. (see below)
I am also using a plugin called WP-PageNavi - /. I only want the pagination on the blog section which I have at the moment and it works fine for that.
The problem is that when I click on to page 2 or 3 on the pagination the 'work' section also goes to the next page but there isnt enough posts so i see the "sorry, no posts" message.
How do i get the pagination to just affect the 'blog' section?
The other problem is that when I goto the 'blog' category page and click on the pagination there (or the 'view older posts', i tried both) it sends me to this url
http://localhost:8888/blog/page/2/
which results in a 404 as it is inserting 'blog' in the url. But if i remove 'blog' so goto
http://localhost:8888/page/2/
It then sends me to the index page and using the pagination on the index page.
If it helps my permalink structure is:
/%category%/%postname%/
Here is my code...
First Loop for 'work' section:
<?php query_posts ($query_string . '&category_name=work'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="grid_4 latest-work">
<?php
// check if the post has a Post Thumbnail assigned to it.
if ( has_post_thumbnail() ) {
the_post_thumbnail('latest-work'); // Other resolutions
} else {
//No featured image supplied so use default.
?>
<img src="<?php bloginfo('template_url'); ?>/img/default.png" width="300" height="200"/>
<?php } ?>
<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
<p class="client-name"><?php $key="client"; echo get_post_meta($post->ID, $key, true); ?></p>
</div>
<!-- Stop The Loop (but note the "else:" - see next line). -->
<?php endwhile; else: ?>
<p class="grid_12" style="margin-top:20px;">Sorry, no posts matched your criteria.</p>
<!-- REALLY stop The Loop. -->
<?php endif; ?>
Second loop for 'Blog' section:
<?php query_posts( array( 'cat' => 6, 'paged' => get_query_var('paged') ) ); ?>
<!-- Start the Loop. -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="what-moves-us" >
<div class="home-blog-content">
<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
<a class="readmore" href="<?php the_permalink() ?>"></a>
</div>
<div class="blog-featured-image">
<?php
// check if the post has a Post Thumbnail assigned to it.
if ( has_post_thumbnail() ) {
the_post_thumbnail('latest-work'); // Other resolutions
} else {
//No featured image supplied so use default.
?>
<img src="<?php bloginfo('template_url'); ?>/img/default.png" width="300" height="200"/>
<?php } ?>
</div>
</div>
<?php endwhile; else: ?>
<p class="grid_12" style="margin:20px 0 0 0;">Sorry, no posts matched your criteria.</p>
<!-- REALLY stop The Loop. -->
<?php endif; ?>
<?php wp_pagenavi(); ?>
I'm have two loops on my index page. One fetches the latest posts from the 'work' category and the other fetches the latest from the 'blog' category. (see below)
I am also using a plugin called WP-PageNavi - http://wordpress/extend/plugins/wp-pagenavi/. I only want the pagination on the blog section which I have at the moment and it works fine for that.
The problem is that when I click on to page 2 or 3 on the pagination the 'work' section also goes to the next page but there isnt enough posts so i see the "sorry, no posts" message.
How do i get the pagination to just affect the 'blog' section?
The other problem is that when I goto the 'blog' category page and click on the pagination there (or the 'view older posts', i tried both) it sends me to this url
http://localhost:8888/blog/page/2/
which results in a 404 as it is inserting 'blog' in the url. But if i remove 'blog' so goto
http://localhost:8888/page/2/
It then sends me to the index page and using the pagination on the index page.
If it helps my permalink structure is:
/%category%/%postname%/
Here is my code...
First Loop for 'work' section:
<?php query_posts ($query_string . '&category_name=work'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="grid_4 latest-work">
<?php
// check if the post has a Post Thumbnail assigned to it.
if ( has_post_thumbnail() ) {
the_post_thumbnail('latest-work'); // Other resolutions
} else {
//No featured image supplied so use default.
?>
<img src="<?php bloginfo('template_url'); ?>/img/default.png" width="300" height="200"/>
<?php } ?>
<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
<p class="client-name"><?php $key="client"; echo get_post_meta($post->ID, $key, true); ?></p>
</div>
<!-- Stop The Loop (but note the "else:" - see next line). -->
<?php endwhile; else: ?>
<p class="grid_12" style="margin-top:20px;">Sorry, no posts matched your criteria.</p>
<!-- REALLY stop The Loop. -->
<?php endif; ?>
Second loop for 'Blog' section:
<?php query_posts( array( 'cat' => 6, 'paged' => get_query_var('paged') ) ); ?>
<!-- Start the Loop. -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="what-moves-us" >
<div class="home-blog-content">
<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
<a class="readmore" href="<?php the_permalink() ?>"></a>
</div>
<div class="blog-featured-image">
<?php
// check if the post has a Post Thumbnail assigned to it.
if ( has_post_thumbnail() ) {
the_post_thumbnail('latest-work'); // Other resolutions
} else {
//No featured image supplied so use default.
?>
<img src="<?php bloginfo('template_url'); ?>/img/default.png" width="300" height="200"/>
<?php } ?>
</div>
</div>
<?php endwhile; else: ?>
<p class="grid_12" style="margin:20px 0 0 0;">Sorry, no posts matched your criteria.</p>
<!-- REALLY stop The Loop. -->
<?php endif; ?>
<?php wp_pagenavi(); ?>
Share
Improve this question
asked Nov 7, 2012 at 11:37
ChrisChris
1212 bronze badges
1 Answer
Reset to default 0The first problem can be solved by changing the query_posts in your work section. Replace '&category_name=work'
with '&category_name=work&paged=1&posts_per_page=-1'
For the second problem, why not use the category template itself in place of index.php
?
As a side note, you should not use query_posts
for this use case. In place of that you should use a new WP_Query
object for the work loop & pre_get_posts
filter for the main loop
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745257602a4619049.html
评论列表(0条)