Support Forums for LiveMesh Themes & Plugins › Forums › Invent Theme Support › Change tagline in header title area based on category
Tagged: category, Header Title, tagline
- This topic has 4 replies, 2 voices, and was last updated 7 years, 10 months ago by
palmtree.
-
AuthorPosts
-
May 18, 2017 at 6:07 am #26658
palmtree
ParticipantI’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”.
May 22, 2017 at 12:36 pm #26691Raghavendra
ModeratorFor 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.
May 22, 2017 at 1:56 pm #26693palmtree
ParticipantThanks 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 thatecho ' - ';
..May 24, 2017 at 1:47 pm #26711Raghavendra
ModeratorHave you tried passing a separator to the function
get_category_parents()
this way –get_category_parents($cat, true, '-');
May 24, 2017 at 2:05 pm #26715palmtree
ParticipantNo I didn’t try.
get_category_parents($cat, true, '-');
worked! Thank you! -
AuthorPosts
- The topic ‘Change tagline in header title area based on category’ is closed to new replies.