If this page shows this,

On all pages except the contact page, I want it to display the following in include-header.php include.

<p><a href="contact.php">Contact</a></p>

On the page, contact.phpI want it to show:

<p><a href="index.php">Home</a></p>

Should it be possible right?

+5
source share
5 answers
<?php
if (stripos($_SERVER['REQUEST_URI'], 'contact.php')){
     echo '<p><a href="index.php">Home</a></p>';
}
else{
     echo '<p><a href="contact.php">Contact</a></p>';
}
+17
source
if ($_SERVER["SCRIPT_NAME"] == '/contact.php') {
    echo '<p><a href="index.php">Home</a></p>';
} else {
    echo '<p><a href="contact.php">Contact</a></p>';
}
+5
source

$_SERVER['PHP_SELF'], . basename() :

if( basename($_SERVER['PHP_SELF'], '.php') == 'contact' ) {
    // Contact page
} else {
    // Some other page
}
+3

:

<?php
$current_page = 'contact';
include('inc_header.php');
....
?>

inc_header.php:

<?php
if($current_page == 'contact') {
    // show home link
} else {
    // show contact link
}
?>
+1

if, . , :

function LinkToPageOrHome( $script, $title ){
   if ( strtolower( $_SERVER[ 'SCRIPT_NAME' ] ) == strtolower( $script) ){
       $script = 'home.php';
       $title = 'Home';
   }
   echo '<p><a href="' . $script. '">' . htmlentities( $title ) . '</a></p>';
}

This is a kind of dumb design approach, but you can use LinkToPageOrHome( 'page.php', 'My Page' );multiple templates and never worry about having a link to a page.

0
source

All Articles