- This topic has 27 replies, 4 voices, and was last updated 2 years, 10 months ago by Tom.
-
AuthorPosts
-
May 6, 2021 at 3:26 am #1767022Nemanja
Hey there,
I want to show my first 4 category archive posts like in the grid 50% – 50%. In first container there is the latest post and in another there are three posts stacked on top of each other. I tried to add it with a block-hook element and with dynamic content but it shows only one post four times. I also wish to display a post title not category title.Can you please help me achieve this.
Thank you!
May 6, 2021 at 5:34 am #1767196DavidStaffCustomer SupportHi there,
to do that would require the WP Show Posts plugin:
https://en-gb.wordpress.org/plugins/wp-show-posts/
With it you would create 2 x WPSP Lists.
The first list to display just the 1 post.
The second list to display 3 posts.Each WPSP list will be create a shortcode. Which can be added using a Shortcode Block inside a GenerateBlocks Grid. Which can be hooked in using a Block Element.
I would suggest for the posts you want displayed in that element to give them a specific Category or Tag eg. Featured Large and Featured Small.
You can use those Categories in the WPSP Taxonomy filter so only those are displayed there.
We can then provide a snippet to exclude them from being duplicated in the main loop.
May 6, 2021 at 5:42 am #1767210NemanjaHi David,
I know that, that’s how I did it on homepage. That means I need to do it manually for all categories?? There are like hundred of them. Is there any other way?Thank You!
May 6, 2021 at 7:20 am #1767609DavidStaffCustomer SupportTom provides a shortcode here with the arguments that will display posts from the current category only:
https://wpshowposts.com/support/topic/show-related-posts-exclude-post/#post-18750
So you could apply the same logic to both your WPSP Lists ( with the relevant
id="123"
) – and in your lists you could use the Offset value for the second post list so it skips the first post ( which would be displayed by your first list ).This could then be added as Block Element for all your categories.
May 6, 2021 at 10:46 am #1767875NemanjaIt works. But the first four are repeated again below. Can you provide me a snippet to exclude them from being duplicated?
Thank you!
May 7, 2021 at 4:01 am #1768704NemanjaHi David,
Can you provide me a snippet to exclude posts from being duplicated?May 7, 2021 at 5:47 am #1768835DavidStaffCustomer SupportSorry your previous topic slipped through our system.
Bear with me whilst i look for a simple solution.May 8, 2021 at 10:45 am #1770602TomLead DeveloperLead DeveloperHi there,
Perhaps this will help?: https://wpshowposts.com/support/topic/stop-showing-duplicate-posts-on-the-same-page-post-using-a-different-shortcode/#post-15716
Let us know 🙂
May 10, 2021 at 3:17 am #1772323NemanjaHi Tom,
they are still duplicated.
The problem is that it always shows the same four (most recent) posts regardless of their subcategory. Is it possible that this code [wp_show_posts id=”123″ settings=”taxonomy=category&tax_term=current”] is pointing to current subcategory or something like that, because first four posts are from the right category but not from the right subcategory??
Please see how it looks on page. (link below)May 10, 2021 at 4:28 pm #1773358ElvinStaffCustomer SupportWe should be able to programmatically do that.
Try adding this PHP snippet:
add_shortcode('dynamic_wpsp', function($atts){ $queriedArchive = get_queried_object(); $atts = shortcode_atts( array( 'id' => '' ), $atts, 'dynamic_wpsp' ); $settings = array( 'taxonomy' => $queriedArchive->taxonomy, 'tax_term' => $queriedArchive->slug, ); wpsp_display( $atts['id'], $settings ); });
This allows you to use
[dynamic_wpsp id="1234"]
shortcode.This shortcode gets the current archive’s taxonomy and terms and then applies it to WPSP and shows the post list.
Note: Only use this on archive pages.
May 10, 2021 at 11:31 pm #1773608NemanjaHi Elvin,
thank you for your response.I added snippet,than the shortcode [dynamic_wpsp id=”1234″] (with ID of my wpsp list) in block-hook element and when I try to update block it says: ‘Updating failed. The response is not a valid JSON response.’
Although it displays correct posts their positioning is off and they are still duplicated.
See link below.And yes, I cleared my cache.
May 11, 2021 at 3:53 pm #1774995ElvinStaffCustomer SupportAlthough it displays correct posts their positioning is off and they are still duplicated.
See link below.I’m not sure what you mean by duplicated.
Are you trying to make a specific post not display anymore if it’s already displayed on the paginated post listing?
If so, consider trying the PHP snippet here – https://wpshowposts.com/support/topic/articles-not-changing-homepage-next-page/#post-25500For the positioning, how do you want it positioned?
Note: You can place your Shortcode block inside a GB Container block if you want to position it.
May 11, 2021 at 11:57 pm #1775283NemanjaHi Elvin,
thank you for your response.Yes I want this four posts to be kind of featured (recent posts of current subcategory) and not to appear again below.
The snippet is not working for me (it changes nothing).I already put that shortcode ( [dynamic_wpsp id=”1234″] ) in container/grid (container (100% width) — grid 50%-50% and in first grid-container there is one post, in second there are three posts one below another ), but it has no effect.
When I press update it shows me an error : ‘Updating failed. The response is not a valid JSON response.’Please read the whole discussion to understand better what I want to accomplish.
May 13, 2021 at 7:31 am #1777697TomLead DeveloperLead DeveloperInstead of Elvin’s function, try this:
add_shortcode('dynamic_wpsp', function($atts){ $queriedArchive = get_queried_object(); $atts = shortcode_atts( array( 'id' => '' ), $atts, 'dynamic_wpsp' ); $settings = array( 'taxonomy' => $queriedArchive->taxonomy, 'tax_term' => $queriedArchive->slug, ); ob_start(); wpsp_display( $atts['id'], $settings ); return ob_get_clean(); });
The duplicated posts thing is harder.
You could try this:
add_action( 'wpsp_before_header', function() { global $added_ids; $added_ids[] = get_the_ID(); } ); add_action( 'pre_get_posts', function( $query ) { global $added_ids; if ( ! empty( $added_ids ) ) { $query->set( 'post__not_in', $added_ids ); } } );
May 17, 2021 at 5:53 am #1784328NemanjaHi Tom,
thank you for your quick response.First snippet works great. It’s displaying posts correctly.
But when I add the second snippet (against duplicating) absolutely nothing displays on the pages.
Is there any other solution for this duplication problem?? -
AuthorPosts
- You must be logged in to reply to this topic.