Forums

Sticky posts only in category? (4 posts)

  1. rforster
    Member
    Posted 2 years ago #

    I made a sticky post in one of my categories and it shows up on the top of my main page as one would expect.
    Is there a way to make a sticky post for the respective category it was posted in?

    TIA!

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Not easily. The sticky option only works, out of the box, on the front page of the site. In theory, it's possible to stick the post to the top if its category page (though I've not tried that myself - yet) but it would need some additional custom code added to the catgeory template file.

  3. rforster
    Member
    Posted 2 years ago #

    I fought with the loop thing for a while trying to make a custom template so could make a page and then have posts below it. Kinda like a FAQ for that category and then descending posts.

    Maybe I can make the stickies work in each category but NOT on the front page... That would be better.

    Thx for responding.

  4. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    What about using:

    <?php
    $sticky_posts = get_posts(array('post__in'=>get_option('sticky_posts')));
    if($sticky_posts):?>
    <ul>
    <?php foreach ($sticky_posts as $sticky) {
    	echo '<li><a href="'.get_permalink($sticky->ID).'">'.$sticky->post_title."</a></li>\n";
    }
    ?>
    </ul>
    <?php endif;?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.