Archived topic
Front page category sections are not pulling posts
5 replies · Started by Jason on February 3, 2023
Good evening!
I have just started a new blog - apartmentdiy.com - and I am now working on the home page.
However, on the front page using the 'Read' template from the GeneratePress Library, each category section does not show the newest post from that category. It looks like a Query Loop is set to pull in the data, but when I go to the 'Taxonomies' and 'Select Terms' options, there is nothing to choose.
This also occurs on the 'Featured Article' tag.
Please advise.
Thanks in advance!
Jason
Hi Jason,
Can you try deleting the Query Loop Parameters and adding new ones?
Let us know how it goes.
Hi Fernando,
Thanks for the quick response, and it looks like that is all that was needed to get those Query Loops working!
The one remaining issue is that in the 'Latest Articles' section, the parent category and child categories are showing. Is there a way to get this to only show the either the parent or the child category?
Thanks again!
Jason
Hi Jason,
There should be an option to include or exclude the child category:
https://www.screencast.com/t/pbVefVnYLnO
Hi Ying,
I do see 'Include child terms' on certain Query Loops on the front page. However, that doesn't seem to impact the visible categories.
There is a 'List of Terms' Headline on the 'Latest Articles' section, and as of now, this is pulling all categories, whether it is a parent or child. I believe this is what would need to be adjusted, and I've taken a few screenshots in the link below.
Thanks again!
Jason
I see, you mean the list of terms.
We don't have such an option built in for the list of terms, but you can try the below method:
1. Add an additional CSS class to the headline block which represents the list of terms, eg.custom-category-list.
https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/
2. Add this PHP snippet, this will return the parent category if there's any, if there's none, then return the child categories.
add_filter( 'render_block', function( $block_content, $block ) {
$categories = get_the_category();
$parent_categories = array();
foreach ($categories as $category) {
if ($category->category_parent) {
$parent_categories[] = $category;
}
}
if ( ! empty( $block['attrs']['className'] ) && 'custom-category-list' === $block['attrs']['className'] && (!empty($parent_categories) )) {
foreach ($parent_categories as $parent_category) {
$block_content = '<p class="parent-categories"><span><a href="' . get_category_link($parent_category->term_id) . '">' . $parent_category->slug . '</a></span></p>';
}
}
return $block_content;
}, 10, 2 );
Adding PHP: https://docs.generatepress.com/article/adding-php/
Let me know if this works.