• Resolved Pepozzo

    (@pepozzo)


    Hello!

    I’ve a custom theme and a page in it that display only posts from a specified category.

    So, i’ve this code:

    <?php
    /*
    Template Name: Pagina Eventi
    */
    ?>
    
    <?php get_header(); ?>
    
    <?php
    $query= 'cat=4';
    query_posts($query);
    ?>
    
    <div id="content">
    <table width="900px"  style="height:580px !important;" cellpadding="0" cellspacing="0">
    [...]
    <?php query_posts('showposts=4'); ?>
    <?php if (have_posts()) : ?>
    
            <?php while (have_posts()) : the_post(); ?>
    			[...]
                <div class="post">
                    <h3 id="post-<?php the_ID(); ?>"><a>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>
    
                    <div class="entry_eventi">
                        <?php the_content('Read the rest of this entry ?'); ?>
    [...]
    
            <?php endwhile; ?>
    </table>
    
    <div class="navigation">
    <div class="alignleft"><?php previous_posts_link('? Previous Entries') ?></div>
    <div class="alignright"><?php next_posts_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 include (TEMPLATEPATH . "/searchform.php"); ?>
    
        <?php endif; ?>
    [..]
    </table>
    
    </div>
    <?php get_footer(); ?>

    Where “[…]” I’ve cut some html code.

    Now, this code display correctly the “Next/Previous Entries”, but when I click on it the url become https://www.mysite.tld/page/2/ but posts remain the same than previous page, nothing change.

    Where am i wrong?

    Thanks

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. Or better still – use the pastebin. As it stands, your code may now have been permanently damaged/corrupted by the forum’s parser.]

Viewing 3 replies - 16 through 18 (of 18 total)
  • OK – try:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
    'cat' => 4,
    'posts_per_page' => 4,
    'paged' => $paged
    }
    query_posts($args);
    ?>
    Thread Starter Pepozzo

    (@pepozzo)

    It works!!!

    I’ve modified your code to correct a PHP error

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

    Excellent! ??

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘Posts pagination in a page’ is closed to new replies.