开发者

Paginate through posts of a single category in Wordpress single.php

I have set up a site using Wordpress as my CMS. I am using the site as a portfolio to show off my front-end web dev skills and have another area of the site for a blog. I got around the issue of having 2 blogs on the site by giving posts a category of either Projects or Blog.

The front page of my site contains thum开发者_开发技巧bnails and links to Recent Projects. When you click through you are taken to a Project Detail page which uses Single.php to display a single post. The TwentyTen theme (which I have edited) comes with pagination so that when you are on the Project Detail page you can also click through to the next or previous post. However there does not seem to be any restriction on the category so you can also click through to Blog posts. I want the user to only be able to click through to other Projects.

I have googled around this issue and seem to find suggestions to use custom queries but none of the solutions suggested seem to work.

I only want to display one post at a time on Single.php and have pagination which lets me link to the next or previous Project post.

Any ideas?


Checkout these links: http://codex.wordpress.org/Function_Reference/previous_post_link http://codex.wordpress.org/Function_Reference/next_post_link

This is an example of how you can use the function to restrict to posts in current cat only:

<?php previous_post_link('%link', 'Next: %title &raquo;' , in_same_cat, 'excluded_categories '); ?>
<?php next_post_link('%link', '&laquo; Previous: %title', in_same_cat, 'excluded_categories '); ?>


Your going to want something like this:

$the_page = get_query_var('paged'); //<!-- tell wordpress this is paged
query_posts('cat=7&posts_per_page=6&paged='.$the_page); //<-- set cat= to the numeric category

if (have_posts()) {
    while (have_posts()) {
        the_post();

        // do your awesome WP loop stuff here
        <div><?php next_posts_link('Next Page &raquo;') ?></div>
        <div><?php previous_posts_link('&laquo; Previous Page') ?></div>
    }
}

Hope this helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜