Posts not changing in Archive Layout

Hello,

I created a blog page using an archive layout: https://ecsiteapp.com/news-resources/

The menu over the posts is the category menu. When I click a category, rather than just displaying the posts in that category, it displays the same posts but changes all of the labeled categories in each post (using {{dc:term:title}}) to the category I clicked.

I’m not sure if this is a problem with the Looper or if it’s an assignment issue.

Also, when I click on the next page on the pagination at the bottom, it shows the same posts.

Any help would be greatly appreciated.

Hello @zenzino,

Thanks for writing in!

Please be advised that a Looper provider cannot be the Looper Consumer at the same time.

For the Archive Layouts, you only need the Looper Consumer because the archive page itself has an ongoing Loop. I went ahead and corrected your custom layouts already. Check your site now.

In the meantime, please review this tutorial video to be more familiar with how you can create a custom archive layout.

Best Regards.

Hey @ruenel,

Thanks for looking into this.

I used a Looper Provider because I wanted to exclude the ‘Job Posting’ category from showing up on the posts page.

Should I use the Query Builder in the Lopper Provider and not use the Consumer to do this?

Hello @zenzino,

Yes, you can use the Looper Provider type as “Query Builder” as suggested by my colleague @ruenel then you can select the category or exclude the category from the Taxonomy to filter the post by category.

Thanks

Ok.

So I used the Query Builder as a Provider for the Section to exclude the ‘Job Postings’ category and then set the Posts row as the Looper Consumer (Blog page layout). Then I set the condition ‘Blog being viewed’.

Then I created another layout (Category Archive) which only has the Looper Consumer for the posts. I set the Condition to ‘Blog being viewed’ and ‘Category is not Job Postings’. https://ecsiteapp.com/category/events/

This has solved all my problems except the Pagination on the Blog page layout (/news-resources/) is not working.

I have watched all the Looper videos multiple times and read the docs page on Pagination and didn’t find the answer there.

Hello @zenzino,

What you are trying to do cannot be done with the custom Archive Layout. You need additional custom PHP code that will exclude the Job Posting category from your archive page. This article can help:

I went ahead and removed your Looper Provider. Then I followed the article to exclude your Job Posting category by adding a code in your child theme’s functions.php file:

// Exclude Job Posting category from the archive pages
// =============================================================================
function exclude_category( $query ) {
	if ( $query->is_home() && $query->is_main_query() ) {
		$query->set( 'cat', '-12' );
	}
}
add_action( 'pre_get_posts', 'exclude_category' );
// =============================================================================

Your blog index should now display without post items belonging to the Job Posting category now.

Note: Please clear your browser cache first before testing your blog index. Be advised that this is a custom code. You will have to maintain this code whenever there are theme updates to make sure that it is still working.

Best Regards.

@ruenel,

You are a gentleman and a scholar. And you are awesome!

Thank you so much for your help.

I super appreciate the whole Theme Co team.

You are most welcome.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.