WordPress.org

Ready to get started?Download WordPress

Forums

recent post title showing as page title. (4 posts)

  1. Another Account
    Member
    Posted 1 year ago #

    Hello,

    So here is the situation. I have no plugins running, so I am sure its not the plugins. I have cleaned up my database a couple of times and thats not it either.

    In my header file I have the following code

    <div class="container headtitle">
    			<div id="b" class="last">
    				<div id="title"><h1><?php echo get_the_title(); ?></h1></div>
    	</div>
    </div>

    Which basically shows the page title on each page, except its not working for the 'Blog' page. On the blog page it shows me the title for the most recent blog post.

    <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    you need to get the page id for the 'blog page' or 'page for posts' from the options table in the database;

    change the one line:

    <div id="title"><h1><?php if( is_home() && get_option('page_for_posts') ) { $posts_page_id = get_option('page_for_posts'); echo get_the_title($posts_page_id); } else { echo get_the_title(); ?></h1></div>

    do you have the same page title problem for archive pages?

  3. Another Account
    Member
    Posted 1 year ago #

    Hi alchymyth,

    Thanks for the reply.

    Yes, the same thing has been happening on the archive page. The code you gave me doesn't return anything different. It's the same thing. I am sure there is a fix for this.

    Thanks for your help though.

  4. alchymyth
    Forum Moderator
    Posted 1 year ago #

    I forgot to check if you have a static front page and set the 'blog' page at the same time? ( http://codex.wordpress.org/Creating_a_Static_Front_Page )

    if not, and the 'blog' page is your home page, then my code would not work;

    this adapted code would show the title 'Home' on the 'blog' page, and the respective page title otherwise:

    <div id="title"><h1><?php if( is_home() && get_option('page_for_posts') ) { $posts_page_id = get_option('page_for_posts'); echo get_the_title($posts_page_id); } elseif( is_home() ) { echo 'Home'; } else { echo get_the_title(); ?></h1></div>

    it might be helpful if you could post a link to your site.

Topic Closed

This topic has been closed to new replies.

About this Topic