[Resolved] Making 3-4 posts be at the top or archive, but different ones depending

Home Forums Support [Resolved] Making 3-4 posts be at the top or archive, but different ones depending

Home Forums Support Making 3-4 posts be at the top or archive, but different ones depending

Viewing 15 posts - 16 through 30 (of 37 total)
  • Author
    Posts
  • #1900674
    nomadiceman

    I’ve replaced Elvins code with David’s.

    The pages 2 onwards of that tag archive still show the element

    I wonder what I’m doing wrong

    Any help is greatly appreciated

    #1900693
    nomadiceman

    to confirm yes its a block element

    The Block Element has these settings:
    Block – Hook
    generate_before_main_content

    location: Post Tag Archive: Visa

    hope that helps

    #1900711
    David
    Staff
    Customer Support

    I made a slight mistake in my code. I have updated it here:

    https://generatepress.com/forums/topic/making-3-4-posts-be-at-the-top-or-archive-but-different-ones-depending/#post-1900376

    Make sure to update the ID.

    #1900714
    nomadiceman

    perfect it worked! thanks David.

    I honestly have no idea how you guys handle looking at code all day. it fries my brain

    thank you for you continued help

    #1900716
    David
    Staff
    Customer Support

    We start the day with fried brains lol

    Glad to be of help!

    #1900717
    nomadiceman

    hahaha

    #1902404
    nomadiceman

    Hi elvin,

    ive just noticed that the code to remove posts that are already shown by WPSP isn’t working.

    as you can see in the link ive sent

    the code from that link you supplied which was written by Tom is this:

    // Track IDs added by WPSP.
    add_action( 'wpsp_before_header', function() {
        global $displayed_posts;
        $displayed_posts[] = get_the_ID();
    } );
    
    // Don't output posts already being output.
    add_filter( 'generate_do_template_part', function( $do ) {
        global $displayed_posts;
    
        if ( in_array( get_the_ID(), (array) $displayed_posts )) {
            $do = false;
        }
    
        return $do;
    } );

    any idea how to make this work as needed?

    I see that 2 of the WPSP posts are not displayed, but 1 is. I’ve also noticed that maybe its because one of the WPSP position in the normal archive is on page 2. I hope that makes sense

    thanks for you help guys

    #1902879
    David
    Staff
    Customer Support

    Do you have any Page Caching either plugin or server side ?
    If so try clearing the caches.

    #1903043
    nomadiceman

    Hi David. I’ve just double checked all chaching and it’s still showing

    Hope you guys can figure it out 🙏

    #1903416
    David
    Staff
    Customer Support

    Not sure but lets try adding the global variable earlier in the code.
    Keep your existing code, but add this snippet before it:

    add_action('init', function(){
        global $displayed_posts;
        $displayed_posts = '';
    },100);

    As an aside, how are the Featured Posts selected for that archive ? I assume its not the Latest Posts ?

    #1903427
    nomadiceman

    To select the 3 posts I want at the top I just add the page reference number in wpsp. Hope that’s correct.

    I’ll try that vide asap

    #1903480
    David
    Staff
    Customer Support

    Let us know how that snippet works.

    #1903934
    nomadiceman

    Hi, sorry David. I’m a little confused.

    Where do I put that code?

    #1903953
    nomadiceman

    if you mean this, I added it and the site broke

    add_action('init', function(){
        global $displayed_posts;
        $displayed_posts = '';
    },100);
    add_filter( 'generate_element_display', function( $display, $element_id ) {
        if ( 13152 === $element_id && is_paged() ) { 
            $display = false;
        } 
    
        return $display;
    }, 10, 2 );
    #1904006
    David
    Staff
    Customer Support

    Remove the snippet for the time being.
    I’ll relook at the options.

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