user2650940
user2650940

Reputation: 11

PHP - Identify and hide link to same page

I have 3 PHP pages with the same subject (shoe1.php, shoe2.php, shoe3.php).

At the bottom of each page I am including a list of links to all shoe-related pages. This list points to shoe1.php, shoe2.php, shoe3.php.

I would like to know how can I automatically trim the list by hiding the link to shoe1.php if the list is at the bottom of shoe1.php, and so on for shoe2.php and shoe3.php.

Currently on the shoe1.php pages I use

<?php
$title = 'Shoe1';
$path = getenv('SCRIPT_NAME');
$filename = basename($path, ".php");
$imagename = $filename;
?>

to identify the page filename ("shoe1"), and then

<p><img src="images/<?php echo("$imagename"); ?>.jpg" border=0></P>

to load an image with the same name of the page (shoe1.jpg for shoe1.php).

I then include my list of links

<? ini_set('include_path',$_SERVER['DOCUMENT_ROOT'].'/folder_path'); include('shoe_links.php'); ?>

Currently this list shows all 3 links to shoe1.php, shoe2.php, shoe3.php.

How can I use the same parameters in the hosting page shoe1.php to hide from shoe_link.php the first of the 3 links (the link to shoe1.php)?

Thank you in advance for your help.

Upvotes: 1

Views: 226

Answers (1)

Kender
Kender

Reputation: 1264

on your included file you should be able to add this to get the file name of the page you are on

$path = getenv('SCRIPT_NAME');
$filename = basename($path, ".php");

then for your links you can do something like

$link = '';
$link .= ($filename != 'shoe1') ? '<a href="shoe1.php" title="shoe1">Shoe 1</a> | ' : null;
$link .= ($filename != 'shoe2') ? '<a href="shoe2.php" title="shoe2">Shoe 2</a> | ' : null;
$link .= ($filename != 'shoe3') ? '<a href="shoe3.php" title="shoe3">Shoe 3</a>' : null;

basically it says.. if the file name is not "shoe#" display the link, else do nothing.

Upvotes: 1

Related Questions