WordPress.org

Ready to get started?Download WordPress

Forums

Featured post showing twice (4 posts)

  1. sonnyg80
    Member
    Posted 5 years ago #

    I recently had a theme created and there's a featured post section at the top. The problem came once someone left a comment on that post - the featured post showed again in the main body with all other posts.

    Not sure why but would appreciate any help!

  2. sonnyg80
    Member
    Posted 5 years ago #

    Snippet of code from http://www.sonnygill.com that may help make more sense:

    <div id="featured">
    	<div class="wrapper clear">
    		<?php $lastposts = get_posts('numberposts=1&category=18');
    		foreach($lastposts as $post) :
    		setup_postdata($post); ?>
    		<div class="left"><img src="<?php echo get_post_meta($post->ID, "featured", true); ?>" alt="" /></div>
    		<div class="right">
    			<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1><span><?php the_time('dMy'); ?></span>
    			<?php the_content(); ?>
    			<p class="right"><a href="<?php the_permalink(); ?>">continue reading</a></p>
    		<?php endforeach; ?>
    		</div>
    	</div>
    </div>
  3. Jeremy Clark
    Moderator
    Posted 5 years ago #

    Have a look at this. You'll need to add a check for the featured post id in the second loop.
    http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

  4. sonnyg80
    Member
    Posted 5 years ago #

    I'm still having a difficult time understanding which code to implement.

    I've implemented this bit of code <?php query_posts($query_string."&order=DESC&cat=-18"); while(have_posts()) : the_post(); ?> into where the current query is located below:

    <div class="content">
    		<?php query_posts('cat=-18&orderby=ID'); ?>
    		<?php query_posts($query_string."&order=DESC"); while(have_posts()) : the_post(); ?>
    			<div class="post">
    				<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><span><?php the_time('dMy'); ?></span></h1>
    				<?php the_content(); ?>
    				<div class="meta">
    					<span class="left"><?php comments_popup_link('no comments', '1 comment', '% comments'); ?></span>
    					<span class="right">filed under <?php the_category(', '); ?></span>
    				</div>

    What it does is get rid of the featured post showing twice BUT post order is reverted back to ascending. I have to put the DESC query because my posts are shown in ascending order otherwise.

Topic Closed

This topic has been closed to new replies.

About this Topic