Black Friday Sale! Get up to $30 off GP Premium! Learn more ➝

[Resolved] Custom category archive page

Home Forums Support [Resolved] Custom category archive page

Home Forums Support Custom category archive page

Viewing 15 posts - 1 through 15 (of 28 total)
  • Author
    Posts
  • #1767022
    Nemanja

    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!

    #1767196
    David
    Staff
    Customer Support

    Hi 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.

    #1767210
    Nemanja

    Hi 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!

    #1767609
    David
    Staff
    Customer Support

    Tom 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.

    #1767875
    Nemanja

    It works. But the first four are repeated again below. Can you provide me a snippet to exclude them from being duplicated?

    Thank you!

    #1768704
    Nemanja

    Hi David,
    Can you provide me a snippet to exclude posts from being duplicated?

    #1768835
    David
    Staff
    Customer Support

    Sorry your previous topic slipped through our system.
    Bear with me whilst i look for a simple solution.

    #1770602
    Tom
    Lead Developer
    Lead Developer
    #1772323
    Nemanja

    Hi 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)

    #1773358
    Elvin
    Staff
    Customer Support

    We 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.

    A wise man once said:
    "Have you cleared your cache?"

    #1773608
    Nemanja

    Hi 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.

    #1774995
    Elvin
    Staff
    Customer Support

    Although 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-25500

    For 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.

    A wise man once said:
    "Have you cleared your cache?"

    #1775283
    Nemanja

    Hi 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.

    #1777697
    Tom
    Lead Developer
    Lead Developer

    Instead 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 );
        }
    } );
    #1784328
    Nemanja

    Hi 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??

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