WordPress: Multiple conditional statements not working - wordpress

I'm trying a simple multiple conditional statement which should work fine with PHP but WordPress says no. What am I missing?
<?php if (is_page('sample1') || is_page('sample2') || is_page('sample3') || is_page('sample4')) { ?>
include this
<?php } else { ?>
include this instead
<?php } ?>

Undefined function?
How are you calling footer.php from your theme?

It has nothing to do with the code you posted. It has everything to do with the path to the footer or where you are trying to load it within the page lifecycle. Also check if the path is right.

Related

removing p tag around images from wordpress term_description

Should be pretty straight forward but placing my filter in the themes function file is not having any affect on the template:
add_filter('term_description', 'filter_ptags_on_images');
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
and my markup:
<?php echo term_description(); ?>
EDIT: I tried testing the filter by returning dummy content from the function and nothing changes, so the filter isn't running on the content for some reason
It turns out I was trying to target the wrong template and the actual function was an Advanced Custom Field wysiwg custom content tag:
<?php the_field('fieldname'); ?>
It took me a little while to figure out how to filter this but with a little googling I found out you can use this to target an ACF wysiwyg field from your functions file:
add_filter('acf_the_content', 'your_function');

How to remove header from particular single page

I'm a newbie at WordPress and php.
I want to remove the header from one or two pages only.
I saw this http://wordpress.org/support/topic/how-to-remove-footer-from-individual-pages
so I did this in my header.php file found under my theme folder
<?php if( !is_page('18') ) :?> <!-- this is what I added -->
<header class="banner">
...rest of html...
</header>
<?php endif;?> <!-- this is what I added -->
Just for the sake of seeing if changes to this file were taking effect I also did <?php if( false ) :?> which was supposed to remove it from all pages but this didn't work either.
Though I don't know the difference, I saw some different syntax and so also tried <?php if(false) { ?> and <?php } ?>
I am wondering if I have to do something else to have the changes take effect.
In case it matters, I am using the roots starter theme http://roots.io/starter-theme/
and WordPress 3.9.1
You should be editing the file /roots/templates/header-top-navbar.php. This get decided at base.php:
if (current_theme_supports('bootstrap-top-navbar')) {
get_template_part('templates/header-top-navbar');
} else {
get_template_part('templates/header');
}
Just in case, add your code to both. I tested your code with header-top-navbar.php and works ok.
you are giving wrong condition it should be if(is_page('18'))
{// do nothing } else {...rest of html...}

Wordpress if post or blog category statement

got a little problem here on Wordpress.
I am trying to use PHP to check whether the page I am on is a category page or a post page if it isn't on either it will do something else nothing.
The code I have is:
<?php if( (!is_category($category)) || (!is_single($post)) ) { ?>
Do something...
<?php } ?>
When I try it without the or the category bit works fine. When I join them together the code stops working.
I think what you're actually trying to test is if it's not a category and not a post. So change your condition accordingly:
if( (!is_category($category)) && (!is_single($post)) ) {

Drupal multi-site and one theme: how to know which multi-site user is on?

I have drupal multisite installed and atm I have two sites. Both sites uses same theme, but there are few tiny differences between looks of the site (like logo and div/bar is different color). Or well I would that they would have those differences. Now the question is how can I know on theme template that which site is showing up? Is there some paremeter or variable somewhere? Basically so that I could do is simple php if clause (if its this site, show this div and its the other site dnot show it)?
Thanks.
In one of my project I had the similar problem. What I did was that in template.php I created the following function:
function mytheme_firstdomain() {
global $base_url;
if(strpos($base_url,"http://firstsubdomain.mydomain") !== false) {
return true;
}
return false;
}
And then I could call this in the page.tpl.php code. Like
<?php if(mytheme_firstdomain()) { ?>
<div>Only for first domain</div>
<?php } else { ?>
<div>Only for the second domain</div>
<?php } ?>
Otherwise you could look into Block Classes module. That could also help.

wordpress template file quick tag more no working

i created a page template to be used as my front/home page with the wordpress loop in it, here is the code:
<?php query_posts('posts_per_page=10'); ?>
<?php
/* Run the loop to output the posts.
* If you want to overload this in a child theme then include a file
* called loop-index.php and that will be used instead.
*/
get_template_part( 'loop', 'idex' );
?>
but the problem is that the qiuicktag <!--more--> is not working , they always show the whole content. isn't the <!--more--> stored in the database?
I think the tag is just stored inside the text of the field post_content in the wp_posts table.
If you do not want WordPress to show the whole content, then use "the_excerpt" or call "the_content" in your loop with the correct parameters:
http://codex.wordpress.org/Customizing_the_Read_More
Just use a conditional tag in your loop.php where you call "the_content":
if(is_home() || is_front_page()) {
the_excerpt(); // or the_content( $more_link_text , $strip_teaser, $more_file );
} else {
the_content();
}
I hope this solves the problem. Otherwise there could be a bug or problem with your template regarding the "the_content"-function.

Resources