Change tagline in header title area based on category

Support Forums for LiveMesh Themes & Plugins Forums Invent Theme Support Change tagline in header title area based on category

This topic is: not resolved

This topic contains 4 replies, has 2 voices, and was last updated by Palmtree palmtree 2 years, 6 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #26658
    Palmtree
    palmtree
    Participant
    Post count: 126

    I’m wondering how to change H2 class tagline that goes into the header title area. I have found by rewriting header-title-area.php in child theme can do this job. However, I’m stuck because in_category or is_category don’t seem to work. Around line 150 of the header-title-area.php (framework > functions). There is conditional declaration like below. And I have added some categories like coupons and shops but they are ignored. I have also tried is_singular, both in, is category and using ID value instead of slug. None of them worked.. Currently single post title (detail page title) outputs just “Blog”. News category outputs “news”.

            elseif (is_singular('news')) {
                $tagline = mo_get_theme_option('mo_news_tagline', __('News', 'mo_theme'));
                echo '<h2 class="tagline">' . $tagline . '</h2>';
            }
            elseif (in_category('coupons')) {
                echo '<h2 class="tagline">Coupons</h2>';
            }
            elseif (in_category('shops')) {
                echo '<h2 class="tagline">Shops</h2>';
            }
            elseif (is_singular('post')) {
                echo '<h2 class="tagline">' . $tagline . '</h2>';
            }
            elseif (is_archive() || is_search()) {
                get_template_part('loop-meta'); // Loads the loop-meta.php template.
            }
            elseif (is_404()) {
                echo '<h1>' . __('404 Not Found', 'mo_theme') . '<h1>';
            }
            else {
                echo mo_get_entry_title(); // populate entry title for page and custom post types like portfolio type
            }

    Furthermore, What I actually want to do with this output is.
    For the parent category, if the category name is “Shops”, the title is “Shops”. Which is fine. But when this Shops category has multiple child categories like A and B and so on. I want child category top page title to be “A (Shops)” and “B (Shops)” instead of just “A” and “B”. Simply express the title I want for the child category is “Child category name (Parent category name)”.

    And the detail page title (single post page title) of the child category A and B to output the same as their category top title “A (Shops)” and “B (Shops)”. Those titles are currently “Blog”.

    #26691
    Raghavendra
    Raghavendra
    Moderator
    Post count: 4682

    For single posts, you can try this piece of code in the above quoted method –

    
            elseif (is_singular('post')) {
                $categories = get_the_category();
                echo '<h2>';
    
                foreach ($categories as $cat) {
                    echo get_category_parents($cat, true, ' ');
                    echo ' - ';
                }
                echo '</h2>';
            }
            elseif (is_archive() || is_category()) {
                $cat = get_category( get_queried_object_id());
                echo '<h2>';
                echo get_category_parents($cat, true, ' ');
                echo '</h2>';
            }
            elseif (is_archive() || is_search()) { ...

    Customize for separators according to your needs.

    #26693
    Palmtree
    palmtree
    Participant
    Post count: 126

    Thanks a lot Meteorite..
    Now the parent category is output but instead of writing “Parent – Child”, is is written “Parent Child-“. As I am not a programmer, I couldn’t know where to place that echo ' - ';..

    #26711
    Raghavendra
    Raghavendra
    Moderator
    Post count: 4682

    Have you tried passing a separator to the function get_category_parents() this way –

    get_category_parents($cat, true, '-');

    #26715
    Palmtree
    palmtree
    Participant
    Post count: 126

    No I didn’t try. get_category_parents($cat, true, '-'); worked! Thank you!

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Change tagline in header title area based on category’ is closed to new replies.