ThemeShaper Forums » Thematic

[closed]

Help with PHP

(9 posts)
  • Started 4 years ago by Jamie Mitchell
  • Latest reply from Jamie Mitchell
  • This topic is not resolved
  1. Jamie Mitchell
    Member

    hey all...

    i don't know php very well, i need to add a custom title to a home page in a banner (or leader) normal page titles for all pages and 404, and blog for the blog pages.

    i already have the snippet to remove the default page titles, i just need to put them back where i want them

    this is what i used before, and it works great, but i have nothing in there for if is_front_page

    function add_banner() {
        global $id, $post, $authordata;
        if (is_page()) {
            echo ('<div id="banner"><div id="banner-container"><h1>' . get_the_title() . "</h1></div></div>\n");
        } elseif (is_404()) {
            echo ('<div id="banner"><div id="banner-container"><h1>' . __('Not Found', 'thematic') . "</h1></div></div>\n");
        } elseif (is_home() || is_single()) {
            echo ('<div id="banner"><div id="banner-container"><h1>Blog</h1></div></div>');
        }
    }
    add_action('thematic_belowheader', 'add_banner');

    as soon as i add

    } elseif (is_front_page()) {
            echo ('<div id="banner"><div id="banner-container"><h1>front page title</h1></div></div>');
        }

    i just get a white screen

    thanks in advance...J

    Posted 4 years ago #
  2. @Jamie Mitchell: Maybe it's because I don't have a heavily customised child theme at the moment, so your code seems to work for me.

    Posted 4 years ago #
  3. Jamie Mitchell
    Member

    could somebody add

    } elseif (is_front_page()) {
            echo ('<div id="banner"><div id="banner-container"><h1>front page title</h1></div></div>');
        }

    to the larger piece of code above, maybe i did it wrong when i did it, should it be in any order, like if is_front_page, before is_page or something

    much appreciated.

    JM

    Posted 4 years ago #
  4. Jamie Mitchell
    Member

    anybody?

    Posted 4 years ago #
  5. Jamie Mitchell
    Member

    little help, anyone...pitty please !

    just need to get this little thing done.

    J

    Posted 4 years ago #
  6. @Jamie Mitchell: I'm not sure if I tested it correctly the first time, apologies. This slight change seems to work for me:

    function add_banner() {
        global $id, $post, $authordata;
        if (is_front_page()) {
            echo ('<div id="banner"><div id="banner-container"><h1>front page title</h1></div></div>');
        } elseif (is_404()) {
            echo ('<div id="banner"><div id="banner-container"><h1>' . __('Not Found', 'thematic') . "</h1></div></div>\n");
        } elseif (is_home() || is_single()) {
            echo ('<div id="banner"><div id="banner-container"><h1>Blog</h1></div></div>');
        } elseif (is_page()) {
            echo ('<div id="banner"><div id="banner-container"><h1>' . get_the_title() . "</h1></div></div>\n");
        }
    }
    add_action('thematic_belowheader', 'add_banner');

    All I've done is change the order so is_front_page is the first if.

    Posted 4 years ago #
  7. Jamie Mitchell
    Member

    hey !!!!!

    works perfect...thanks flick, hugely appriecated :)

    Posted 4 years ago #
  8. @Jamie Mitchell: Glad it worked out! I was mainly testing for non-white-screeness the first time round and forgot to check the actual output matched the ifs.

    I think, as you said in your post, it was mainly to do with the order of the ifs. What I found was, as a certain 'page' is defined as the static page, unless e.g. a single post was viewed, it would always display the name/title of the page and not 'front page title'.

    Learnt a teeny bit more about is_home, is_frontpage as a result, and this extra styling is really very nice! Hope that I can apply it properly to one of my sites soon.

    Posted 4 years ago #
  9. Jamie Mitchell
    Member

    good stuff!

    here is the other half, to remove the titles.

    function remove_title($posttitle) {
        if (is_page()) {
            return '';
        } elseif (is_404()) {
            return $posttitle;
        } else {
        		return $posttitle;
        }
    }
    add_filter('thematic_postheader_posttitle', 'remove_title');
    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.