[Resolved] archive sticky post

Home Forums Support archive sticky post

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1102090
    Mike

    Hi
    Is there a way to stick a post excerpt to the top of a category archive page?

    Thanks

    #1102236
    David
    Staff
    Customer Support

    Hi there,

    how would you select or decide which excerpt is to be displayed?
    e.g the most recent post in the category.

    #1102264
    Mike

    I have two nav bar choices on a niche site which are ….Reviews and Information. These menu selections each open a category archive page.

    I would like to stick a post to the top of the Reviews category page, so that every time that page opens you see the same review post excerpt at the top of the page with the recent (category review) post following it.

    I’m sure it’s a hair brain idea, but it seems like I’ve been able to do it in the past but can’t make it happen now?

    Anyway, that’s what I would like to do, and whether I can or not isn’t a life or death deal. And I really can’t tell you how great it is to be able to ask you?

    Thank you
    Mike Mahaffey

    #1102286
    David
    Staff
    Customer Support

    Hmmm… had a look at the WP Repo for Stick Posts on Category and all of them are out of date, unsupported or no longer available. Which makes it a more tricky affair.

    Theres a few steps involved:
    1. How to ‘select’ the Sticky Featured Post. I would suggest using a taxonomy Tag for that.
    2. Then we can use that Tag to remove the post from the Category Loop.
    3. And then we could use WP Show Posts and a Hook Element to use the same Tag to display just that post.

    That work for you? If so i can provide the steps to do that.

    #1102302
    Mike

    Thanks David
    I hate I didn’t mention that I had already been through the wp plugins.

    Yes, if you could (at your convenience) get me started with the steps you mentioned I would appreciate it.

    Thanks
    Mike Mahaffey

    #1102323
    David
    Staff
    Customer Support

    OK
    1. Add a new Tag to your featured post. Name it what you like eg. Featured Review.
    2. Add this PHP Snippet to remove the Tag post from the category loop:

    add_filter('pre_get_posts', 'excludeTag');
    function excludeTag($query) {
          if ( $query->is_category('category-slug') ) {
                $query->set('tag', '-1');
          }
          return $query;
    }

    Replace category-slug with the slug of the category eg. reviews
    Replace the -1 in $query->set('tag', '-1'); with the ID of the Tag, you can find that by editing the tag and checking the URL, eg. if the ID=65 then the code will be: $query->set('tag', '-65')

    If that works ie. that post is no longer displayed in the loop then:

    3. Install the WP Show Posts Plugin: https://wordpress.org/plugins/wp-show-posts/
    3.1 Dashboard > WP Show Posts > New. Configure your new list with Taxonomy filter to display just your new Tag and set it to display 1 post and do all the other settings you wish to display.
    3.2 Whilst editing the list it provides you with a shortcode.

    4. Now you can add the Shortcode using a Hook Element:
    https://docs.generatepress.com/article/hooks-element-overview/

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.