Archived topic
Custom Post Archive templates - conditional filter
11 replies · Started by Antoinette on July 15, 2021
Hello again. Sorry to ask, but I am driving myself a bit mad trying to work it out - I've searched and tried a variety of MacGuyver-ed frankencodes but to no avail.
I'm trying to apply the column layout conditionally to a 'parent' archive page for a custom content type - based on which tag is being used.
I can get the templates applying to the posts I need them to just fine, but for the life of me I cannot figure out how to define the columns/grid layout. I suspect it's something to do with a variable on this, but I feel like I am a content loop myself at this point.
add_filter( 'generate_blog_get_column_count','tu_search_column_count' );
function tu_search_column_count( $count ) {
if ( is_team() ) {
return 33;
}
More details in the box.
Hi Antoinette,
We can correct the conditions so it properly checks for the archive.
Try this:
add_filter( 'generate_blog_get_column_count','tu_search_column_count' );
function tu_search_column_count( $count ) {
if ( is_post_type_archive('team') ) {
return 33;
}
This is assuming team is the actual slug of the custom post type.
Oh that part works already (not sure if the details to the dev site worked in the box) - yay!
But I need a filter on top of the that one to exclude the posts on the parent archive (team) from the three-grid layout / adjust to have more grids if possible.
But I need a filter on top of the that one to exclude the posts on the parent archive (team) from the three-grid layout / adjust to have more grids if possible.
Not exactly sure what you mean.
To clarify: Do you mean you want to remove specific posts from the archive page? or do you want some posts on the archive page to not follow the 3 column layout.
I want some posts on the parent archive page to be excluded from the 3 column layout, yes :-)
Ideally, if at all possible, for some of those (they're using tags to distinguish) to have a four column layout - but that's not a deal breaker.
Hi there,
can you reconfirm the login details - it didn't work for me :(
Always a chance I confused myself ha.
Also happy to consider alternative solutions if this is not possible.
Have i understood this correctly:
1. Tag: Directors are to be displayed in a 3 column row
2. Tag: Intern ( and others ? ) to be displayed in a different number of columns ?
Yep - they'll all be defined by tags to decide their column layouts on that main team archive page.
I'm fairly confident I can work out how to tweak accordingly if I have the base set up - but my attempt to at the snippet to vary these failed dismally.
Columns are defined for the whole post loop - not the individual post items.
So you need to use CSS instead - something like this which will set the posts with the tag term interns to 25%:
@media(min-width: 1024px) {
.generate-columns-container .generate-columns.tag-interns {
width: 25%;
}
}
A scholar and a gentleman you are! That looks like it'll do just the job.
Glad we could be of help!