SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot calmestghost's Avatar
    Join Date
    Dec 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamically Collect <h2> Tag

    I would like to dynamically collect the page content title <h2>Page 1</h2> into the browser title <title>Website.com - Page 1</title>. This must be incredibly simple, similar to collecting form data?

    Is there not a way to do something like:

    PHP Code:
    <title>Website.com - <?php echo $_something["pagetitle"]; ?></title>

    <h2 name="pagetitle">Page 1</h2>
    Of course this is inaccurate, but there must be a way to accomplish what I'm looking for with similar simplicity. Please let me know what the proper method is. Thank You

  2. #2
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You could just use a variable, like you did in your example, but put it in the h2 as well. Set it at the top of the page and it will appear in both.

  3. #3
    SitePoint Zealot calmestghost's Avatar
    Join Date
    Dec 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it's not too much trouble could you show me exactly how you'd code it because I'm working on it right now and I'm coming up blank?

  4. #4
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $strPageTitle 
    "Some Title";
    ?>

    [...]

    <title>Website.com - <?php echo $strPageTitle;?></title>

    <h2 name="pagetitle"><?php echo $strPageTitle;?></h2>

  5. #5
    SitePoint Zealot calmestghost's Avatar
    Join Date
    Dec 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's what I'm attempting:

    1. Defining the function of the given variable, name, id, constant, whatever you'd like to call it like so:

    PHP Code:
    <?php define("pagetitle","Page 1"); echo pagetitle?>
    2. And then trying to implement it into additional places like so:

    PHP Code:
    <?php echo($pagetitle); ?>
    as partly explained here:

    http://us2.php.net/manual/en/function.define.php

    I'm getting nothing, just blank space.

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    When you define constants you do not prefix them with the $ to call them.

    PHP Code:
    <?php
    define
    ('PAGE_TITLE','My Page Title');
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title><?php echo PAGE_TITLE?></title>
        </head>
        <body>
            <h2><?php echo PAGE_TITLE?></h2>
        </body>
    </html>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  7. #7
    SitePoint Zealot calmestghost's Avatar
    Join Date
    Dec 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Beautiful SilverBulletUK, absolutely beautiful... I love that feeling of relief and learning something new at the same time. Thank You


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
  •