Archived topic
Archive pages content not identical
5 replies · Started by Mi on December 6, 2022
It´s me again, I´m sorry. I really have a problem to understand all the boxing things. I miss to see the code to understand what is happening there ... the boxes are so abstract to me. So I am very sorry for bothering you ...
I noticed, that my archive pages are looking different depending on whether a post or a page is displayed in the first place.
If the first entry is a post - everything is fine, everything looks as it should. If the first entry is a page, the date and all taxonomies are missing from the archive, even if the second entry is a post.
How can I make sure, that they all look the same? (Post first is the look that I want)
Hi Mi,
Pages don't have categories by default.
Can you try using a Block Element - Content Template? Reference: https://docs.generatepress.com/article/block-element-content-template/
A Content Template allows you to set how posts and pages appear on a category page. This should make the appearance look consistent.
I use this to add taxonomies to pages:
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 );
}
Everything is fine if the first entry in the archive is a post - then all the pages are displayed correctly too.
It is just not working if the first entry is a page. Then the taxonomies from the posts are not shown too.
I see. Can you try using a Content Template as mentioned?
Let us know how it goes.
I´m so sorry, but that is, what I mentioned above. I don´t understand this template things.
I already have a perfect archive - with one little issue.
If I now open a content template there is nothing there. Do I have to recreate everything? Where is my code to edit?
I have always worked with html pages. There was an archive template, I could see the code, understand what it does, see where the code snippet I want is missing, write it in. But in this templates there is no code. I am blind. What am I doing there? When I change it here, does it overwrite my page-hero designs? I am very sorry and really ashamed, but I have absolutely no idea what to do.
Yes, I'm presuming you have code to alter the way the Posts and Pages in archive pages are shown.
On the contrary, you don't need code with a Content Template. This is also our suggested way of modifying how Posts and Pages are shown on an Archive page. You just need to use Blocks.
It won't overwrite your Page Hero. It will just overwrite the way Posts and Pages are shown.
There are also templates you can begin with. Example: https://share.getcloudapp.com/7KujRyXl
The link I shared above also shows how to create one from scratch.
Basically, through this, you should be able to easily modify how pages and posts are shown in your Archive pages. And, this also ensures that they appear consistently all over your site.