2
votes

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 thumbnails 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?

2
I managed to solve this problem myself. I realised that I did not need to run a query before the loop as I already had the post I wanted displaying on the page. All I wanted to do was link to other related posts which are in the same category. After a little further searching I came across this: codex.wordpress.org/Function_Reference/previous_post_link Worked like a charm. I hope this answer helps someone out one day who was as confused as I was for a small time.James Howell
Please make your comment into an answer and mark it as accepted if it solved your problem.cdeszaq

2 Answers

3
votes

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 '); ?>
1
votes

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