Site logo

Archived topic

Custom page header in taxonomy archive page

19 replies · Started by Dani on July 15, 2016

Viewing posts 1–15 of 20

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.

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!

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 :)

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.

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

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 :)

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

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.

Thanks, Tom - I'll tinker around with this and see what I come up with!

No problem! Let me know how it works :)

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!

Glad it's working!

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

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?

This archived topic is closed to new replies.