- This topic has 5 replies, 2 voices, and was last updated 1 year, 1 month ago by
David.
-
AuthorPosts
-
December 12, 2019 at 6:38 am #1102090
Mike
Hi
Is there a way to stick a post excerpt to the top of a category archive page?Thanks
December 12, 2019 at 7:09 am #1102236David
StaffCustomer SupportHi there,
how would you select or decide which excerpt is to be displayed?
e.g the most recent post in the category.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/December 12, 2019 at 7:37 am #1102264Mike
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 MahaffeyDecember 12, 2019 at 8:01 am #1102286David
StaffCustomer SupportHmmm… 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.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/December 12, 2019 at 8:17 am #1102302Mike
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 MahaffeyDecember 12, 2019 at 8:32 am #1102323David
StaffCustomer SupportOK
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/Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.