Support » Fixing WordPress » Sticky post styling on pages other than the homepage

  • Resolved COTKPR

    (@cotkpr)


    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Michael

    (@alchymyth)

    Forum Moderator

    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':'')); ?>
    COTKPR

    (@cotkpr)

    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)

    Michael

    (@alchymyth)

    Forum Moderator

    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

    COTKPR

    (@cotkpr)

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sticky post styling on pages other than the homepage’ is closed to new replies.