Archived topic
Taxonomie for pages -> colums for pages in archives
3 replies · Started by Mi on May 30, 2022
Hello again,
i read a lot in the forum and found a lot of helpful stuff, but not exactly what I am looking for.
My website is based mostly on pages and because there are so many of them I want to add categorys and tags to them. I did this via adding this in the functions.php:
function add_taxonomies_to_pages() {
register_taxonomy_for_object_type( 'post_tag', 'page' );
register_taxonomy_for_object_type( 'category', 'page' );
}
add_action( 'init', 'add_taxonomies_to_pages' );
if ( ! is_admin() ) {
add_action( 'pre_get_posts', 'category_and_tag_archives' );
}
function category_and_tag_archives( $wp_query ) {
$my_post_array = array('post','page');
if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) )
$wp_query->set( 'post_type', $my_post_array );
if ( $wp_query->get( 'tag' ) )
$wp_query->set( 'post_type', $my_post_array );
}
Works perfect. - But now I can´t give the pages-previews in the archives-page the same design as the posts. (see here -> https://www.ffcorner.com/testwp/tag/tifa/ First Entry is a post, the next are pages)
I tried it with css and with the Colums to custom post types filter -> https://docs.generatepress.com/article/using-columns-in-the-blog/#adding-columns-to-your-custom-post-type
but I could´t get it to work.
I didn´t want to try the WPSP, because I´ve read that there will be no more updates and that it is coming with the new GenerateBLock version. Should I wait for this or is there any other way I can go for now?
Thank you!
Hi there,
the GP blog columns apply to the post post type.
But we can filter in other post types using the snippet provided here:
Which should be:
add_filter( 'generate_blog_columns', function( $columns ) {
if ( 'page' === get_post_type() && ! is_singular() ) {
return true;
}
return $columns;
} );
I already tried this ..... and it didn't work. Now it does ^^'
Thanks a lot and sorry for the circumstances!
No problems - glad to hear it is working!