Cyber Week Sale! Get $20 off GP Premium, $40 off our new Lifetime license, and 45% off license renewals/extensions! Learn more

[Resolved] Custom page header in taxonomy archive page

Home Forums Support Custom page header in taxonomy archive page

  • This topic has 19 replies, 4 voices, and was last updated 4 years ago by Tom.
Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #209925
    Dani

    How can I setup this taxonomy pages:
    http://espaipiscines.finismedia.com/tipus-producte/piscines/

    To be like this single taxonomy page (merge with header and transparent menu) ?
    http://espaipiscines.finismedia.com/productes/piscina-obra-mosaic-blau/

    In the single, I have the controls to setup this, but i can have control in taxonomy pages… Can I change the header with any add_action hook?

    Thank you!

    #210031
    Tom
    Lead Developer
    Lead Developer

    Interesting – is that a page you can edit in the Dashboard? It looks like you’re using the Page Header metabox on it?

    Typically, using the Page Header metabox isn’t possible on archives/blogs, so I’m curious how you got it to work so far.

    #210733
    Dani
    add_action( 'generate_after_header', 'fm_titol_projectes');
    function fm_titol_projectes() {
    	$queried_object = get_queried_object(); 
        if ( is_tax("tipus_producte") && !is_front_page()) {
    			echo '<div class="page-header-content parallax-enabled generate-page-header generate-content-header" style="background-image: url('. get_stylesheet_directory_uri() .'/images/back-header-piscines.jpg);background-size:cover">
    				<div class="inside-page-header-container inside-content-header grid-container grid-parent ">
    					<div class="inside-page-header">
    						<h1 style="margin:0;text-shadow: 0 0 6px rgba(0,0,0,.6)">'. $queried_object->name .'</h1>
    					</div>
    				</div>
    			</div>';
    	}	
    }

    I’ve wrote this function. But i’d like to merge with header this taxonomy archive pages, like in this page http://espaipiscines.finismedia.com/contacte/

    Thank you!

    #210903
    Tom
    Lead Developer
    Lead Developer

    Hmm, you would need to split it up into two functions:

    add_action( 'generate_before_header', 'fm_titol_projectes_before');
    function fm_titol_projectes_before() {
    	$queried_object = get_queried_object(); 
        if ( is_tax("tipus_producte") && !is_front_page()) {
    		echo '<div class="page-header-content parallax-enabled generate-page-header generate-content-header" style="background-image: url('. get_stylesheet_directory_uri() .'/images/back-header-piscines.jpg);background-size:cover">
    			<div class="inside-page-header-container inside-content-header generate-merged-header grid-container grid-parent ">';
    	}	
    }
    
    add_action( 'generate_after_header', 'fm_titol_projectes');
    function fm_titol_projectes() {
    	$queried_object = get_queried_object(); 
        if ( is_tax("tipus_producte") && !is_front_page()) {
    		echo '<div class="generate-combined-content grid-container grid-parent">
    				<div class="generate-inside-combined-content">
    					<h1 style="margin:0;text-shadow: 0 0 6px rgba(0,0,0,.6)">'. $queried_object->name .'</h1>
    				</div>
    			</div>
    			</div>
    		</div>';
    	}	
    }

    Not 100% sure it will work at all, but worth a shot 🙂

    #211226
    Dani

    Very very good!

    This function inspired me! This is what I wanted. Now, I have this:

    http://espaipiscines.finismedia.com/tipus-producte/piscines/

    Thank you!

    PD: It would be great, to implement this somehow….. with the WP metaboxes…. Maybe a plugin…

    #211267
    Tom
    Lead Developer
    Lead Developer

    Great!

    It’s tough to add as an option, as taxonomy/archives pages like this don’t have an “edit page” area to add the options to.

    #243309
    Marc

    Hey Tom,

    I’m about to implement this workaround for a client, but I’m a bit worries about the sustainability. For instance, if you update the HTML structure of the page header in future GeneratePress updates, won’t this workaround break?

    Is there an alternative solution to this or should I stick to placing this code in the GP Hooks for now?

    Thanks man!

    -Marc

    #243310
    Tom
    Lead Developer
    Lead Developer

    The next update to GP Premium has a filter so we can tell GP to place the Blog Page Header (built in the Customizer) wherever we live.

    If you’d like to shoot me an email I can send you the latest version to try it out 🙂

    #243323
    Marc

    Wow, thanks! Just sent you an email…excited to see if this works. 😀

    #243326
    Tom
    Lead Developer
    Lead Developer

    Just sent it to you.

    This is what you would do:

    add_filter( 'generate_get_blog_page_header','tu_global_page_header' );
    function tu_global_page_header()
    {
        // Add your conditional to show the blog page header - is_home() is default
        if ( is_home() )
            return true;
    
        // If the conditional isn't true, set it to false
        return false;
    }

    Note to others: This will work as of GP Premium 1.2.92.

    #243328
    Marc

    Thanks, Tom – I’ll tinker around with this and see what I come up with!

    #243330
    Tom
    Lead Developer
    Lead Developer

    No problem! Let me know how it works 🙂

    #243336
    Marc

    Alright, looks like I’m able to put the blog page header on the page archives now. Wooo!

    Had to make some small changes to the code (for the archive):

    add_filter( 'generate_get_blog_page_header','tu_global_page_header' );
    
    function tu_global_page_header(){
    
        // Add your conditional to show the blog page header - is_home() is default
        if ( is_archive() )
            return true;
    
        // If the conditional isn't true, set it to false
        return false;
    }

    Going to try tinkering a bit more to make the blog page header more flexible (will pull archive descriptions when the page is an archive, etc.).

    Ideally, something like this would exist in the GenerarePress settings (with a menu for each new custom post type the user creates). Obviously this would take quite a while to implement, just some food for thought.

    Thanks for all your help here Tom!

    #243339
    Tom
    Lead Developer
    Lead Developer

    Glad it’s working!

    Options for stuff like this can get a little too crazy. Filters are awesome for complex stuff 🙂

    #249179
    Igor

    I’ll wait to 1.2.92 to get this working, looks nice. But also I’d like to know which is the best way to put a page header for example in a custom post type archive or a custom taxonomy term page. I could make something like this:

    add_action('generate_after_header', 'my_custom_generate_after_header', 0);
    
    public function my_custom_generate_after_header(){
        		
     if(is_post_type_archive('my-custom-post-type')){   
              $html = '
    			<div class="page-header-content parallax-enabled generate-page-header generate-content-header">
    				<div class="inside-page-header-container inside-content-header grid-container grid-parent ">
    					<div class="generate-inside-page-header-content">
    						<div class="inside-page-header">
    							<h2>Title for mi custom post type archives</h2>
    						</div>
    					</div>
    				</div>
              </div>';
    
              echo $html;
        }
    }

    But it is not a clean solution. Any ideas? Could be possible to create a Page Header dinammically for example with a shortcode and its attributes?

Viewing 15 posts - 1 through 15 (of 20 total)
  • You must be logged in to reply to this topic.