Site logo

Archived topic

Display specific content category on homepage w/

7 replies · Started by Scott on March 13, 2022

Viewing posts 1–8 of 8

Hi there,

I'm wanting to create a homepage which using content templates in order to make a "cards" kind of style. Basically the exact same as the "Charge" theme - text on top of image.

Only thing is, I don't want ALL posts to show, just posts within 1 category.

Is that possible?

Thanks!
Scott

Hi there,

are you going to want another page that shows the entire blog ?

Hi David,

No, that's not desired. Just this one page that shows all posts with the specified tag (I said category earlier, but I meant tag).

Thanks,
Scott

OK, then you can add a PHP Snippet to your site:

add_action( 'pre_get_posts', function ( $query ) {
    if ( !is_admin() && $query->is_home() && $query->is_main_query() ) {
        $query->set( 'tag', 'your_tag_slug' );
    }
});

Just update your_tag_slug

Thank you David. I'll give this a try but, apologies for my ignorance - which PHP file would I be updating?

Sorry my bad - I should have explained = see this doc:

https://docs.generatepress.com/article/adding-php/

TLDR:
If you have a Child Theme installed then: add it to the Child Themes functions.php. If you DO NOT then install the Code Snippets plugin and add it the code in a new Snippet.

Works!

Thanks so much :))

Glad to hear that!!

This archived topic is closed to new replies.