• Hey,

    I have the problem that, on my news (blog) page, where all the posts are displayed, it should display the page title on top, not the first posts title.

    Currently it is like this:
    The posts page is called “Blog”, but inside my h1 it always displays the first posts title.

    Code:

    <?php
    $sub_title=get_post_meta($post->ID,'subtitle',true);
    if($sub_title != '') {
    echo '<h1><span>'. get_the_title() .'</span>'. $sub_title .'</h1>';
    }else {
    echo '<h1 style="background: none;"><span>'. get_the_title() .'</span></h1>';
    }

    (I’m using a function to create a header with a subtitle.)

    I tried this, which does not work inside my function correctly. It does only work when i’s inside the ‘else’.

Viewing 1 replies (of 1 total)
  • as this seems to be the page set to be the ‘posts page’ under dashboard – settings – reading, you need to retrieve the page ~ID first;

    adapted, for example (might need an ‘else’ section if you are using the same code on ‘normal’ static pages):

    if( is_home() && get_option('page_for_posts') ) : $sub_title=get_post_meta(get_option('page_for_posts'),'subtitle',true);
    if($sub_title != '') {
    echo '<h1><span>'. get_the_title(get_option('page_for_posts')) .'</span>'. $sub_title .'</h1>';
    }else {
    echo '<h1 style="background: none;"><span>'. get_the_title(get_option('page_for_posts')) .'</span></h1>';
    }
    endif;
Viewing 1 replies (of 1 total)
  • The topic ‘Display page title of the news page, not the first posts title’ is closed to new replies.