• Hello.

    Wondering if this is a good code to get all post of a specific category to a page?

    <?php query_posts(‘cat=25’.get_the_title()); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    Furthermore I would like to have ten posts per page, I would like to use next/previous function of some sort.
    This I′ve got now, but it doesn′t work properly.
    What have I done wrong?

    <?php previous_post_link(‘%link’, ‘%title’, TRUE, ‘7’); ?>
    <?php next_post_link(‘%link’, ‘%title’, TRUE, ’10’); ?>

    Thanx!

    My page.

Viewing 1 replies (of 1 total)
  • In order to have pagination work properly, you need to include the ‘paged’ argument in your query_posts(), something like this:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array (
        'posts_per_page' => 10,
        'cat' => 25,
        'paged' => $paged
    );
    query_posts($args);
    ?>

    Then, for the pagination, you should use next_posts_link() and previous_posts_link(). next_post_link() and previous_post_link() are for displaying the next/previous individual post when viewing a single post, not for displaying the next/previous page of 10 posts.

    Below is some sample code taken from this Codex article: https://codex.www.ads-software.com/Pagination#Example_Loop_with_Pagination

    <div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
    <div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
Viewing 1 replies (of 1 total)
  • The topic ‘query_posts and a specific category’ is closed to new replies.