Add Header to Category Pages

This topic contains 15 replies, has 4 voices, and was last updated by  Moez Tharani 8 years, 5 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #290292

    Moez Tharani
    Full Member
    Post count: 60

    I am using the 1280 Genesis child theme and modifying it to display a header on all pages. The code I’m using for this in the 1280 function.php is as follows. I’ve only extracted the code that determines whether or not to add the header. It’s separated out as such because I want on certain pages for it to grab the featured image, but on others (like geodirectory custom post types, I want a standard image). This works pretty much everywhere I want it to, except for geodirectory category pages and search pages (/places/category/ and /?geodir_search=1&stype=gd_place&sgd_placecategory%5B%5D=665&s=+&snear=&sgeodir_foodtypes%5B%5D=&sgeo_lat=&sgeo_lon=). Any thoughts on making it work for those two page types?

    
    
    	if ( is_page() || is_single() || is_category() || is_archive() || is_tag() || is_search() || ( is_home() && get_option('page_for_posts') ) ) 
    {
    		wp_enqueue_script( 'sk-backstretch', get_bloginfo( 'stylesheet_directory' ) . '/js/jquery.backstretch.min.js', array( 'jquery' ), '1.0.0' );
    	if ( is_singular( array( 'gd_place', 'gd_event', 'gd_pet_friendly', 'gd_adoptee' ) ) ) {
    		wp_enqueue_script( 'sk-backstretch-set', get_bloginfo('stylesheet_directory').'/js/backstretch-set.js' , array( 'jquery', 'sk-backstretch' ), '1.0.0' );
    		wp_localize_script( 'sk-backstretch-set', 'BackStretchImg', array( 'src' => str_replace( 'http:', '', 'https://petpedia.ca/wp-content/uploads/2016/08/featured_dark.jpg' ) ) );
    	} else {
    		wp_enqueue_script( 'sk-backstretch-set', get_bloginfo('stylesheet_directory').'/js/backstretch-set.js' , array( 'jquery', 'sk-backstretch' ), '1.0.0' );
    		wp_localize_script( 'sk-backstretch-set', 'BackStretchImg', array( 'src' => str_replace( 'http:', '', genesis_get_image( array('format' => 'url') ) ) ) );
    	}
    	} 
    #290368

    Guust
    Moderator
    Post count: 29970

    By default, GD Listings and Search pages have the same header as any other page using the 1280 Genesis child theme. So I am not quite following…

    #290512

    Moez Tharani
    Full Member
    Post count: 60

    Ok, I figured out a different approach to this, basically modifying the existing code instead of adding new code. In order to do what I need, I need to move the title from before the content sidebar to after the header. I changed:

    add_action( 'genesis_before_content_sidebar_wrap', 'geo1280_page_title', 10 );

    to

    add_action( 'genesis_after_header', 'geo1280_page_title', 10 );

    That has the desired effect on every page but the detailed listing page. On that page, the title is displayed twice. I don’t know enough about Genesis to understand why that’s happening. Any ideas? Link below shows the duplication.

    https://petpedia.ca/dog_parks/alberta/calgary/off-leash/confluence-park-west-nose-creek/

    #290528

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    I too am unsure of your desired outcome but this function might help you, you can identify GD pages with it: https://wpgeodirectory.com/codex/codex/geodirectory_functions/geodir_is_page/

    Thanks,

    Stiofan

    #290689

    Moez Tharani
    Full Member
    Post count: 60

    Well I’m past that now anyway. Now I just need to figure out why I get a duplicate header on the listing detail page. Any idea on that?

    #290925

    Paolo
    Site Admin
    Post count: 31211

    Hi,

    that’s because that theme already has an

    with the title in it in the detail page.

    If you use the function Stiofan provided as condition, you can use the old snippet if the page is a detail page and your new snippet for all other pages.

    Thanks

    #291290

    Moez Tharani
    Full Member
    Post count: 60

    I’d actually prefer to replace the header in the detail page too. Is there a way for me to remove the header on the detail page as well?

    #291563

    Paolo
    Site Admin
    Post count: 31211

    Hi,

    for that you will need to tweak the function function

    geo1280_page_title()

    in functions.php

    Thanks

    #291902

    Moez Tharani
    Full Member
    Post count: 60

    Alright guys. I get that you’re probably busy and it’s easy to try and dismiss things under the guise of “custom, non-supported”, but I’m paying so that I don’t have to spend hours finding one line of code. And yet, that’s exactly what I’ve been forced to do. After literally hours of going through code trying to figure out what the hell is going on, I discovered this gem in the Genesis compatibility:

    add_action('geodir_wrapper_open', 'geo1280_page_title', 101);

    This makes it so that a duplicate title will appear when you do this:

    add_action( 'genesis_after_header', 'geo1280_page_title', 10 );

    So ultimately, this successfully repositions the title, without a duplicate appearing on the detail page:

    
    
    remove_action('geodir_wrapper_open', 'geo1280_page_title', 10);
    add_action( 'genesis_after_header', 'geo1280_page_title', 10 );
    #291904

    Moez Tharani
    Full Member
    Post count: 60

    So as it turns out, this doesn’t do anything in the geo-1280 function.php:

    remove_action('geodir_wrapper_open', 'geo1280_page_title', 10);

    The only way I can remove the duplicate title is by commenting out this in the compatibility file:

    add_action('geodir_wrapper_open', 'geo1280_page_title', 101);

    Obviously, that isn’t ideal. What’s the right way of doing this?

    #292712

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi again,

    When removing an action you need the priority argument to be of the same value, in this case 101, so

    remove_action('geodir_wrapper_open', 'geo1280_page_title', 101);

    Thanks,

    Stiofan

    #294212

    Moez Tharani
    Full Member
    Post count: 60

    I reverted the change to the compatibility file and inputted your suggestion to the child function.php. It didn’t work. So I’m back to modifying the compatibility file. Thoughts?

    #295204

    Paolo
    Site Admin
    Post count: 31211

    Hi,

    please provide a link and admin credentials so that we can add the function for you.

    Thanks

    #295382

    Moez Tharani
    Full Member
    Post count: 60
    This reply has been marked as private.
    #296856

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hello,

    I had posted on this earlier but the reply seems missing..

    To remove the hook you must remove it after it was added: try this:

    
    
    add_action('after_setup_theme', 'my_gd_compat_php_genesis_geo_1280_fix', 12);
    function my_gd_compat_php_genesis_geo_1280_fix(){
    remove_action('geodir_wrapper_open', 'geo1280_page_title', 101);
    }

    Thanks,

    Stiofan

Viewing 15 posts - 1 through 15 (of 16 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount