View Full Version : Dynamic link and title.

06-20-2009, 08:17 PM
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.

06-20-2009, 10:30 PM
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.

06-21-2009, 03:19 AM
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.


06-21-2009, 05:01 AM
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.

06-21-2009, 05:34 AM
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.


06-21-2009, 05:50 AM
Yeah, the first-three requirement is easy to satisfy. $links = array_splice (http://us2.php.net/manual/en/function.array-splice.php)($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.

08-02-2009, 12:57 AM
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.

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

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.

$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>


08-02-2009, 02:03 AM
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:
$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.

08-08-2009, 10:09 AM
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){
case 1 : $title = "Trial Page";
$description = "Test Of Description";
$keyword = "trial, keyword";
case 2 : /* make others like above */break;
echo '<title>'.$title.'</title>';

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

08-09-2009, 06:53 PM
OP: Note that I'm still ready to answer questions.

09-05-2009, 04:22 AM
Ok sorry for taking forever again.

I have moved my link testing array to a 3rd file and included it in my links page. I reformatted the php to allow the HTML link coding.

Now the only thing I need to help doing is formatting my links output on my links page.

right now they are in a scrollable table. Obviuosly I don't just want a giant list of links. I would like them formatted with some spacing and what not. The output does not need to match 100% the current table structure output but needs to be simular.

How do I format my PHP output?

Here is my current CSS and Table structure

<style type="text/css">
div.tableContainer {
width: 100%; /* table width will be 99% of this*/
height: 450px; /* must be greater than tbody*/
overflow: auto;
margin: 0 auto;

thead tr {
top: expression(offsetParent.scrollTop); /*IE5+ only*/

thead td, thead th {
text-align: center;
font-size: 14px;
background-color: #C0C0C0;
color: #000000;
font-weight: bold;
border-top: solid 1px #d8d8d8;

table>tbody { /* child selector syntax which IE6 and older do not support*/
overflow: auto;
height: 400px;
overflow-x: hidden;

table {
width: 99%; /*100% of container produces horiz. scroll in Mozilla*/
border: none;
background-color: #f7f7f7;


<div class="tableContainer">
<table cellpadding="0" cellspacing="0" width="100%">
<td align="left" valign="top" width="20%">Date</td>
<td align="left" valign="top" width="80%">Title</td>
<td align="left" valign="top">July 08, 2009</td>
<td align="left" valign="top"><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></td>
<td colspan="2">&nbsp;</td>
<td align="left" valign="top">June 16, 2009</td>
<td align="left" valign="top"><a href="press/jun 16 09.htm" target="_blank">MetaPower International, Inc. Receives Australian Patent for UCoDA Business Process Management Technology </a></td>
<td colspan="2">&nbsp;</td>

Thanks for your help.

09-13-2009, 09:33 PM
NVM I got it.

I just included the table html in my php array with the " escaped out. Works great. Thanks for the info.