Wordpress Options framework check variable isset - php

I am using this library http://wptheming.com/options-framework-theme/ for creating a theme option page in my admin panel in wordpress.
I want to know How can I check the variable that if the value is inserted on the input box or not
right now I am printing the value like this
<?php echo of_get_option('title', '');?>
I want to do like this
if(isset($title)){
<?php echo of_get_option('title', '');?>
}
Thanks

You can try this:
<?php if (of_get_option('title')) {?>
<?php echo $title ?>
<?php } else { ?>
<?php echo "No Title Submitted in Options Framework" ?>
<?php } ?>

Related

PHP, variable wont attach to hyperlink

Im trying to send the patient ID through a hyperlink, tho while it redirects to the correct page it is not sending the information.
<a href="./patientrecord.php?patient_id="<?php $row["patient_id"]?>><?php echo $row["surname"];?></a>
Please make sure you are going to echo the variable
Echoing a variable:
<?= $echoable_variable_here ?> // Use <?= ?> tags
or
<?php echo $echoable_variable_here ?> // Use echo inside <?php ?> tags
Edit: You have placed echo outside the href attribute tag
Therefore,
Change this:
<a href="./patientrecord.php?patient_id="<?php $row["patient_id"]?>><?php echo $row["surname"];?></a>
to:
<?php echo $row["surname"];?>
or to:
<?php echo $row["surname"];?>

How to hide a <Div> using PHP

Hi I have used some code but I want it so when the name is NULL it is hidden, if this is possible please help.
Here is the code
<p id="top"><strong>Welcome back <?php echo $_SESSION['name']; ?> [Logout]<br/>Welcome To the homepage of The Journalist's</p>
I want it to be when name is NULL, for
"<strong>Welcome back <?php echo $_SESSION['name']; ?> [Logout]"
to be hidden.
Thank you.
update...
This is what i have so far
This is what i have so far.
<?php
if ($SESSION['name']= NULL) {
?>
<div><strong>Welcome back <?php echo $_SESSION['name']; ?> [Logout]</div>
<?php
}
?>
I have fixed it , thank you for everyone that has commented. for anyone else with this problem. here is my solution.
<?php
if ($_SESSION['name']!= NULL) {
?>
<strong>Welcome back <?php echo $_SESSION['name']; ?> [Logout]<br/>
<?php
}
?>
Update from your posted code:
For one, you are using $SESSION instead of $_SESSION. Second, you are setting $SESSION['name'] using a single equal sign, so the if condition would always fail because it is evaluating if (NULL). You need to use == or ===. Read up on comparison operators.
<?php
if (condition) {
?>
<div></div>
<?php
}
?>

Hide Div title if there's no content

I'm very newbie regarding PHP, I'm trying to configure my wordpress Loop.
I figured out how to display my customfield in my template, I manually added a title before my taxonomy and custom fields, but I'd like it doesn't show if the taxonomy is empty.
Here is the code:
<div class="customfields">
<h2 class="widgettitle">My Title</h2>
<?php echo do_shortcode('[tax id="agences" before="Agences : " separator=", " after=""]'); ?>
<?php echo do_shortcode('[custom_fields_block]'); ?>
</div>
I would very much appreciate your help!
Thanks a ton,
T.
So code should be
<?php $taxonomy = do_shortcode('[tax id="agences" before="Agences : " separator=", " after=""]'); ?>
<div class="customfields">
<?php if(!empty($taxonomy)) : ?>
<h2 class="widgettitle">My Title</h2>
<?php echo $taxonomy; ?>
<?php endif; ?>
<?php echo do_shortcode('[custom_fields_block]'); ?>
</div>
If you want to show content in HTML only if certain variables contain a value then you can create a simple if statement that uses PHP's isset function to determine whether or not the variables are set, and if true place some HTML on the page. You can read more about isset here.

how to code an if else dynamic statement

I'm having trouble writing an if else statement. Considering that I've been doing so for years in ColdFusion, this make me feel very stupid.
Here's the task.
I need to pull first name, last name, email, co-chair status from a database and return the results. However not everyone has an email, so I need a statement that will include a mailto link for those that have emails, and exclude a mailto link for those that don't.
Here's the code I'm using that includes the mailto link for all.
What adjustments do I need to make?
thanks,
david
<?php do { ?>
<?php echo $row_GetMembers['BACmember_First']; ?> <?php echo $row_GetMembers['BACmember_Last']; ?>
<?php /*START_PHP_SIRFCIT*/ if ($row_GetMembers['BACmember_CoChair']=="Yes"){ ?>
<strong> Co-Chair</strong>
<?php } /*END_PHP_SIRFCIT*/ ?><br />
<?php } while ($row_GetMembers = mysql_fetch_assoc($GetMembers)); ?>
This is the line of code you want to optionally display as a link (split for readability):
<a href="mailto:<?php echo $row_GetMembers['BACmember_Email']; ?>">
<?php echo $row_GetMembers['BACmember_First']; ?>
<?php echo $row_GetMembers['BACmember_Last']; ?>
</a>
You'll want something like this instead:
<?php if (!empty($row_GetMembers['BACmember_Email'])): ?>
<a href='mailto:<?php echo $row_GetMembers['BACmember_Email']?>>
<?php echo $row_GetMembers['BACmember_First']; ?>
<?php echo $row_GetMembers['BACmember_Last']; ?>
</a>
<?php else: ?>
<?php echo $row_GetMembers['BACmember_First']; ?>
<?php echo $row_GetMembers['BACmember_Last']; ?>
<?php endif; ?>
If the email field isn't empty (the ! negates the result, so we're checking if it isn't empty), it prints the first and last name inside an anchor tag. If it is empty, it prints the name without it.
A more elegant solution may be to provide the email address as a separate field or link, as opposed to having a list of some names that are links and some that aren't.

Don't display if attribute is string(0)

I'm using the following section of code to display some icons on our Magento store with the idea being if there is nothing added in the icons section it shouldn't display, for some reason this isn't working...it is displaying a division as if something is there but there is actually nothing.
<?php
if($_helper->productAttribute($_product,($_product->geticons()), 'icons') !== null):
?>
<div class="product-icons">
<?php echo $_helper->productAttribute($_product,($_product->geticons()), 'icons') ?>
</div>
<?php endif; ?>
It needs to show Icons if they are coded in the attribute field and then hide the division if there is nothing added.
I've worked out that the code is returning a value of string(0) what do I need to change in my coding to get the desired effect?
Here's the thing you need, and you don't need call the same functionality twice to get the empty result. Define your variable and check if it is empty (null, undefined or false) or not
<?php $icons = $_helper->productAttribute($_product,($_product->getIcons()), 'icons');?>
<?php if(!empty($icons)):?>
<div class="product-icons">
<?php echo $icons;?>
</div>
<?php endif;?>
this could be even better solution as it wont call the helper unless there are icons defined but you first have to try it out on your codebase.
<?php if($_product->getIcons()):?>
<div class="product-icons">
<?php echo $_helper->productAttribute($_product,($_product->getIcons()), 'icons') ?>
</div>
<?php endif; ?>
and please check if it isn't a typo and it really is:
$_product->geticons()
or should it be
$_product->getIcons()
Something like:
<?php
if($_helper->productAttribute($_product,($_product->geticons()), 'icons'))
{
echo "<div class=\"product-icons\">";
echo $_helper->productAttribute($_product,($_product->geticons()), 'icons');
echo "</div>";
}
?>
would be better!
try
<?php
if(!empty($_helper->productAttribute($_product,($_product->geticons()), 'icons')))
{
echo "<div class=\"product-icons\">";
echo $_helper->productAttribute($_product,($_product->geticons()), 'icons');
echo "</div>";
}
?>

Categories