Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Dynamic link and title.

  1. #1
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dynamic link and title.

    I'm looking for a way to make dynamic link and title. Here is what I'm trying to do. On the home page there is a latest news section. It will have three links to the latest press releases located on the PR page. The PR page has a large list of PRs in order by date with most current at the top. Each PR in the list is a simple link with the headline of the PR being the text in the link. You click the link and it opens a new window with the full PR.

    I would like my three links on the home page under latest news to dynamically automatically be the 1st three links in the PR list on the PR page. So the text in the link and link itself needs to be dynamic. I have no idea how to do this.

    Any ideas.
    Thanks

  2. #2
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Unless you need to update the list after the page initially loads, this would be better solved in PHP. JS would require AJAX, but use of AJAX is senseless unless you need to react to a change after the server sends the page to the client.

    Whichever language does it, you'll need to retrieve the PR page's HTML source, find the links, and put them on the home page.

    Well, there actually is another reason that JS would be required... Are the links generated by JavaScript on the PR page? If so, that complicates things because most PHP installations can't parse JavaScript.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  3. #3
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    No the links are not made by java script. They are static html normal links. I really have no idea what kind of script to be using so I just posted in java script. If php would be better than that is fine. I still have no idea how to do this in php tho. Any suggestions or code source.

    Thanks

  4. #4
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    There is actually a cleaner way to do this. If the PR links are originally stored in a PHP array in an included file, the file can be included on both pages and the HTML scraping is completely avoided.

    I'm not particularly interested in helping with a scraper, but if you need help with the array that should be pretty easy.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  5. #5
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok. I don't mind putting the PR links into a PHP array and then including the file on both home and PR pages. I just need to make it clear that I don't want all the PR links in my latest news section on the home page, just the first 3 links in the PR list. So that way when ever we add new links to the list the latest news section on the home page is always the latest 3 links.

    Thanks
    Chris

  6. #6
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Yeah, the first-three requirement is easy to satisfy. $links = array_splice($links, 3);

    As for the code, I'm waiting for you to get stuck trying. The first thing is to make the array and use it instead of a static list on the PR page. Then you just need to do the same thing on the home page with the first three links.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  7. #7
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry for not getting back to you until now. Had some things come up. I can now work on the project again.

    Ok so a made a little test array.

    <html>
    <head>
    <title>PHP Test</title>
    </head>
    <body>
    <?php
    $linksList[0] = "http://www.google.com";
    $linksList[1] = "testing";
    echo $linksList[0];
    ?>
    </body>
    </html>

    Just to test it out. It works fine. I will eventually put the array in an included file. But for now I'm just playing.

    Now it works but how would I make something like this in the array.

    <?php
    $linksList[0] = <a href="press/july 08 09.htm" target="_blank">MetaPower International, Inc. Increases Q1 2009 Revenue by 67 Percent as Compared to Q1 2008 as Stated on Pinksheets.com </a>;
    ?>

    If I try to echo that it fails because of the html code inside the array. At least that's my guess. I need the array to store the link + the text title that the link is applied to and then be displayed just like plain html

    <a href="press/july 08 09.htm" target="_blank">MetaPower International, Inc. Increases Q1 2009 Revenue by 67 Percent as Compared to Q1 2008 as Stated on Pinksheets.com </a>

    Thanks
    Chris

  8. #8
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Nah, PHP doesn't mind HTML values... You need to put the string in quotes (PHP thinks it's parse-able code) and escape the existing quotes so they don't terminate the string:
    Code:
    <?php
    $linksList[0] = "<a href=\"press/july 08 09.htm\" target=\"_blank\">MetaPower International, Inc. Increases Q1 2009 Revenue by 67 Percent as Compared to Q1 2008 as Stated on Pinksheets.com </a>";
    ?>
    You'll also need to build the array in a third file, and include the third file from the two pages. This helps you not forget to update the second page's data so they stay consistent. If you like, you could also query a database in the include so the links could be entered through a web page instead of a text-editor.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  9. #9
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    just use a flag to each page of your web.
    Example :
    index.php -> flag 1

    then, build a function for your header., include it to every page of your web.

    This is the header (dynamicHeader.php):

    function dynamicTitle($flag){
    switch($flag){
    case 1 : $title = "Trial Page";
    $description = "Test Of Description";
    $keyword = "trial, keyword";
    break;
    case 2 : /* make others like above */break;
    }
    echo '<title>'.$title.'</title>';
    }

    Each Page of your website, Include this :
    include "dynamicHeader.php";
    dynamicTitle(1);
    //this is the example for index.php, if you have another page, you may use : dynamicTitle(2); -> don't forget to make the case

  10. #10
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    OP: Note that I'm still ready to answer questions.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

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
  •