Site logo

[Support request] How to build homepage sections with posts from certain categories

Home Forums Support [Support request] How to build homepage sections with posts from certain categories

Home Forums Support How to build homepage sections with posts from certain categories

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2419347
    mooore

    …AND prevent duplicate post there, EVEN though the post have multiple categories each.

    So I’ve installed this Dispatch style and went from there, but would like to build the homepage as follows:

    * the post grid that came with the style, displaying latest post

    * headline + 4-6 latest posts from certain category

    * headline + 4-6 latest posts from certain category

    AND prevent those from duplicating?

    I’ve searched quite a bit on this topic and really didn’t find any great solution.

    Am I supposed to build things with WP shop posts? or use the generate press loops? etc.

    Not sure what is the best way?

    Been playing with the query loops etc. but my time is limited and I just need to get the structure up and display correctly before getting ahead with loads of content (in case I need to revert back to only 1 category per post)

    would greatly appreciate some help on this =)

    #2420218
    Ying
    Staff
    Customer Support

    Am I supposed to build things with WP shop posts? or use the generate press loops? etc.

    Do not use WP show posts as we’ve stopped updating or supporting it. We would recommend using the Query loop block of GenerateBlocks plugin.

    #2421039
    mooore

    ok, and what about preventing the duplicate posts?

    #2421392
    David
    Staff
    Customer Support

    Hi there,

    excluding the latest posts from over query loops:

    1. Add this PHP Snippet to your site:

    
    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
        $args = array(
            'post_type' => 'post',
            'posts_per_page' => 5,
        );
        $latest_posts = new WP_Query($args);
        $latest_post_ids = wp_list_pluck($latest_posts->posts, 'ID');
        if (
            ! empty( $attributes['className'] ) &&
            strpos( $attributes['className'], 'remove-latest-posts' ) !== false
        ) {
        // Merge the current $query_args which contains arguments defined in the editor with your ordering arguments
            return array_merge( $query_args, array(
                'post__not_in' => $latest_post_ids,
            ) );
        }
    
        return $query_args;
    }, 10, 2 );

    Adjust the 'posts_per_page' => 5, value to match the number of latest posts you’re displaying.

    2. Any other Query Loops you want to remove those duplicate posts from you by:

    2.1 Edit the Query Loop block, and inside that select its Grid Block.
    2.2 In Advanced > Additional CSS Class(es) add: remove-latest-posts

    In regards to posts in multiple categories, de-duping them isn’t really possible without some other data, how do we determine which pots are displayed and which are not?

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