• Resolved morollian

    (@morollian)


    Hello,

    I am working on a project and I’m having troubles with one of my single.php templates.

    This single.php is only showing the latest post. The permalink seems to work, the url that the site displays is the wright one (i.e: from my category page i click to the permalink of the post with the id 36, and the url that displays the single.php file is the post 36 name, but doesn’t display the post 36. Instead, it displays the latest post).

    My code single.php :

    <?php get_header(); ?>
    
        <!-- Start the Loop -->
    
            <?php query_posts('post_type=catalogue&posts_per_page=1');
    
              if (have_posts()):  while (have_posts()): the_post(); ?>
    
                              <section class="catalogue">
    
                                    <section class="left">
    
                                        <h2><?php the_title(); ?></h2>
    
                                        <article>
                                              <?php the_content();?>
                                        </article>
    
                                    </section><!--end left-->
    
                              </section><!--end catalogue-->
                            <?php endwhile; ?>
    
              <?php endif; ?>
    
        <!-- End the Loop -->
    
    <?php get_footer(); ?>

    I understand that the loop is suposed to show posts (in my case one-per-page)in chronological order, but here in single.php, isn’t it supposed to get de id from the permalink in the category page?

    I’ve tried refreshing the permalinks, and adding
    header("Cache-Control: no-cache, must-revalidate"); to the top of my header, just in case my single.php was cached somewhere… but nothing worked.

    Any suggestions?
    Thanks in advance,

Viewing 2 replies - 1 through 2 (of 2 total)
  • Looking at your code, query_posts is hi-jacking the original query and WordPress is just doing what it’s told, show the latest post from the catalogue category.

    Thread Starter morollian

    (@morollian)

    Obviously! I feel dumb now… Is right there
    <?php query_posts('post_type=catalogue&posts_per_page=1');

    As you said, wordpress usually does exactly as it’s told…

    I removed the query_posts line and it works just fine..

    Thanks a lot WPRanger!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘single.php only showing the latest post’ is closed to new replies.