Archived topic
Use columns for CPT on author archive
9 replies · Started by Aart on February 25, 2019
Hi,
I have a custom post type called 'recept'. I'm trying to do two things:
1. Show all 'recept' content on their authors' respective archive pages.
2. Adding GP columns and masonry to all archive pages of this post type.
I've managed 1) by creating a little plugin, but I'm having some trouble with 2). I have both columns and masonry working with the help of these code snippets, but I can't get it to work on the author pages.
I hope you can point me in the right direction.
Best regards,
Aart
Hi there,
What's the condition you are currently using?
Have you tried this?
https://codex.wordpress.org/Conditional_Tags#An_Author_Page
Everything should be listed on that page.
Let me know :)
Hi Leo,
I'm currently using this for the post archive pages:
add_filter( 'generate_blog_columns','tu_portfolio_columns' );
function tu_portfolio_columns( $columns ) {
if ( is_post_type_archive( 'recept' ) ) {
return true;
}
return $columns;
}
I want to extend this to all archives, including the author archive, but I'm not sure how to do that.
What if you just do this instead?
https://codex.wordpress.org/Conditional_Tags#Any_Archive_Page
Hi Leo, thanks your help. I tried changing condition to is_author, like this:
add_filter( 'generate_blog_columns','tu_portfolio_columns' );
function tu_portfolio_columns( $columns ) {
if ( is_author ) {
return true;
}
return $columns;
}
Sure enough it worked on the author archive pages, showing the content in columns. Unfortunately it also affected the rest of the site, causing page sections to overlap each other on single pages (like the comment box overlapping the content) and the homepage (which contains WP Show Posts).
So I guess this is not the full solution. I also don't know how to apply this filter to both the post type archive and the author archives using the same code snippet. I'm sorry I don't understand enough about PHP to do this myself, but I hope you can help me with the correct code.
Hmm, it shouldn't ever happen on single posts. Is there a specific page where I can see that happening?
Hi Tom, thank you for replying. I've turned on the snippet again, so now can see it in action on any page, like this one (link). You can also see something strange happening on the front page: the footer is where the main content should start.
This is the full snippet I'm using:
add_filter( 'generate_blog_columns','tu_portfolio_columns' );
function tu_portfolio_columns( $columns ) {
if ( is_author ) {
return true;
}
return $columns;
}
add_filter( 'generate_blog_masonry','tu_portfolio_masonry' );
function tu_portfolio_masonry( $masonry ) {
if ( is_author ) {
return 'true';
}
return $masonry;
}
I also tried disabling all GP Elements that are active, without result.
Instead of is_author, try is_author().
Let me know :)
Thank you so much Tom, that did it! :-)
So now I'm using this as the filter for columns in all relevant views (author, taxonomy, archive):
add_filter( 'generate_blog_columns','tu_portfolio_columns' );
function tu_portfolio_columns( $columns ) {
if ( is_author() ) {
return true;
}
if ( is_tax( array( 'keuken', 'gerechtsoort' ) ) ) {
return true;
}
if ( is_post_type_archive( 'recept' ) ) {
return true;
}
return $columns;
}
It's working great, thanks again!
You're welcome :)