WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Sticky post styling on pages other than the homepage (5 posts)

  1. COTKPR
    Member
    Posted 2 years ago #

    I am looking to style sticky posts, which I have successfully been able to do via:

    <?php post_class(); ?>

    However, the class [and thus the style(s)] only appends to the post(s) on the homepage - not to any of the paged pages or the category/tag/search pages. Is there a way to have the .sticky class append to all posts which have been "stickied" site wide?

    Any help/thoughts would be appreciated.

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    web search returned a link to http://codex.wordpress.org/Function_Reference/sticky_class
    however, this cannot be combined with post_class() as it simply echos ' sticky'.

    possibly, using the conditional tag is_sticky() http://codex.wordpress.org/Function_Reference/is_sticky you could try:

    <?php post_class((is_sticky()?'sticky':'')); ?>
  3. COTKPR
    Member
    Posted 2 years ago #

    Thanks for your quick reply -

    I actually want it to echo "sticky" - just not only on posts that are on the homepage. Currently echoing ".sticky" in the HTML is only happening on the homepage posts...

    (PS: The above code you supplied does not work)

  4. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    please post a link to your site;
    and paste the full code of your single post template (single.php) into a http://pastebin.com/ and post the link to it here - see http://codex.wordpress.org/Forum_Welcome#Posting_Code

    want it to echo "sticky"

    then try to use this code http://codex.wordpress.org/Function_Reference/sticky_class

  5. COTKPR
    Member
    Posted 2 years ago #

    alchymyth -
    Perfect! I had never used <?php sticky_class();?> before. (Didn't know it existed)

    I wound up doing this (utilizing conditionals) at the start of the div:

    <?php if ( is_sticky() ) {?>
    <div id="post-<?php the_ID(); ?>" class="partial flowfix clearfix<?php sticky_class(); ?>">
    <?php } else { ?>
    <div id="post-<?php the_ID(); ?>" <?php post_class('partial flowfix clearfix'); ?>>
    <?php } ?>

    Works like a charm. Thanks again for your help, I'll mark this as resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic