Shijil T Shijil T - 4 months ago 23
PHP Question

Disable a php code only in homepage

I want to add a php code in my CMS site's header, but dont want to run it in homepage. Because it causes errors!!

already tried this code, but it somehow still runs the code and shows error

<?php
$homepage = "/";
$currentpage = $_SERVER['REQUEST_URI'];
if($homepage==$currentpage) {
}
else
{CODE}
?>


It is not an error, if the php code run in the home page header , it will call for a database query, which the home page is not assigned to work for. I am trying to add an additional feature.

Error page

this is the code

<?php



$item = the_item();
$imgsd = 'store_avatar( ( !empty( $item->image2 ) ? $item->image2 : store_avatar( $item->store_img ) ) )';

?>

Answer

Try something more like this (might work):

<?php
    $homepage = array("/","/index.html","/index.php");
    $currentpage = strtolower($_SERVER['REQUEST_URI']);
    if(!in_array($currentpage, $homepage)) {    
        //Code goes here
    }
?>

P.S. : Try to ALWAYS indent your code especially when you post on the internet.

Comments