Before you ask please READ THIS

How to change title from default posts page title to category page title

edited June 2014 in Hypershot Posts: 67
Hi Air,

Long time. :)

I have a page that shows my posts (posts page) and I have two other pages that show specific category posts. The posts that show on the latter do not appear on the former (by tweaking the code). Everything is fine, except when I click on a specific post on the category posts page: the title shows the default posts page title instead of the category page title.

To illustrate:

Page AAA (BLOG on the demo)
Post #1
Post #2

Page BBB (CATEGORY ARCHIVES: POST on the demo)
Post #3
Post #4

Page CCC (another CATEGORY ARCHIVES: POST)
Post #5
Post #6

When I go to Post #1, the title shows 'AAA' (BLOG on the demo), which is fine. However, when I go to Post #3 and Post #5, the page (header?) title also shows 'AAA' instead of 'BBB' and 'CCC', respectively. Would it be possible to change this?

I hope I was able to articulate my question well.

Thank you in advance for your help,
LazyDiver

Comments

  • AirAir
    Posts: 10,970
    Hi:-)

    It is not so easy, cause:
    1) This posts are still part of the blog.
    2) Each post can have many categories.

    this means you will have to write specific code to detect that post is in your special category and then display different title then 'Blog'.

    With regards.
  • edited June 2014 Posts: 67
    Hi Air,

    I think it's this part of utilities.php that I need to revise in order to achieve what I want:
    <?php
                    if($apollo13->get_option( 'blog', 'info_bar_blog_title' ) == 'on'){
                        $blog_h1 = get_the_title(get_option('page_for_posts'));
                        if ( !empty( $blog_h1 ) ){
                            echo ( empty( $blog_h1 ) ? '' : '<h1 class="page-title">' . $blog_h1 . '</h1>' );
                        }
                    }
                ?>
    But how do I change it exactly? Could you please help me? :) I tried to do it myself, but to no avail.

    Let's say I have a category called XXX (ID=11), the title of which I would like to show instead of $blog_h1.

    Many thanks in advance,
    LazyDiver
    Post edited by Air on
  • AirAir
    Posts: 10,970
    In line 689 you have $blog_h1 = get_the_title(get_option('page_for_posts')); Try changing its value to see different results. Now you have to something like:

    if( in_array( 1, wp_get_post_categories( get_the_ID() ) ) ){
    $blog_h1 = 'in category 1';
    }
    elseif( in_array( 11, wp_get_post_categories( get_the_ID() ) ) ){
    $blog_h1 = 'in category 11';
    }
    else{//blog
    $blog_h1 = get_the_title(get_option('page_for_posts'));
    }
    Hope that helps.

    With regards.
  • Posts: 67
    It worked, Air, thanks!

    Just a follow-up question: Do I have to replace the file in the parent theme and do this every time I update? I tried saving a modified utilities.php in the child folder, but the changes did not take effect.

    Regards,
    LazyDiver
  • AirAir
    Posts: 10,970
    You have to just copy function that you changed like explained here: http://apollo13.eu/docs/hypershot/#!/modification_of_theme_changing_theme_functions

    With regards.
  • Posts: 67
    Got it. The instructions were very easy to follow. Thank you! :)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion