WordPress/php if statement within an if statement - php

I'm having one of those moments where I know I'm so close, and probably missing something super minor that's causing this to not work.
I'm using a pre-built theme, with an if statement for including or not including a link. What I want to do it put an if statement inside of THAT differentiating between internal and external links, opening external links in a new tab.
This is the portion I'm specifically working on
if(!empty($parallax_one_service_box->title)){
if( !empty($parallax_one_service_box->link) ){
if($parallax_one_service_box->link_type == 'External'){
echo '<h3 class="colored-text">'.esc_attr($parallax_one_service_box->title).'</h3>';
}else {
echo '<h3 class="colored-text">'.esc_attr($parallax_one_service_box->title).'</h3>';
}
}
else {
if (function_exists ( 'icl_translate' ) && !empty($parallax_one_service_box->id)){
echo '<h3 class="colored-text">'.icl_translate('Featured Area',$parallax_one_service_box->id.'_services_title',esc_attr($parallax_one_service_box->title)).'</h3>';
} else {
echo '<h3 class="colored-text">'.esc_attr($parallax_one_service_box->title).'</h3>';
}
}
}
So it's something along the lines of "if not empty, if external link open in a new tab." I ran it through php code checker, and the code is correct...not missing any brackets or anything. The problem seems to be that it's either opening all in a new tab or opening none in a new tab...it's not differentiating between external and internal. So I'm guessing something is wrong with the "if external" line...
Here's a link to Pastebin with the whole section of code: http://pastebin.com/kmuGiVJv

Related

Wordpress plug in php issues

I'd like to preface that I am not too fluent in php so i'm trying to understand and build php as i go.
I am attempting to add a custom Slidedeck slider to my website, http://cfsb.org/ . I currently have one in the header, but would like to change it on a per page basis.
I currently have:
function slidedecktwo_header_home() {
if (is_home()) {
echo do_shortcode('[SlideDeck2 id=xxx]');
}
}
add_action('genesis_header', 'slidedecktwo_header_home');
But when i try to add something like
else if (is_page(PAGE_ID = x)) {
echo do_shortcode('[SlideDeck2 id=xxx');
}
My webpage crashes and I have to delete the code before my website returns. Anyone see some obvious problems?
Thanks in advance.
Not sure if what you posted is the actual PHP you tried, but there are definite syntax errors.
Your code should look more like this (I added a random ID passed as an integer to the is_page() function):
function slidedecktwo_header_home() {
if ( is_home() ) {
echo do_shortcode('[SlideDeck2 id=xxx]');
} elseif ( is_page(42) ) {
echo do_shortcode('[SlideDeck2 id=xxx]');
}
}
add_action('genesis_header', 'slidedecktwo_header_home');
In your snippet, you had is_page( PAGE_ID = x ) and your shortcode snippet wasn't closed with a closing bracket ]

Using shortcode breaks RSS feed

I had successfully created shortcode on my wordpress website to use it in the posts. But I later realised that it is breaking my rss-feed.
Here is the shortcodes.php
<?php
function disclaimer() {
$disc = " <p style='font-style:italic;'> <strong>Disclaimer</strong> :</p>";
return $disc;
}
add_shortcode('disclaimer', 'disclaimer');
?>
Here is how I am including it on the functions.php
<?php
include 'shortcodes.php';
So now, I am getting this error when I access my rss URL on my browser
So when I removed this include 'shortcodes.php'; my rss feed started working. But then I also want my shortcode to work. Am I doing anything wrong here? Any help would be highly appreciated.
You can change your function so that the disclaimer is not added on feed page
function disclaimer() {
if ( ! is_feed() ) {
$disc = " <p style='font-style:italic;'> <strong>Disclaimer</strong> :</p>";
return $disc;
}
}
Edit:
Then it is not a problem with the code, but some problem with the file.
Make sure there is not extra space after the closing ?> php tag. Or better, try to remove it completely.

How To: PHP elseIf to change div depending on the URL Contents

Issue: I have a php file that I do not have access to but I need to be able to format it. It generates several different pages depending on the search. I have been able to change a div using php if else statements in the header that the php calls to. (See Below)
What I would like to do is have a statement that will change the div depending on what is in the url, now the issue with this is that one of the pages I need to change, has the "submitIt" in the url which is what I am using to change the first div.
I have tried to change the code so that it calls to a different portion of the url but because the url still contains the first bit "submitIt" it calls to that div, rather than the new div.
Is there a way to call the elseif statement where if it contains "submitIt and "MEDIA_TYPE_ID" then it would print out the new div?
<?php $url = $_SERVER["REQUEST_URI"];
if (strpos($url, "submitIt")) {
echo '<div style="width:560px;" class="app-h3 app-table">';
}elseif (strpos($url, "MEDIA_TYPE_ID")) {
echo '<div style="width:560px;" class="app-h3 app-table-none">';
}else {
echo '<div style="width:560px;" class="app-h3">';
}
?>
I think you are looking for the && operator. It means 'and'.
if (strpos($url, "submitIt") && strpos($url, "MEDIA_TYPE_ID")) {
// do something
}
If both of those are true, it will execute the code block.

Using is_page outside the loop in Wordpress

I have looked at the other posts on this topic and can't find what I'm looking for.
I want to call a different shortcode depending on the page I am on.
The is_page function doesn't work in the loop so Im not sure how to accomplish this. Here is what I have so far. It makes logical sense to me but won't work for some reason.
if ( is_page(545) ) { <?php echo do_shortcode('[scrapeazon asin="Product1"]') ?>}
elseif ( is_page(525) ) { <?php echo do_shortcode('[scrapeazon asin="Product2"]') ?>}
else ...
Any help is much appreciated!
Thanks,
Mike
You're using the function correctly according to Wordpress Docs but your PHP is off. You have <?php open tag when php is already open, matching closing tags that aren't required either, and you're missing semicolons.
<?php
if ( is_page(545) ) { echo do_shortcode('[scrapeazon asin="Product1"]'); }
elseif ( is_page(525) ) { echo do_shortcode('[scrapeazon asin="Product2"]'); }
else ...
?>
You don't need the curly braces in there for single line executions but I left them for the sake of highlighting the error.
There is a cleaner way to do it though
<?php
$pages=array(
545=>'Product1',
525=>'Product2',
567=>'Product3',
568=>'Product4',
// etc
// etc
);
foreach ($pages as $page_id=>$asin){
if (is_page($page_id)) {
echo do_shortcode('[scrapeazon asin="'.$asin.'"]');
break; // because you used elseif you must want to stop checking ids after finding one is a page
}
}
?>
Though it's probably faster, and less work for your db, to select all the pages at once and loop through that array.

this PHP code functions in XAMPP but AZURE shows code in browser

<?php
require_once('functions.php');
//display links from xml
$links = simple_load_file('links.xml');
foreach($links as $link){
$name = $link['name'];
$ref = $link->loc;
echo "<a href='".$ref."' class='navigation'>".$name."</a>";
}
//Display login boxes if user hasnt logged in
if((!isset($_SESSION['validUser'])) || ($_SESSION['validUser'] != true))
{
?>
//code for showing boxes.....
In the browser, it displays the folowing ;
loc; echo " ".$name." ";} //Display loginboxes.........all the way to != true)) { ?>
When I test this on XAMPP locally it works as intended, but using Azure it produces this.
It appears as if it's reading the '->' as a closing tag for my php. Anyne encounter something like this?
I never did get to find the exact problem, as the project was abandoned. however, as suggested it is most likely a configuration issue from within Windows Azure.

Categories