MSUK1 Posted July 10, 2011 Share Posted July 10, 2011 Hello, i am wanting to show a logo on the home page, and on any other page, a completly different logo.. I was thinking about using what i know from shtml, but my site is in php? i was thinking it would be like.. if url == www.domain.com, then -> logo 1, else if !== www.domain.com then -> logo2? can anyone help me out wiht this? thanks, Quote Link to comment https://forums.phpfreaks.com/topic/241600-if-page-home-then/ Share on other sites More sharing options...
QuickOldCar Posted July 10, 2011 Share Posted July 10, 2011 <?php $server_page = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); //echo $server_page."<br />"; $current_page = end(explode("/", $server_page)); if($current_page == "index.php") { $logo = "./images/logo1.png";//use your logo location } else { $logo = "./images/logo2.png"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/241600-if-page-home-then/#findComment-1240943 Share on other sites More sharing options...
MSUK1 Posted July 11, 2011 Author Share Posted July 11, 2011 Thank you very much! please could you explain the "explode" part of this script what does htat mean? Quote Link to comment https://forums.phpfreaks.com/topic/241600-if-page-home-then/#findComment-1241197 Share on other sites More sharing options...
MSUK1 Posted July 11, 2011 Author Share Posted July 11, 2011 Hello, i have given this script a try, i am using wordpress and it thinks everypage is index.php http://bit.ly/oO36a3 i echo'd the "page" and yes, index.php everytime, Do you have another solution? or a work around this? Kind Regards Quote Link to comment https://forums.phpfreaks.com/topic/241600-if-page-home-then/#findComment-1241204 Share on other sites More sharing options...
QuickOldCar Posted July 11, 2011 Share Posted July 11, 2011 Yes i can see how that is possible. This will find home within each folder, meaning per script path or could very well be a subdomain path <?php //get the url from the address bar $current_url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); if (!empty($_SERVER["QUERY_STRING"])){ $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING); $current_url .= "?".$query_string; } //explode url into parts by /,get the last part $current_file_path = end(explode("/", $current_url)); echo $current_url."<br />"; echo $current_file_path."<br />"; if(empty($_SERVER["QUERY_STRING"]) && $current_file_path == "index.php"){ echo "HOME"; } else { echo "NOT HOME"; } ?> Otherwise, this may just work for you <?php //get the url from the address bar $current_url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); if (!empty($_SERVER["QUERY_STRING"])){ $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING); $current_url .= "?".$query_string; } $home_url = filter_var("http://".$_SERVER['HTTP_HOST']."/", FILTER_SANITIZE_STRING); $index_url = filter_var("http://".$_SERVER['HTTP_HOST']."/index.php", FILTER_SANITIZE_STRING); if($current_url == $home_url || $current_url == $index_url){ $is_home = true; } if(empty($_SERVER["QUERY_STRING"]) && $is_home == true){ $logo = "./images/logo1.png";//use your logo location } else { $logo = "./images/logo2.png"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/241600-if-page-home-then/#findComment-1241457 Share on other sites More sharing options...
MSUK1 Posted July 12, 2011 Author Share Posted July 12, 2011 Sorry but neither of these work still? wordpress uses the htaccess file to create permalinks for the site.. So everything is run off of index.php ? So i still cannot get this to work ? Quote Link to comment https://forums.phpfreaks.com/topic/241600-if-page-home-then/#findComment-1241622 Share on other sites More sharing options...
QuickOldCar Posted July 12, 2011 Share Posted July 12, 2011 There is a wordpress home_url() and site_url() function http://codex.wordpress.org/Function_Reference/home_url Maybe can use that in some way, I don't know personally as I never tried to determine if was home or not in wordpress. Quote Link to comment https://forums.phpfreaks.com/topic/241600-if-page-home-then/#findComment-1241624 Share on other sites More sharing options...
MSUK1 Posted July 12, 2011 Author Share Posted July 12, 2011 for site directory url it alos shows www.domain.com as part of this function, however if somebody could add respectively into the code i will happily try it? Quote Link to comment https://forums.phpfreaks.com/topic/241600-if-page-home-then/#findComment-1241626 Share on other sites More sharing options...
QuickOldCar Posted July 12, 2011 Share Posted July 12, 2011 going by how wordpress displays the site description in header.php of a theme.... if (is_home() || is_front_page() ){ echo "HOME"; } else { echo "NOT HOME"; } It works, I tried it in a new wordpress install Quote Link to comment https://forums.phpfreaks.com/topic/241600-if-page-home-then/#findComment-1241675 Share on other sites More sharing options...
QuickOldCar Posted July 12, 2011 Share Posted July 12, 2011 Here's an example of how I made different images for the site names link in the default twentyeleven theme. I placed 2 images in the themes images folder, gave full url of the image. The new php area with check for is_home and is_front_page just after </head> For the sites link had to add <?php echo $custom_image;?> </head> <?php //php block added if (is_home() || is_front_page() ){ $custom_image ="<img src='http://localhost/wp-content/themes/twentyeleven/images/headers/logo.png'/>"; } else { $custom_image ="<img src='http://localhost/wp-content/themes/twentyeleven/images/headers/banner.jpg'/>"; } ?> <body <?php body_class(); ?>> <div id="page" class="hfeed"> <header id="branding" role="banner"> <hgroup> <h1 id="site-title"><span><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php echo $custom_image;//this instead of sites name ?></a></span></h1> <h2 id="site-description"><?php bloginfo( 'description' ); ?></h2> </hgroup> Quote Link to comment https://forums.phpfreaks.com/topic/241600-if-page-home-then/#findComment-1241682 Share on other sites More sharing options...
MSUK1 Posted July 12, 2011 Author Share Posted July 12, 2011 that works! Brilliant! Thank you for the help guys Quote Link to comment https://forums.phpfreaks.com/topic/241600-if-page-home-then/#findComment-1241778 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.