- This topic has 5 replies, 2 voices, and was last updated 2 years, 8 months ago by Elvin.
-
AuthorPosts
-
July 19, 2021 at 9:44 pm #1862028StoicCorn
Hello,
I’ve tried tinkering with settings in GeneratePress/GenerateBlocks as well as searched the forum and I think I’ve come up with the answer but wanted to confirm to be sure.
Is it not possible to have blocks with blog categories?
I’d like my Blog Post Page to have blocks at the top with each category and then a list of all posts.
As of now, I believe I can accomplish the bottom portion with WP Show Posts Pro but am having difficulty with achieving the first part.
I’ve created this image as an example of what I’d like.
Is there anyway to do this?
July 19, 2021 at 11:53 pm #1862147ElvinStaffCustomer SupportHi there,
This should be possible with just WP Show Posts Pro but there’s a caveat.
You can’t use pagination on “List of All Blog Posts” as pagination gets bugged when there are multiple
WP_Query
on the page.For the 3 Blog post categories, you can place a WPSP list on them as well w/ each WPSP list having its own specific category query set on WPSP Edit page’s Post tab.
You then make sure all these categories don’t display anything other than the title, basically making it into a “list”.
Alternative to making 3 separate lists, you can simply make 1 list and set the shortcode attribute change the query.
Example:
[wp_show_posts id="1234" settings="taxonomy=category&tax_term=cats"]
[wp_show_posts id="1234" settings="taxonomy=category&tax_term=dogs"]
[wp_show_posts id="1234" settings="taxonomy=category&tax_term=birds"]
These 3 shortcodes will use the same WPSP list but will display different posts depending on th specified tax_term.
As for the layout:
The top row will be a grid block w/ 3 columns with each columns containing WPSP shortcodes of specified tax_terms.
The bottom one will be a container block containing the WPSP shortcode for ALL the blog posts.
July 20, 2021 at 11:31 am #1863375StoicCornHi Elvin,
Thank you for your reply.
However, the top three blocks I would want as a link to a page that has the list of posts rather than having them displayed inside the block.
So in your shortcode example, it would be Cats, Dogs, and Birds and when you click on Cats it takes you to a page with a list of all Cats posts.
Is it possible to set it up that way?
July 20, 2021 at 6:41 pm #1863769ElvinStaffCustomer SupportSo in your shortcode example, it would be Cats, Dogs, and Birds and when you click on Cats it takes you to a page with a list of all Cats posts.
If this is the case, I think there shouldn’t be any need for WPSP for this.
I believe you can just place a GB Headline block and add a link pointing to the specified category archive page. Or perhaps I’m missing something?
Let us know.
July 21, 2021 at 4:16 pm #1865426StoicCornHi Elvin,
That’s exactly what I’d like to have happen but was wondering if it was possible to generate those links manually. This way, when I write about something in a new category, a block automatically gets added to the page.
July 21, 2021 at 7:09 pm #1865531ElvinStaffCustomer SupportAh you mean the category dynamically changes as well to whatever category the latest post is under?
If so, you may have to get a plugin that does that.
Or, here’s one that’s a bit tricky.
Create a shortcode that does a query for the latest post but instead of getting the rest of the post’s details like title, date, etc, just fetch the category.
Example:
add_shortcode( 'latest_post_cat', function($atts) { $atts = shortcode_atts( array( 'offset' => '0', 'posts_per_page' => '1', ), $atts, 'latest_post_cat' ); $args = array( 'posts_per_page' => $atts['posts_per_page'], // we need only the latest post, so get that post only 'offset' => $atts['offset'], ); $q = new WP_Query( $args); ob_start(); if ( $q->have_posts() ) { while ( $q->have_posts() ) { $q->the_post(); echo '<a href="' . esc_url( get_category_link( get_the_category()[0]->term_id ) ) . '"><h1 class="latest-post-cat-name">'.get_the_category()[0]->name.'</h1></a>'; } wp_reset_postdata(); } return ob_get_clean(); } );
Here’s a PHP snippet for a shortcode that displays the category link and category name of the latest post.
Example usage/s:
[latest_post_cat offset="1" posts_per_page="5"]
or[latest_post_cat offset="2"]
Where offset is the offset value from the latest page.
post_per_page
is optional. It sets the number of posts(category name of the post) to display. -
AuthorPosts
- You must be logged in to reply to this topic.