sticky post for archive pages
-
My need was to modify the code so that the archived pages for a specific category always display one particular post at the top. Three different categories, three different archives, three different sticky posts.
I have modified the code so that this mostly works. It breaks once the maximum number of posts per page is exceeded. Once the archive is split amongst more than one page, the sticky post will be bumped to the back page, although it will remain at the top of that page.
I need the sticky post to stay at the top of the first page of archived posts.
Here is the modified code in archive.php:
<?php get_header(); ?><!-- Sticky post modification -->
<?php $do_not_duplicate = get_sticky_post_ID(get_query_var('cat')); ?><?php if (have_posts()) : while (have_posts()) : the_post();
if( $post->ID == $do_not_duplicate ){ ?><!-- start a post -->
<div class="posthead"><hr width="100%" />
" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></div>
<div class="thepostbox clearfix">
<div class="thepost"><?php the_content('Read the rest of this entry »'); ?></div>
</div>
<!--end a post --><?php }
else
continue;
endwhile; ?><?php endif; ?>
<?php if (have_posts()) : while (have_posts()) : the_post();
if( $post->ID == $do_not_duplicate )
continue;
else { ?>
<!-- start a post --><div class="posthead"><hr width="100%" />
" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></div>
<div class="thepostbox clearfix">
<div class="thepost"><?php the_content('Read the rest of this entry »'); ?></div>
</div>
<!--end a post -->
<?php }
endwhile; ?><!-- End Sticky post modification -->
<div class="next_prev">
<table width="570">
<tr>
<td align="left"> <?php next_posts_link('« Previous Entries') ?></td>
<td align="right"><?php previous_posts_link('Next Entries »') ?></td>
</tr>
</table></div>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p><?php endif; ?>
<?php get_footer(); ?>
NOTE: the function ‘get_sticky_post_ID’ returns the ID number of the post that is sticky in the category being displayed.
Any thoughts on what I’ve done wrong?
Thanks,
Andrea -
Yes. You are in the wrong forum. This is the wordpress.com support forum for bloggers who have blogs hosted by wordpress.com on the wp-MU multiuser blogging platform. We do not have access to our underlying blog templates here and we cannot edit them. You need to go to http://wordpress.org/support for assistance. It’s the correct forum for those self hosting software they downloaded from wordpress.org.
- The topic ‘sticky post for archive pages’ is closed to new replies.