• Hi!
    I’m making a template for one of my pages.
    I want to display the latest post in a specific category on this page.

    I found a code that works on the index-page. If I replace the regular loop with the code below, it works great with the latest post.

    <?php $wp_query->is_single = true; ?>
    
        <?php $post_count = 0; ?>
    
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>    
    
            <?php if ($post_count == 0) : ?>
    
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    	<?php the_content(''); ?>
    
            <?php $post_count++; ?>
    
        <?php endif; ?>
    
    <?php endwhile; endif; ?>

    However it doesn’t work if I make a template of it and use it on one of the pages.

    So I was wondering how to make this work on an other page than the index/home. And how to make it work on a specific post-category.

  • The topic ‘How to display latest post as single on template page’ is closed to new replies.