WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Making a post Sticky, has it showing up twice (13 posts)

  1. wpfiend
    Member
    Posted 3 years ago #

    Hello experts:

    I have made the only post on my blog a Sticky post.

    Now it shows up on the home page twice. I can understand it showing up as a sticky but how can I get rid of the second redundant post??

    There are no other posts on the blog as yet.

    Thanx in advance,

    --wpf.

  2. Gisha James
    Member
    Posted 3 years ago #

    In 2010 it shows only once. Which theme you are using, Does the theme display the posts more than once like, featured, recent or something like that...

  3. wpfiend
    Member
    Posted 3 years ago #

    Hi. Thanx for the response.

    I am using the theme called "Ships Ahoy!"

    And this is the code for home.php.

    <?php get_header(); ?>
    
    <div id="content"><!-- begin content -->
    
    <h2 class="title">Latest Ramblings</h2>
    
    <div class="home"><!-- begin home -->
    
    		<?php query_posts('showposts=1'); // this shows the latest post you have written ?>
    		<?php while (have_posts()) : the_post(); ?>
    		<div class="post" id="post-<?php the_ID(); ?>">
    		<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    		<h3>by <?php the_author() ?> | <?php the_time('F jS, Y') ?> | Filed under: <?php the_category(', ') ?> | <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></h3>
    				<div class="entry">
    					<?php the_content('continue reading'); ?>
    				</div>
    			<?php if (function_exists('the_tags')) { the_tags('<p>Tags: ', ', ', '</p>'); } ?>
    			<?php edit_post_link('[edit]', '<p class="edit">', '</p>'); ?>
    		</div>
    			<?php endwhile; ?>
    </div><!-- end home -->
    
    <div class="spacer"></div> <!-- the hr below the first post -->
    
    <div class="recentposts"><!-- begin recent posts -->
    
    		<?php query_posts("offset=1"); // you can chage how many posts are shown through your WordPress dashboard = settings = reading ?>
    		<?php while (have_posts()) : the_post(); ?>
    		<div class="repost" id="post-<?php the_ID(); ?>">
    <!--		<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    		<p class="repostmetadata"><?php the_time('F jS, Y') ?> | <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?><br/>
        	<?php if(function_exists("the_tags")) the_tags('Tags: ', ', ', ''); ?></p>
    -->
    		<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    		<h3>by <?php the_author() ?> | <?php the_time('F jS, Y') ?> | Filed under: <?php the_category(', ') ?> | <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></h3>
    				<div class="entry">
    					<?php the_content('continue reading'); ?>
    				</div>
    			<?php if (function_exists('the_tags')) { the_tags('<p>Tags: ', ', ', '</p>'); } ?>
    			<?php edit_post_link('[edit]', '<p class="edit">', '</p>'); ?>
    
    		</div>
    		<?php endwhile; ?>
    
    </div><!-- end recent posts-->
    
    </div> <!-- end begin content -->
    
    <?php include(TEMPLATEPATH."/left.php");?>
    <?php include(TEMPLATEPATH."/right.php");?>
    
    <?php get_footer(); ?>

    Any ideas.

    Thanx again,

    --wpf.

  4. Gisha James
    Member
    Posted 3 years ago #

    Yes, your theme shows the post and recent posts, that is why it appears twice. You have to exclude sticky post from recent post.

  5. wpfiend
    Member
    Posted 3 years ago #

    So I can NEVER use the Sticky Post feature as it will ALWAYS display the same post twice???

    Can I not change the code that I have included above, to get me where I want....???

    --wpf.

  6. Gisha James
    Member
    Posted 3 years ago #

    You can use sticky post. As I mentioned before you have to exclude sticky posts from recent posts. - exclude sticky posts from second loop.

  7. wpfiend
    Member
    Posted 3 years ago #

    Gisha James:

    I have no idea how to do this. What I want is if I have made a post sticky that it be NOT included when the other posts are being shown after the sticky post. I don't want the sticky post displayed twice.

    Here is the code to home.php.

    <?php get_header(); ?>
    
    <div id="content"><!-- begin content -->
    
    <h2 class="title">Latest Ramblings</h2>
    
    <div class="home"><!-- begin home -->
    
    		<?php query_posts('showposts=1'); // this shows the latest post you have written ?>
    		<?php while (have_posts()) : the_post(); ?>
    		<div class="post" id="post-<?php the_ID(); ?>">
    		<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    		<h3>by <?php the_author() ?> | <?php the_time('F jS, Y') ?> | Filed under: <?php the_category(', ') ?> | <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></h3>
    				<div class="entry">
    					<?php the_content('continue reading'); ?>
    				</div>
    			<?php if (function_exists('the_tags')) { the_tags('<p>Tags: ', ', ', '</p>'); } ?>
    			<?php edit_post_link('[edit]', '<p class="edit">', '</p>'); ?>
    		</div>
    			<?php endwhile; ?>
    			<?php wp_reset_query(); ?>
    </div><!-- end home -->
    
    <div class="spacer"></div> <!-- the hr below the first post -->
    
    <div class="recentposts"><!-- begin recent posts -->
    
    		<?php query_posts("offset=1"); // you can chage how many posts are shown through your WordPress dashboard = settings = reading ?>
    		<?php while (have_posts()) : the_post(); ?>
    		<div class="repost" id="post-<?php the_ID(); ?>">
    		<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    		<p class="repostmetadata">by <?php the_author() ?> | <?php the_time('F jS, Y') ?> | Filed under: <?php the_category(', ') ?> | <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?><br/>
        	<?php if(function_exists("the_tags")) the_tags('Tags: ', ', ', ''); ?></p>
    		<?php the_content('continue reading'); ?> <!-- Added to include the FULL post -->
    		<?php edit_post_link('[edit]', '<p class="edit">', '</p>'); ?>
    
    		</div>
    		<?php endwhile; ?>
    
    </div><!-- end recent posts-->
    
    </div> <!-- end begin content -->
    
    <?php include(TEMPLATEPATH."/left.php");?>
    <?php include(TEMPLATEPATH."/right.php");?>
    
    <?php get_footer(); ?>

    Can you please help??

    Thanx,

    --wpf.

  8. Gisha James
    Member
    Posted 3 years ago #

    In the second loop, replace the existing query_posts("offset=1"); with

    $args =array("post__not_in" =>get_option("sticky_posts"),
    'offset'=>1);
    query_posts($args);

  9. wpfiend
    Member
    Posted 3 years ago #

    That was it!!!!!

    Thank you so much for your time.

    Warm Regards,

    --wpf.

  10. flowerpowermeg
    Member
    Posted 3 years ago #

    Can you please help me as well with code changes to make sure sticky posts don't come twice? I have exactly same problem and I am not that great at code changes. My theme is albizia and sticky posts keep coming twice.
    My home.php code is :
    <?php get_header();extract(itx_get_option('front'));?>
    <div id="main" class="wrap">
    <div id="mainwrap">
    <div id="content">
    <div id="contentpad">
    <div id="contentwrap">
    <?php
    $column=itx_get_option('front','column');
    if (!is_paged()){
    itx_sidebar('name=innertop');
    if ($type=='fe'||$type=='fl'){
    if (have_posts()){itx_home_title();the_post(); itx_content('featured');}
    if ($wp_query->post_count<2) $nosearch=1;
    }
    }

    if ($type=='fe'||$type=='fl'){
    if(!get_option('sticky_posts')){
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $offset='&offset='.(($paged-1)*get_query_var('posts_per_page')+1);
    } else $offset='&caller_get_posts=1';
    query_posts($query_string.$offset);
    }

    if (have_posts()) {
    if (!($type=='fe'||$type=='fl')||is_paged()){itx_home_title();}
    if ($type=='fl') echo '<div class="linepostwrap">';
    $i=0;
    while (have_posts()) {
    the_post();
    if ($type=='traditional') itx_single_content('singlepost');
    elseif ($type=='fl') itx_line_content('linepost');
    else {
    $i++;
    $postwrap=ceil($i/$column);
    itx_content('posts postwrap-'.$postwrap);
    }
    }
    if ($type=='fl') echo '</div>';
    } elseif (empty($nosearch)) itx_notfound();

    ?>
    <div class="clear"></div>
    <?php if (!is_paged()){itx_sidebar('name=innerbottom');}?>
    </div>
    <div class="clear"></div>
    <div id="navi">
    <?php wp_pagenavi();?>
    </div>
    </div>
    </div> <!--/content-->
    <?php itx_sidebar('name=sidebar&pos=left');itx_sidebar('name=sidebar&pos=right');?>
    </div>
    </div> <!--/main-->
    <?php get_footer(); ?>

  11. wpbless
    Member
    Posted 3 years ago #

    Where is the file that Gisha and WP fiend are discussing?

    I believe it's the home.php file.

    Which I can't find in my wp-admin, wp-content-, wp-includes folders.

    I've found files are sometimes concealed on my server by some setting at the hosting company. Maybe that's why.

    But can anybody point me to the right file for excluding sticky posts from recent posts?

    Many thanks!

  12. Gisha James
    Member
    Posted 3 years ago #

    The home.php should be in your theme folder.

    wp-content/ themes/[your theme folder]

  13. EffortlessEnglishClubPl
    Member
    Posted 3 years ago #

    Working with the same problem here....

    Every post I create shows up double and when a new one is created the previous one reverts back to only one. I'm sure this is going to be fixed in the same way as the problems above but once again...I'm one who doesn't know anything about 'loops' or php.

    Can someone lend a hand on fixing this code? I'm using the Grunge RockeTheme template. The code is below....

    <?php
    /**
     * @version   1.0 February 17, 2011
     * @author    RocketTheme http://www.rockettheme.com
     * @copyright Copyright (C) 2007 - 2011 RocketTheme, LLC
     * @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
     */
    
    // no direct access
    ?>
    
    <?php global $post, $posts, $query_string; ?>
    	<div class="blog">
    
    				<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    				if($gantry->get('blog-query') != '') : query_posts("'paged=".$paged.'&'.$gantry->get('blog-query')."'");
    
    				else: query_posts('paged='.$paged.'&orderby='.$gantry->get('blog-order').'&cat='.$gantry->get('blog-cat').'&post_type='.$gantry->get('blog-type'));
    
    				endif; 
    
    				?>
    
    				<?php while (have_posts()) : the_post(); ?>
    
    				<!-- Begin Post -->
    					<div class="leading">
    
    				<?php if ($gantry->get('blog-page-title') != '') : ?>
    
    			<div class="sectiontitle">
    				<?php echo $gantry->get('blog-page-title'); ?>
    			</div>
    
    			<?php endif; ?>
    
    						<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
    
    							<?php if($gantry->get('blog-title')) : ?>
    
    							<!-- Begin Title -->
    
    								<?php if ( count( get_the_category() ) ) : ?>
    								<h1 class="title">
    								<span><?php print(get_the_category_list( ', ' ) ); ?></span>
    								</h1>
    								<div class="articledivider"></div>
    								<?php endif; ?>
    
    								<?php if($gantry->get('blog-link-title')) : ?>
    
    								<h2 class="contentheading">
    									<span><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></span>
    								</h2>
    
    								<?php else : ?>
    								<h2 class="contentheading">
    									<?php the_title(); ?>
    								</h2>
    
    								<?php endif; ?>
    
    							<!-- End Title -->
    
    								<?php if($gantry->get('blog-meta-date')) : ?>
    
    								<!-- Begin Date & Time -->
    
    								<div class="contentdate"><span class="createdate"><!--<?php _re('Posted on'); ?> --><span><?php the_time('d.m.y'); ?></span></span></div>
    
    								<!-- End Date & Time -->
    
    								<?php endif; ?>
    
    							<?php endif; ?>
    
    							<?php if($gantry->get('blog-meta-comments') || $gantry->get('blog-meta-date') || $gantry->get('blog-meta-modified') || $gantry->get('blog-meta-author')) : ?>
    
    							<!-- Begin Meta -->
    
    							<p class="articleinfo">
    
    								<?php if($gantry->get('blog-meta-modified')) : ?>
    
    								<!-- Begin Modified Date -->
    
    								<span class="modifydate"><?php _re('Last Updated on'); ?> <?php the_modified_date('l, d F, Y H:i', '<span>', '</span>'); ?></span>
    
    								<!-- End Modified Date -->
    
    								<?php endif; ?>
    
    								<?php if($gantry->get('blog-meta-author')) : ?>
    
    								<!-- Begin Author -->
    
    								<span class="createdby"><?php _re('Written by'); ?> <span><?php the_author(); ?></span></span>
    
    								<!-- End Author -->
    
    								<?php endif; ?>
    
    							</p>
    
    							<!-- End Meta -->
    
    							<?php endif; ?>
    
    							<div class="articlebox">
    							<p class="iteminfo"></p>
    								<!-- Begin Post Content -->
    							<?php if(function_exists('the_post_thumbnail') && has_post_thumbnail()) : the_post_thumbnail('gantryThumb', array('class' => $gantry->get('thumb-position'))); endif; ?>
    								<?php if($gantry->get('blog-content') == 'content') : ?>
    
    								<?php the_content(false); ?>
    
    								<?php else : ?>
    
    								<?php the_excerpt(); ?>
    
    								<?php endif; ?>
    
    								<?php if(preg_match('/<!--more(.*?)?-->/', $post->post_content)) : ?>
    								<div class="readon">
    									<a href="<?php the_permalink(); ?>"><span><?php echo $gantry->get('blog-readmore'); ?></span></a>
    								</div>
    
    								<?php endif; ?>
    
    								<!-- End Post Content -->
    
    								<?php if($gantry->get('blog-meta-comments')) : ?>
    
    									<!-- Begin Comments -->
    
    									<?php if($gantry->get('blog-meta-link-comments')) : ?>
    									<div class="readon">
    										<a href="<?php the_permalink(); ?>#comments">
    											<span><?php comments_number(_r('0 Comments'), _r('1 Comment'), _r('% Comments')); ?></span>
    										</a>
    									</div>
    
    									<?php else : ?>
    
    									<div class="readon">
    										<span><?php comments_number(_r('0 Comments'), _r('1 Comment'), _r('% Comments')); ?></span>
    									</div>
    
    									<?php endif; ?>
    
    									<!-- End Comments -->
    
    								<?php endif; ?>
    
    							</div>
    						</div>
    						<div class="clear"></div>
    						</div>
    				<!-- End Post -->
    
    				<?php endwhile;?>
    
    				<!-- Begin Navigation -->
    
    				<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if($total_pages > 1) : ?>
    
    				<div class="rt-pagination nav">
    					<div class="alignleft">
    						<?php next_posts_link('« '._r('Older Entries')); ?>
    					</div>
    					<div class="alignright">
    						<?php previous_posts_link(_r('Newer Entries').' »') ?>
    					</div>
    					<div class="clear"></div>
    				</div><br />
    
    				<?php endif; ?>
    
    				<!-- End Navigation -->
    
    	</div>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.