- This topic has 13 replies, 2 voices, and was last updated 3 years, 3 months ago by
Tom.
-
AuthorPosts
-
August 13, 2020 at 7:51 am #1401080
AdB
Hi, I’ve a question regarding archive.php
I created an archive template for a custom taxonomy (Standort): everything’s working fine.
Is there a way to redefine the order of the elements (meta, data, post title etc) for this archive?
for example,post category/ies
post title
post data
post excerptI already check out this post https://generatepress.com/forums/topic/customize-mobile-featured-image-archives/ but I guess I need a couple of more hints to achieve that π
I mean, the title / data / excerpt are already in this order. For this archive, I need only to move the categories on top. It’d be great also to know how generally can I define the order of such elements.
thank you very much!
Davide
August 13, 2020 at 2:18 pm #1401645Tom
Lead DeveloperLead DeveloperHi Davide,
Right now it’s not overly easy, but we have a solution on the horizon.
So basically we just need to move the categories to above the title for this specific archive? Not the single posts?
Let me know π
August 14, 2020 at 12:53 am #1402140AdB
Yes, exactly. Only moving the category for this archive, thank you!
(single post: I’ll put together “something” customized with some hooks. I’ve also a question regarding the single post layout, I’ll open another topic ;))
thanks
DavideAugust 14, 2020 at 9:28 am #1402939Tom
Lead DeveloperLead DeveloperYou could try this:
add_filter( 'generate_footer_entry_meta_items', function( $items ) { if ( is_post_type_archive( 'your-cpt-name' ) ) { return array_diff( $items, array( 'categories' ) ); } return $items; } ); add_action( 'generate_before_entry_title', function() { if ( is_post_type_archive( 'your-cpt-name' ) ) { $categories_list = get_the_category_list( ' | ' ); if ( $categories_list ) { printf( '<div class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</div>', esc_html_x( 'Categories', 'Used before category names.', 'generatepress' ), $categories_list ); } } } );
August 14, 2020 at 9:44 am #1402968AdB
aaa great thanks!
only one thing, the code should be for a taxonomy archive, so I changed is_post_archive() with
is_tax()add_filter( 'generate_footer_entry_meta_items', function( $items ) { if ( is_tax( 'standort' ) ) { return array_diff( $items, array( 'categories' ) ); } return $items; } ); add_action( 'generate_before_entry_title', function() { if ( is_tax( 'standort' ) ) { $categories_list = get_the_category_list( ' | ' ); if ( $categories_list ) { printf( '<div class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</div>', esc_html_x( 'Categories', 'Used before category names.', 'generatepress' ), $categories_list ); } } } );
seems to work fine. I was about to write a quite related question in another post, but I guess I’ll continue here (summarized: how can I display the categories / tags / author of a custom post type in an archive page. Normally only the post title, excerpt and custom image are displayed. With the code above I noticed that the category is displayed also for the custom post type, so you “accidentally” anticipated me)
August 14, 2020 at 12:51 pm #1403217Tom
Lead DeveloperLead DeveloperAwesome! So it’s working for both needs now?
Thanks for posting your code π
August 16, 2020 at 1:18 pm #1405399AdB
Hi Tom, I didn’t test it with the custom post type archive.
With this “custom taxonomy archive page”, it seems to work fine, but what if I’d like to do the same also with both the category archive and the tag archive? They’re both taxonomy, so it should work … but actually it doesn’t Β―\_(γ)_/Β―
and also, since the code above displays the categories of the custom posts too (which is not happening within a standard archive page), there’s a way to do the same also for the posts date? It should go here –> ‘generate_after_entry_title’.
Thank you very much
DavideAugust 17, 2020 at 8:43 am #1406463Tom
Lead DeveloperLead DeveloperYou would have to expand your
is_tax()
to include those other taxonomies I think.Doesn’t the post date display after the title by default?
August 17, 2020 at 2:34 pm #1406883AdB
Hi Tom,
with the custom post types, the post metadata (tags, category, post date etc.) aren’t displayed in the archive pages (post archive, meta archive etc.).So I did some further research, I found this post of yours:
I add the piece of code to my custom posts and to the standard wp-post type.
Everything’s fine, except that in archive, for the standard posts, the post date and the categories are shown twice.I solved the post date “problem” with that
add_action( 'after_setup_theme', function() { remove_action( 'generate_after_entry_title', 'generate_post_meta' ); } );
How can I also remove the standard categories? With something like: “remove_action( ‘generate_after_entry_content’, ……. ” ?
thank you
DavideAugust 18, 2020 at 10:04 am #1408104Tom
Lead DeveloperLead DeveloperInstead of that code, this filter might be worth checking out: https://docs.generatepress.com/article/generate_entry_meta_post_types/
August 18, 2020 at 1:16 pm #1408378AdB
Hi Tom, thanks.
the code from your last post works fine for the post-dates (& meta).
Doing so I’m back with the categories display problem (the code of this post is not working with the normal categories and taxonomy archives.That’s why I went on with my research and found your other post which is working perfectly except that the post date and post categories of the standard post are displayed twice.
For the post-date I solved it like indicated in my last post, regarding the double categories, I now tried with some css
.cat-links {display:none;}
it seems to work, but I’m not 100% sure about that, that’s why I’m still looking for something like remove_action.Does it make sense? (a bit confused I know ;))
thanks!Davide
August 19, 2020 at 9:01 am #1409809Tom
Lead DeveloperLead DeveloperSo the only issue now is the double categories?
Where are the second set of categories displaying?
August 19, 2020 at 2:14 pm #1410160AdB
Hi Tom,
exactly.
the second set of categories are actually the standard one, so on the archive page they’re displayed after the excerpt.thank you
August 20, 2020 at 9:22 am #1411432Tom
Lead DeveloperLead DeveloperRemoving those is what this function should do:
add_filter( 'generate_footer_entry_meta_items', function( $items ) { if ( is_tax( 'standort' ) ) { return array_diff( $items, array( 'categories' ) ); } return $items; } );
You just need to make sure the condition is correct. If it’s not working, what’s the condition you’re trying?
-
AuthorPosts
- You must be logged in to reply to this topic.