PHP experts, little help with wordpress title

Discussion in 'PHP' started by Googles76, Nov 10, 2005.

  1. #1
    Hi,

    I modified my wordpress header.php to have the title displayed like this:

    <title><?php single_post_title()?><?php single_cat_title()?> - <?php bloginfo('name')?> </title>
    PHP:
    So if the user is looking at just a category it will display the categorytitle - blogtitle, if they are looking at a permalink then it will have posttitle - blogitle

    This works like a charm however one little problem I ran into is when there is neither a category, nor a permalink, such as when the website is loaded for the first time, the title becomes - blogtitle. The probelm is that I don't want that dash to be there if there is nothing in front of it to display. So I was thinking is there any way to incorporate the dash only if single_post_title or single_cat_title are present?
     
    Googles76, Nov 10, 2005 IP
  2. dataman

    dataman Peon

    Messages:
    94
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Something like this...

    <title><?if ( ( $pt = single_post_title () ) || ( $pt = single_cat_title () ) ):?><?=$pt;?> - <?endif?><?=bloginfo ( 'name' );?></title>
    PHP:

    jb
     
    dataman, Nov 10, 2005 IP
  3. tlainevool

    tlainevool Guest

    Messages:
    1,071
    Likes Received:
    52
    Best Answers:
    0
    Trophy Points:
    0
    #3
    My advice was wrong, see next post

    It looks good, except you want to use '==' instead of '=' in the if.

    Like this...

    <title><?if ( ( $pt == single_post_title () ) || ( $pt == single_cat_title () ) ):?><?=$pt;?> - <?endif?><?=bloginfo ( 'name' );?></title>
    PHP:
     
    tlainevool, Nov 10, 2005 IP
  4. dataman

    dataman Peon

    Messages:
    94
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    No you don't want to use * == *! I am assigning $pt the functions value so use like I said * = *!

    jb
     
    dataman, Nov 10, 2005 IP
  5. tlainevool

    tlainevool Guest

    Messages:
    1,071
    Likes Received:
    52
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Oh, I get sorry for the good up.
     
    tlainevool, Nov 10, 2005 IP
  6. Googles76

    Googles76 Peon

    Messages:
    664
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    0
    #6
    This way only permalink title works, all others have just - blogtitle

    THe way with single = everything works but there is no - anywhere.

    Hmm, not sure how the if statements work here. Does blogger assume if those variables have 0 characters than the if statement returns false?
     
    Googles76, Nov 10, 2005 IP