Not sure how to explain this but i'm trying to run (2) php if statements together using a getIsHomePage block of code. I need for the div replacement to be true if home page = yes and if "certain page url" = yes. If not either of these two pages then the 'else' statement should be true.
Here is the code block I have now:
<?php if(Mage::getBlockSingleton('page/html_header')->getIsHomePage()) {
echo '<div class="main">';
} else {
echo '<div class="main container">';
}
?>
Any assistance would be appreciated.
Thanks,
Ryan.
You can use the below-mentioned code to check if you are on Home page or viewing your custom URL.
<?php
$myCustomUrl = "...";
if($this->getIsHomePage() || $myCustomUrl ) {
echo 'Either you are on Homepage or your page URL is : ' .$myCustomUrl;
} else {
echo 'Nither you are on Homepage nor your page URL is : ' .$myCustomUrl;
}
?>
Related
I try to make something like title say's.
Some friendly websites use a widget with iframe of my front page and i get traffic.
The problem is that all the traffic goes to home page. I want to share the visitors of the iframe to random posts without to edit the external iframe widget of the friend's site's.
i have search and finded a code but has a bug and with this code i cant access my homepage, the home page is redirecting all visitors to random posts.
How can i make the home page redirecting if it is only in iframe?
<?php
$continue = 0;
if(isset($_SERVER['HTTP_REFERER'])) {
//correct domain:
$ar=parse_url($_SERVER['HTTP_REFERER']);
if( strpos($ar['host'], 'mydomain.com') === false ){
} else {
$continue = 1;
}
}
if($continue == 0){ ?>
<?php if (is_front_page()) { ?>
<?php query_posts( 'posts_per_page=1&orderby=rand' ); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php wp_redirect ( get_permalink () ); exit; ?>
<?php endwhile; ?>
<?php } ?>
<?php } ?>
Thanks
Your code is confusing. Why do you need to store "continue" as a variable? Why don't you just add something like this to the top of your page?
<?php
if(isset($_SERVER['HTTP_REFERER'])) {
$ar=parse_url($_SERVER['HTTP_REFERER']);
if( strpos($ar['host'], 'mydomain.com') === false ){
header('Location: http://www.yourwebsite.com/posts_per_page=1&orderby=rand');
exit();
}
}
?>
(Just reusing your code - basically, check if the site is loaded in an iframe and the homepage was requested - if so, redirect to the random page)
I am a beginner when it comes to php, and I have encountered a problem that I cannot find the solution for. I have tried searching for a relevant answer but I haven't found one.
I have the following code in my index.php:
<?php if ($set_status = 2) {
echo 'There is one or more errors';
} else {
echo '';
}
?>
and this a bit further down:
<?php include 'scan/a.php'; ?>
And inside my a.php I have the following code:
<?php
$a = file_get_contents
('http://www.a-random-website/text.html', NULL, NULL, 2, 1);
if ($a == "0") {
include 'fail.php';
} elseif ($a == "1") {
include 'success.php';
} else {
echo 'Offline';
}
?>
And inside my fail.php I have the following code:
<?php
$set_status = 2;
echo 'Failed';
?>
So the idea here is that "a.php" will fetch a number from the website (The correct website has either ["1"] or ["0"] displayed that the code will fetch).
Depending on the result it returns, a.php will include either "fail.php" or "success.php", each containing either a success or a fail-message. If file_get_contents return a 0 I also want fail.php to $set_status = 2; which will cause "There is one or more errors" to be displayed on the front-page (index.php).
The reason that I am using include is that there's going to be a "b.php" and "c.php" and "d.php" and so on, all doing the same thing but fetching data from different pages. I want the success or fail-message to remain easy to edit, without having to edit each and every new x.php file.
So here's where it gets problematic. Everything works beautifully, except for the "There is one or more errors"-message that's supposed to trigger if ($set_status = 2).
I can get as far as the message showing, but when I switch the 1 and 0 in "a.php" (To simulate a specific result) the message will still show. I can't seem to figure it out.
So my question is: What have I done wrong, and what is the correct way to do it?
Thank you in advance!
Best regards,
Marc
use == operator in index.php to compare
<?php if ($set_status == 2) {
echo 'There is one or more errors';
} else {
echo '';
}
?>
<?php if ($set_status ==2) {
echo 'There\'s one or more errors';
} else {
echo '';
}
?>
Just change this code ... see slash\ and == in the echo line .. else of your code id fine
Situation is getting a logo on:
domain.com/special_dir/any_page
or
domain.com/special_dir/any_dir/
to use a link to [domain.com/special_dir/].
Everywhere else on [domain.com/] the logo must a link to [domain.com/]
This is what I have so far.
<?php
$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if( $host == 'domain.com/special_dir/' ) {
echo '<div"><img src="..."></div>';
} else {
echo '<div"><img src="..."></div>';
}
?>
The logo for [domain.com/special_dir/] only works for [domain.com/special_dir/] URL, no others. I suppose the code it doing what it should, I just don't know how to make it recursive. I did search and read a lot of similar situations but none based on PHP code worked for me.
It is WordPress Multi-site setup and the "special_dir" is a regular sub-directory.
How to correct?
Thanks
Your if ($host == 'domain.com/special_dir/') statement means the special link will be printed for domain.com/special_dir/ only. It excludes everything else, including comain.com/special_dir/any_dir and domain.com/special_dir/any_page.
If think you want ...
if (substr($host,0,22) == 'domain.com/special_dir/') { ... }
This did the trick.
<?php
$url = $_SERVER["REQUEST_URI"];
if (strpos($url, "/special_dir/") === 0) {
echo '<div"><img src="..."></div>';
} else {
echo '<div"><img src="..."></div>';
}
?>
I'd like to make subpages within the same page, using if isset(get) to show the subpages.
I have a page: page.php and a subpage: page.php?do=userList and I'd like to make other subpage using the same URL: page.php?do=userList&id=123
This is my code (page.php):
if(empty($_GET)) {
?>
User List
<?php
}
if (isset($_GET['do']) && $_GET['do'] == 'userList') {
// the user list
echo '' . $row['name'] . '';
}
if (isset($_GET['id'])) { // ???
// user info
}
Can I use that URL but showing only the content of: "if (isset($_GET['id']))"??
If is set $_GET['id'] don't show $_GET['do']... :P
Just add && !isset($_GET['id']) to your second if statement.
I am developing a site, I was wondering if I could use PHP in a generic way in order to show a div on the home page, but no on any other page. The code I have so far,
<?php
if host == 'http://domain.com/'; echo {
This should only be shown on the homepage http://domain.com but not on domain.com/directory or sub.domain.com/ !
} else {
};
?>
<?php
$match_domains = array('google.com','www.google.com');
if(in_array($_SERVER['SERVER_NAME'], $match_domains) {
echo 'show on my domain!';
}
?>
Using $_SERVER['SERVER_NAME'] we compare it to our desired domain.
We use in_array to search $match_domains for the current domain. If it's in the array, we show our text...Anything else, we ignore.
<?php
$domain = str_replace('www.','',$_SERVER['SERVER_NAME']); // Strip out www.
$match_domains = array('google.com');
if(in_array($domain, $match_domains) {
echo 'show on my domain!';
}
?>
Since you want the home page why don't you check the file name
if ($_SERVER['SCRIPT_NAME'] == "/index.php") {
echo "<div>Content</div>";
}