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
Related
I am new to PHP and was writing a condition while making WordPress website. I have writing the correct tag syntax but when I am converting it into PHP echo then it is showing error.
Both the tags are present in the jsfiddle link below.
Jsfiddle link
Please let me know how to convert correct HTML code of the jsfiddle link to correct and working PHP code.
In wordpress we can write php code in header.php , footer.php etc. files which are under the directory wordpress/wp-content or wordpress/wp-admin etc.
But if we want to use php code after login in wordpress I mean in page, post , widget etc. wordpress can't recognize those php code ().
So, please explain in which file are you writing both code.
I'm damn sure that the code which is not working is inside the admin panel.
(Note : if you want to use condition through () inside admin panel (inside page,post etc.) ) you have to add a plugin like Exec-PHP (https://wordpress.org/plugins/exec-php/) or any other plugin which executes PHP code in posts, pages and text widgets.
May be this will help
You added something in last like
";}?>
These are no needed
<?php if (is_user_logged_in() ) {
echo "<a"; <?php if ( get_post_meta( get_the_id(), 'dysaniaselect', true ) == 'dysania-link' && get_option('dysania_gridgallery_targetblank') == "true") {
echo 'target="_blank"'; } ?> class="<?php echo( get_post_meta( get_the_id(), 'dysaniaselect', true ) ); ?> <?php echo 'clbx' . $id; ?>" data-title="<?php the_title(); ?>" data-rel="<?php echo ( get_post_meta( get_the_id(), 'dysaniaselect', true ) ) . 'clbx' . $id; ?>" href="<?php if (!empty($video)) { echo $video; } else { echo $imageurl; } ?>">
I want to make a check if im on a subpage. On the homepage it is :
<?php if(is_front_page()): ?> <?php endif; ?>
But how to do it when it is another page?
This is literally right from the docs:
There is no function to check if a page is a sub-page. We can get around the problem:
if ( is_page() && $post->post_parent > 0 ) {
echo "This is a child page";
}
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'])): ?>
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 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')) { ...