Archived topic
Making 3-4 posts be at the top or archive, but different ones depending
36 replies · Started by nomadiceman on August 11, 2021
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
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
I made a slight mistake in my code. I have updated it here:
Make sure to update the ID.
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
We start the day with fried brains lol
Glad to be of help!
hahaha
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
Do you have any Page Caching either plugin or server side ?
If so try clearing the caches.
Hi David. I’ve just double checked all chaching and it’s still showing
Hope you guys can figure it out 🙏
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 ?
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
Let us know how that snippet works.
Hi, sorry David. I’m a little confused.
Where do I put that code?
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 );
Remove the snippet for the time being.
I'll relook at the options.