Results 1 to 2 of 2

Thread: Creating dynamic and static titles

  1. #1
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Creating dynamic and static titles

    Hi,

    I'm trying to create some seo-friendly titles for site and need help with how to code the title tag.

    For the dynamic part I have received this:
    <title><?php if( $post ) { echo $post->post_title; }?></title>

    Now I want to add some static text next to this, so it would look like:
    Photo gallery >> Worlds leading school of photography.

    The 'Photo gallery' text is now generated by the dynamic title tag. I just want to know what the correct way is to add the static text: '>> Worlds leading school of photography.'

    Any help would be greatly appreciated!

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by DarkOcean View Post
    <title><?php if( $post ) { echo $post->post_title; }?></title>
    I just want to know what the correct way is to add the static text: '>> Worlds leading school of photography.'
    ...just add the static text:
    PHP Code:
    <title><?php if( $post ) { echo $post->post_title; }?> >> Worlds leading school of photography</title>
    however, it would be more robust like so:
    PHP Code:
    <?php
    // start
    $title '<title>';
    // check the actual property you're trying to use, not just the object
    // also, the way you do it above will still cause an error if $post does not exist
    // in the end, this:
    //   if( $post ){ echo $post->post_title; }
    // is no different than:
    //   echo $post->post_title;
    // except that you have _two_ opportunities to run into problems.
    if( !empty( $post->post_title ) ){ $title .= $post->post_title; }
    // add the static part, and finish
    $title .= ' >> Worlds leading school of photography</title>';
    // when you're ready...
    print $title;
    also,
    Please use the forum's bbcode tags and indent your code to make it more readable:

    for php code............[php] <?php /* code goes here */ ?> [/php]
    for html...............[html] <!-- markup goes here -->.....[/html]
    for js/css/other.......[code] code goes here................[/code]
    Last edited by traq; 05-04-2012 at 07:54 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •