How can I combine the two if statements below, but I would like the page to display the breadcrumbs if one OR the other fields are present.
<?php if (!empty($secondaryslider)): ?>
<?php if (!empty($node->field_upload_banner[0]['view'])) {?>
Use || or OR
if (!empty($secondaryslider) || !empty($node->field_upload_banner[0]['view']))
{
}
Just use an ||:
<?php if ( !empty($secondaryslider) || !empty($node->field_upload_banner[0]['view']) ): ?>
very straight forward
<?php if (!empty($secondaryslider) && !empty($node->field_upload_banner[0]['view'])): ?>
Related
I am very new to PHP and I am trying to get a piece of PHP code to run inside of my HTML file.
I have a drop down menu. If users select one item, it should display additional fields. So, I want them to only display if they select that item from the drop down menu. I am trying to select it based on the value for that drop down item. I have not declared any PHP values in a PHP script. This is all in HTML.
I know that with jquery you have to pull in the jquery library before running the script. Do I need to do this with PHP also?
Here is the code that I am trying to run:
Thank you in advance!
<?php
if ($dropmenuValue == "specificParameter") {
?>
<div>
-conditional content-
</div>
<?php
}
?>
<?php
if ($value ) {
?>
<div>
-conditional content-
</div>
<?php
}
?>
If you are setting the $values variable like this
$value = true
Then you can do
<? if($value){ ?>
<div>Content Here</div>
<? } ?>
Is the page a .php page?
A multi conditional statement is done in a different manner. The manner being:
<?php if($val): ?>
<div>
-conditional content-
</div>
<?php endif; ?>
the problem is that your comparing a boolean to a String.That's why your code won't work I would suggest something like If($value){ or if($value==true){.
you want to do if($value == true). The quotes you have around true does not make it a boolean variable.
Everything else in your code looks find.
tldr: correct: if($value == true) ----------
incorrect: if($value == "true")
<?php if ($value ):?>
<div>
-conditional content-
</div>
<?php endif;?>
Here are a few pointers.
$value is a boolean value. It is best to evaluate using if($value)
The PHP if syntax used above is a much cleaner way.
You will be able to see where your if statement begins and ends.
Enjoy!
can someone explain why the else statement is not working in WordPress for the sidebar.php?
<?php if(is_front_page() ) : ?>
**content shows on main page sidebar**
<?php elseif(!is_front_page() ) : ?>
<?php // else: ?> // tried **else:** also
**some content**
**nothing is shown on any other page...**
<?php endif;?>
The is_front_page() conditional will always return false if it is used inside the loop or after the loop has ran (like in a sidebar). You can call wp_reset_query(); after your loop to reset the page query_vars.
See this answer on WPSE for more info.
Im not sure if is_front_page() exists, but just use {} around each condition result:
<?php if(is_front_page() ) { ?>
**content shows on main page sidebar**
<?php } else { ?>
// tried **else:** also
**some content**
**nothing is shown on any other page...**
<?php } ?>
I'm trying to create a PHP 'if' statement that tells an image to display on certain pages in Wordpress. What I'm trying to do is shown below, but I think the syntax is incorrect.
I'm trying to say "If the page displayed equals 'about' or 'gallery' and that page is not 'services', go ahead and display the image.
Here's the section of code that you should be able to analyze and see where I went wrong:
<?php if(is_page('about' || 'gallery') && (is_page != 'services')) { ?>
<li><img id="profile_pic" alt="DermaKare (Official Fan Page)" src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/50556_123510051042639_3343345_n.jpg" class="photo img" /></li>
<?php } ?>
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Banner") ) : ?>
<?php /*?><p><a href='<?php bloginfo('siteurl')?>/wp-admin/widgets.php'>Widgetize this sidebar</a></p><?php */?>
<?php endif; ?>
Thanks in advance for any help on this.....
If a page is about or gallery then it never is services. So you can spare that not part.
Next to that you need to call the function twice:
if (is_page('about') || is_page('gallery'))
{
# then
}
This should do it. Wrapped into your code this should look like:
<?php if (is_page('about') || is_page('gallery')) { ?>
if ( ( is_page('about') || is_page('gallery') ) && !is_page('services') )
watch the brackets.
edit: and what #hakre said, if it's about or gallery, it never is services
<?php if( (is_page('about') || is_page('gallery') ) && (!is_page('services') ) {
echo "<li><img id=\"profile_pic\" alt=\"DermaKare (Official Fan Page)\" src=\"http://profile.ak.fbcdn.net/hprofile-ak-snc4/50556_123510051042639_3343345_n.jpg\" class=\"photo img\" /></li>";
} ?>
this should work
I am looking to add a where clause to the following:
<?php foreach($this->assignments as $assignmentIndex => $assignmentArray): ?>
I want basically to only pull data from the database where assignmentType=pdf
any help would be great!
thanks
<?php foreach($this->assignments as $assignmentIndex => $assignmentArray): ?>
<?php if(assignmentType == 'pdf') :?>
....
....
<?php endif; ?>
<?php end foreach; ?>
well you can't change the sql line in the foreachloop
however if the assignmentArray containts assignmenType
you could ignore the other types like this:
if($assignmentArray['assignmentType'] != 'pdf'){
continue;
}
or somewhat nicer would be:
if($assignmentArray['assignmentType'] == 'pdf'){
// do your fancy stuff here
}
I'm writing a sidebar for my site and I'm trying to check if:
The page is a post, via: is_post()
The author can edit the post via: current_user_can('edit_post')
I'm trying to combine both of these conditions, but I'm horrid at PHP and I just can't figure out the syntax to do so. I figured it'd be something like below. Could you please let me know what I'm doing wrong? I'm assuming it's something simple, but my inexperience is causing problems and I can't find the right example/documentation to help me out.
<?php if is_single and if (current_user_can('edit_post')) { ?>
<li>Edit post</li>
<?php ;} ?>
It should be:
<?php if (is_single() && current_user_can('edit_post')) { ?>
<li>Edit post</li>
<?php } ?>
The syntax and idea is:
if (true && true) {
// things will happen ...
}
For your functions:
if (is_single() && current_user_can('edit_post')) { ...