Question about #wordpress. I want a regular page with all my post (a stream) and a front page with just a selection (in my case any post NOT in Uncategorized category). Do I need to build a custom `front-page.php` or is there some other nice way to achieve this?

@metbril You could probably use a `pre_get_posts` callback (which accepts a `$query` arg) or something and then check for either `is_home()` or `is_front_page()` (not too sure) and `$query->is_main_query()` and then modify `$query` accordingly. Or use a custom query in a `front-page.php` template. 🤓 developer.wordpress.org/refere

@jan That pre_get_posts callback could be in my functions.php, I guess, so no need to change or clone any template file?

@metbril Exactly. First of those basic examples on that page would probably work, just need to change the `post__not_in` bit with `category__not_in` and the correct category ID (or slug, not sure).

@metbril You could (probably) do the same for your “stream” page, by the way, even include CPTs, or remove the post limit (in order to really get all of them instead of paginated results). Instead of `is_front_page()` you would then do `is_page( 'page_ID_or_slug' )` or something.

@jan I'm new to this, so it's a little trial and error. The (sempress) theme has an index.php, no home.php or front-page.php. I've set my home page to a static page and the blog page "/all" to another. The blog page shows the stream just fine (regular WP) but the new home page still shows the regular content (title et al).

@metbril Yeah, your homepage (the static one) will return `true` for `is_front_page()`, on the “blog” page it’s `is_home()` you should use (or not, if it’s already fine).

Follow

@metbril The callback runs for every database query, so often even multiple times per page. The `if` statement ensures you modify the query you’re looking for.

Sign in to participate in the conversation
Mastodon

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!