Site logo

Archived topic

Dispatch theme: Posts disappearing from the "list" below the heros on homepage

3 replies · Started by Malin on July 10, 2022

Viewing posts 1–4 of 4

Dear helpful support people,
I have an issue with posts on the home page that I need help with.

On the first page, I would like the most recent post to be first.

There are 4 heros with pictures and nice headlines, and I want articles to be there, but not smaller stuff like workshop listings.
(I had an old support topic here on the same and thought it was solved, but I realize it's not:
https://generatepress.com/forums/topic/dispatch-theme-posts-showing-up-twice-on-homepage/ )
I got help to write a snippet then, and this is what I've added:

This removes duplicates in the heros:

// 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;
} );

And this removes the "smaller" posts that should not be heros, but only in the list below:

function exclude_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', array( '-68', '-2538', '-2539', '-2540', '-2541', '-2542', '-2543', '-2544', '-2545', '-2546', '-2547', '-2548', '-2549', '-6740', '-6741', '-6742', '-6743', '-6744', '-6745', '-6746', '-6747', '-6748', '-6749', '-6750', '-6751', '-6752', '-6753' ) );
}
}
add_action( 'pre_get_posts', 'exclude_category' );

The problem: What happens is that an article moves from the first spot in the hero, and then to second, third and fourth, like it should. BUT after it never "falls down" to the list below, it just disappears totally from the first page.
I would like visitors to be able to scroll down and find older content, so, would it be possible to have it included in the list underneath when it's in the fifth place?

Here is the website:
https://www.alternativephotography.com/

I would really appreciate help. :-)

Hi Malin,

To clarify, do you want to exclude the smaller stuff in the WPSP list but still include them in the query?

If so, can you try replacing this:

function exclude_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', array( '-68', '-2538', '-2539', '-2540', '-2541', '-2542', '-2543', '-2544', '-2545', '-2546', '-2547', '-2548', '-2549', '-6740', '-6741', '-6742', '-6743', '-6744', '-6745', '-6746', '-6747', '-6748', '-6749', '-6750', '-6751', '-6752', '-6753' ) );
}
}
add_action( 'pre_get_posts', 'exclude_category' );

With something like this:

add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
if ( 394283 === $settings['list_id'] ) {
	$my_exclude_array = array( '396728', '2538', '2539' );
	$args['post__not_int'] = $my_exclude_array;

	} return $args;
},10,2);

Replace 394283 with your list id and 396728, 2538 and 2539 with your post ids. Add the other post ids as well.

Kindly let us know how it goes.

Thank you so much for you help!

You’re welcome Malin!

This archived topic is closed to new replies.