• So I’m using this bit of code to display the content of one post from a category on my homepage.

    <?php $wp_query = new WP_Query(array('posts_per_page' => 1, 'cat'=> 14 ) ); ?>
    <?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
    <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    <?php the_content();?>
    <?php endwhile; ?>
    <?php endif; // do not delete ?>

    I’d like to use the same bit of code to display the same post above the Page content of a certain page. The loop doens’t seem to close properly and instead of showing the post content, and then the normal page content, it’s showing the post content twice:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    What am I doing wrong?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter fitzpatrick512

    (@fitzpatrick512)

    ok, pastebin is down, but i have that on top and this below:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
                <div class="posttitle">
                	<h3><?php the_title(); ?></h3>
                </div>
    
                <?php the_content(__("Read More", 'organicthemes'));?><div style="clear:both;"></div><?php edit_post_link(__("(Edit)", 'organicthemes'), '', ''); ?>
    
                <?php endwhile; else: ?>
    			<p><?php _e("Sorry, no posts matched your criteria.", 'organicthemes'); ?></p>
    			<?php endif; ?>
    Thread Starter fitzpatrick512

    (@fitzpatrick512)

    So it seems that I need something between the two to close the loop? What’s happening is that it shows the post above as desired, but then below, instead of showing the page content, it just shows the post content again.

    either use a different variable name for the query (i.e. don’t use $wp_query which is the default variable name), or try to use wp_reset_query() after the endif of the first look.

    Yes, I would try a different variable & a query reset.

    If that doesn’t work, you could try a get_posts query above the page content.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘showing one post form a category before regular page content’ is closed to new replies.