Do not pull information only in index

3

Well, I'll try to explain as best I can, I know this can be simple but at the same time I do not know how I can do this ...

Let's say that in my Header I have a 'bar' that I would like to appear on all the pages that I pull the LESS header in the index for a Slide that I put ...

(incasethisbluebarIwantedittoappearonallpagesexcepttheindex)

Solutionifitisadivitself.

<?phpvar_export($_SERVER['REQUEST_URI']);$array=explode("/", $_SERVER['REQUEST_URI']);
$url = str_replace("/", "", $_SERVER['REQUEST_URI']);
$pagina = end($array);


if ($url != 'apcefsp') {
    ?>
    <div><img src="http://localhost/apcefsp/wp-content/uploads/2017/10/ficha-1.png"alt="" width="100%" height="5"/></div> 
    <?php
}
?>

Is there any way to pull the different header? or any CSS that makes such a div does not appear except in the index?

    
asked by anonymous 27.10.2017 / 15:45

1 answer

3

In this way you get the current page, if it is different from 'index.php' it includes the code with the bar.

<?php
$array = explode("/", $_SERVER['PHP_SELF']);
$pagina = end($array);
if($pagina != 'index.php'){
    include 'barra.php';
}

For DOM element as a div:

<?php
$array = explode("/", $_SERVER['PHP_SELF']);
$pagina = end($array);
if ($pagina != 'index.php') {
    ?>
    <div>Sua div</div>
    <?php
}
?>

Explaining the code

Get the current url without the host:

$_SERVER['PHP_SELF']

Example:

  

/pagina/teste.php

Create an array with the division of the string that are separated by "/":

var_export(explode("/", $_SERVER['PHP_SELF']));

Example:

array ( 0 => '', 1 => 'pagina', 2 => 'teste.php', )

Get the last array item:

$pagina = end($array);

In the case of this example:

  

'test.php'

Then it checks if it is not in the index to show the div:

if ($pagina != 'index.php') {
    ?>
    <div>Sua div</div>
    <?php
}

To solve the problem, you had to use $ _SERVER ['REQUEST_URI'], since the variable was dynamic, but the idea is the same as the example above.

    
27.10.2017 / 15:59