Do not pull information on index only

Asked

Viewed 86 times

3

Well I’ll try to explain it as best I can, I know it can be simple but at the same time I don’t know how I can do it...

Let’s say in my Header I have a 'bar' that I would like to appear on all pages that I pull the MINUS header into the index because of a Slide that I put...

Essa seria a linha

(in case that blue bar I wanted it to appear on all pages except in index)

Solution if it is a div in itself.

    <?php
var_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 not appear except in index ?

  • Ta very vague, put details of what is really taking place to facilitate understanding...

  • I put an image to better understand ( the bar is a div )

  • That bar comes from a include() in php ?

  • @Axcse If I understand correctly it’s not just not putting the Html bar code on the Index page.

  • @Isac yes from Header

  • Send print_r($_SERVER); so you can see what’s happening there and show you the best way.

Show 1 more comment

1 answer

3


This way you take 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

Takes the current url without the host:

$_SERVER['PHP_SELF']

Example:

/page/test.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', )

Takes the last array item:

$pagina = end($array);

In the case of this example:

'php test.'

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

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

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

  • Look I didn’t quite understand this logic, but eh so the bar is in the header.php and I want all the contents of the header with a include() minus a specific div ( that is the one with the bar ) My god I’m very lost huAHUSHA beginner is fucked so

  • I edited the answer by placing with div instead of include

  • I made a new edition explaining the code.

  • I think I’m doing something wrong because it still wasn’t, or it appears at all depending on the parole or appears in anything xD

  • Put the code in your question for best help-Ló

  • Okay, I think I’m doing it wrong hahaha

  • With the help of Wictor we have solved the problem. Vlw guys

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.