- This topic has 7 replies, 3 voices, and was last updated 7 years, 7 months ago by Tom.
-
AuthorPosts
-
May 1, 2016 at 9:15 am #190765Susanne
Hi there, I looked everywhere for this info and could not find it:
I have created three custom post types for my portfolio. One of them has several categories. I want to display the category name as the title on my category archive page
Right now it just says “Archive”. I know there is a simple way to do this.
I see that there is a function that says<?php do_action( 'generate_archive_title' ); ?>
in the archive template. So I think I have to add a filter for that function?
Can you help? much appreciatedMay 1, 2016 at 9:54 pm #190895TomLead DeveloperLead DeveloperHmm, this is a tough one..
You would have to do something like this I think:
add_action( 'after_setup_theme','generate_taxonomy_title' ); function generate_taxonomy_title() { if ( is_tax( 'tax-slug' ) ) { remove_action( 'generate_archive_title','generate_archive_title' ); add_action( 'generate_archive_title','generate_custom_taxonomy_archive_title' ); } } function generate_custom_taxonomy_archive_title() { ?> <header class="page-header<?php if ( is_author() ) echo ' clearfix';?>"> <?php do_action( 'generate_before_archive_title' ); ?> <h1 class="page-title"> Your title </h1> <?php do_action( 'generate_after_archive_description' ); ?> </header> <?php }
Something along those lines..
May 2, 2016 at 8:30 am #191067SusanneThanks for your quick reply Tom. I am now thinking it would be better to make a custom page template that uses a filterable portfolio. That way I would not have to bother with archive titles at all. Will try to get some more info on that. I found a great link here:
how-to-build-isotope-portfolio-in-your-wordpress-theme/
Will try to make that happen and report back- This reply was modified 7 years, 11 months ago by Susanne.
May 2, 2016 at 9:55 am #191106TomLead DeveloperLead DeveloperCool π
August 2, 2016 at 7:50 am #214797HansHi Tom,
I am a novice and not that familiar with PHP. I tried for some hours to bring your code to work. I believe that it has an error. I printed out some information and got the feeling that the hook is at the wrong place. When it is invoked the post seems to be not yet activated. I printed out the post-type and the tax an both where empty. By the way – there seems to be a coding error at the end of the snippet.
Do you have an idea how the code could work correct and which hook should be used.
August 2, 2016 at 11:39 pm #215046TomLead DeveloperLead DeveloperHi Hans,
I just adjusted the code – sorry about that.
Let me know if it works now π
August 3, 2016 at 7:05 am #215180HansHi Tom,
unfortenately I did not succeed with your code. Either I got a syntax error or nothing happend using different hooks. I don’t know what I am making wrong. I use now a modification in template-tags.php at the end of the list of if … elseif which is working fine for me.
elseif ( is_tax() ) : $tax = get_taxonomy( get_queried_object()->taxonomy ); /* translators: 1: Taxonomy singular name, 2: Current taxonomy term */ printf( __( '%1$s: %2$s', 'genratepress' ), $tax->labels->singular_name, single_term_title( '', false ) ) ;
August 3, 2016 at 2:25 pm #215332TomLead DeveloperLead DeveloperIf that’s working, copy the entire function you’re editing in template-tags.php (including the function_exists() wrapper) and add it to your functions.php in your child theme (or another method: https://generatepress.com/knowledgebase/adding-php-functions/).
That will make it so you won’t lose your changes when you update π
-
AuthorPosts
- You must be logged in to reply to this topic.