• demonboy

    (@demonboy)


    Hi,

    I’ve been reading up on this and not getting very far. A couple of stackexchange discussions said this was not possible due to a conflict in the wordpress codex, so I’m hoping they were older posts and things have changed.

    Quite simply, I have a category archive page, and I would like to one post sticky. I can assign sticky within the post, but can’t get it to remain post number one on my category page.

    Is this possible and, if so, how is it done without plugins?

    Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello @demonboy,

    Could you tell us more about the WordPress theme and builder you are using?

    Also, the public url of your website (NOT the user credentials) so we can see the category page you are referring to.

    Thanks

    Thread Starter demonboy

    (@demonboy)

    @hdeprada – hi, thanks for getting back to me. I completely forgot to include the link! I’m using Astra Pro. The link for the category page is:

    https://followtheboat.com/category/ftbmates

    Hello @demonboy,

    I think in that case, best way to proceed would be for you to ask Astra Pro support. Since I am sure they will have the best answer of how to do that with their theme, as it is an option they might have.

    Hope this works.

    Thanks

    Moderator bcworkz

    (@bcworkz)

    Hi demonboy,
    This is possible, but a plugin is likely the best solution. Not necessarily an existing plugin, but one of your own making. You can use “the_posts” filter to insert another (or a few) WP_Post object(s) in front of all the posts found via query.

    Currently designated sticky post IDs are saved in option “sticky_posts”. You can use get_posts() with appropriate args to get the needed post objects.

    Your filter callback should confirm the passed WP_Query object’s query vars indicate this is a main query, and a category archive query, and ignore_sticky_posts is not true. (normally undefined or empty for category queries). If not done, you risk adding stickies in addition to existing ones, or adding them where they do not belong.

    Thread Starter demonboy

    (@demonboy)

    @hdeprada – unfortunately that’s not an option as it’ll require custom coding, and theme creators don’t offer this service for free!

    @bcworkz – thanks for this guide. I do think it’s a little outside my comfort zone though.

    Since the sticky post will never change (it’s an introduction post to the category archive page), we could forget that it’s sticky and hard-code a reference to the post ID in the page layout.

    Moderator bcworkz

    (@bcworkz)

    Yes, altering the template itself is a viable solution. While it lacks the convenience of checking the “make this post sticky” checkbox in quick edit, it works well if the sticky rarely if ever changes.

    If you alter your theme’s templates and your theme is subject to periodic updates, you should create a child theme to contain your altered templates.

    Apologies if I repeat advice or suggest solutions beyond your capabilities. While I know we’ve conversed before, I have difficulty remembering what I have or have not told you, as well as remembering your relative coding skill level.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Make a post sticky on category archive page?’ is closed to new replies.