I need a little help creating a current page link system that makes the link text bold but not linked. The basic concept is setup like this:

<strong>Link 1</strong> <-----------Current page is bold not linked
<a href="test.php">Link 2</a>
<a href="test2.php">Link 3</a>
<a href="test3.php">Link 4</a>

The pages that I am not currently on needs to have a link tag to link to them, but I want the current page to be just bold with no link tags.

If you can I want to setup my array to hold the data like so:

// Link Name => File Name
$links = array("link-1" => "test.php","link-2" => "test2.php","link-3" => "test3.php");

Member Avatar for diafol

For a list:

$links = array(
    array('label'=>'Link 1','url' => 'test1.php', 'title' => 'this will take you to xyz'),
    array('label'=>'Link 2','url' => 'test2.php', 'title' => 'this will take you to abc'),
    array('label'=>'Link 3','url' => 'test3.php', 'title' => 'this will take you to nmo'),
    array('label'=>'Link 4','url' => 'test4.php', 'title' => 'this will take you to pqr')
    );

$thispage = $_SERVER['PHP_SELF'];

$list = "<ul>";
foreach($links as $l){
    $list .= ($l['url'] == $thispage) ? "\n\t<li><strong>{$l['label']}</strong></li>" : "\n\t<li><a href=\"{$l['url']}\" title=\"{$l['title']}\">{$l['label']}</a></li>";
}
$list .= "\n</ul>";

echo $list;

If your array key is your label:

$links = array('Link-1'=> 'test2.php','Link-2'=> 'test1.php','Link-3'=> 'test3.php','Link-4'=> 'test4.php');

$thispage = $_SERVER['PHP_SELF'];

$list = "<ul>";
foreach($links as $k=>$v){
    $list .= ($v == $thispage) ? "\n\t<li><strong>$k</strong></li>" : "\n\t<li><a href=\"$v\">$k</a></li>";
}
$list .= "\n</ul>";

echo $list;

Hi,

For better result use :

$thispage = basename($_SERVER['PHP_SELF']);

I modified it just a little, but it is working great. Thanks diafol :)

Member Avatar for diafol

Akmozo is perfectly correct. Use basename.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.