I have a div of services (full width) which I only want to display on the home page of my Wordpress site. I have used the conditional tag if(is_home()) and it is working fine. But when I added a new template this division is showing up in the template page, too. I tried using:
(if(is_home())&&(!is_page_template('blog.php'))
...but unfortunately it is not working. I have also tried it using ID and slug, and yet still this particular div is coming in the template.
I some how want this div to show up only on the homepage. You can see the services div here. The same is being displayed here, but not in other inner pages.
Use is_front_page() instead.
See Here
This code
<?php if (is_home()) : ?>
// yes, home page
<?php else : ?>
//no, not home page
<?php endif; ?>
Simply use
if(is_home() && !is_page_template('blog.php'))
Everything Should be in one condition
You can do it with any of the following conditional tags
if( is_home() && !is_page_template( 'page- template-Blog-php' ) ) {
// service div here
}
Note: If you are using template in any folder you need to give folder path too.
For example: If you are placing all the templates in 'templates' folder your code will be:
if( is_home() && !is_page_template( 'templates/page-template-Blog-php' ) ) {
// service div here
}
or you can try following code:
if( is_home() || is_front_page() ) {
// service div here
}
Braces wrongly placed:
if( (is_home()) && (!is_page_template('blog.php')) )
Related
I am trying to hide a script in some posts and specific categories, here I leave a demonstration of what I have done but it is not working, since when using! Is_single (1001) what it does is hide all the content in it site.
My codes:
<?php
if ( !in_category(118) && !in_category(137) && !in_category(121)) {
?>
<script></script>
<?php } ?>
This is what I've been doing:
<?php
if ( !in_category(118) && !in_category(137) && !in_category(121) && !is_single(1001)) {
?>
<script></script>
<?php } ?>
For categories it does work but when I add! Is_single (1001) the script is hidden all over the site.
I hope your help, I am starting to learn php in WP.
first of all your conditions looks little doubtful, cause it's comparing all the conditions when you use && instead please use || (OR) condition if you are trying to enable or disable script on those conditions.
Second: i dont think WP has function like in_category to check, but i guess you should use is_category()
Third, please add id in array if you have multiple
for example:
!is_category( array( 9,12,19,30 ) );
!is_single( array( 1009,102,119,330 ) );
hope that will work!
So, I have been trying a couple of things but I can't figure it out.
In my header.php file I have a simple PHP line (custom-made Wordpress theme):
<?php if ( is_page('Home') || is_404() || is_search() ) { echo ""; } else { echo "<h1>". get_the_title() ."</h1>"; } ?>
This was working GREAT until I was required to install "The Events Calendar" plugin and adapt it to my theme.
The plugin allows me to go into its settings and create a URL slug, in this case I named it "reunions" and I did "reunion" slug for single events. So, logically I should be able to do this:
<?php if ( is_page('Home') || is_page('reunions') || is_page('reunion') || is_404() || is_search() ) { echo ""; } else { echo "<h1>". get_the_title() ."</h1>"; } ?>
But this didn't work, additionally I tried these two things but no luck:
$pagenow == 'the-events-calendar.php'
is_plugin_active( 'the-events-calendar/the-events-calendar.php' )
My work around would be to manually add <h1>(title)</h1> to each page, there's gotta be a way to do this. Is it possible to create a is_plugin('the-events-calendar') function to check for the plugin and disable the H1 line?
Any help would be greatly appreciated :)
You could use is_singular() function to check if the current post is of plugin's event custom post type, like this:
<?php if ( is_page('Home') || is_singular('tribe_events')...
Update:
You could also use has_term() function, to check for specific slug, like this:
<?php if ( is_page('Home') || has_term('reunions')...
I am currently using
<?php if ( is_home() ) :
get_header( 'home' );
endif;
?>
To call 'header-home.php' on the homepage only.
I also want to call 'header-fullwidth.php' on our full width posts.
This is one of our full width posts: http://www.sickchirpse.com/photos-vatnajokull-glacier/
This is a normal post (it has a sidebar): http://www.sickchirpse.com/how-survive-european-squat-house-berlin/
What can I add to achieve this?
if(get_page_template() == 'your-full-width-template'):
get_header( 'full-width' );
endif;
You can alwasy check the current page template path with the get_page_template() function.
Sorry for the trivial question but I'm not very skilled in php...
I need to display a slideshow on every page of my wordpress site except in one (sponsor).
I tried with this code but does not work.
<? php if (! is_sponsor ()) {do_action ('slideshow_deploy', '3484'); }?>
Where did I go wrong?
The normal code to display the slideshow is:
<?php do_action('slideshow_deploy', '3484'); ?>
Thanks in advance!
If you want to disable the slider on the page with slug "sponsor", try with the following code:
if( !is_page('sponsor') ) {
do_action('slideshow_deploy', '3484');
}
If you want to disable the slider on posts from post type "sponsor", try with the following code:
if( !( is_single() && get_post_type() == 'sponsor' ) ) {
do_action('slideshow_deploy', '3484');
}
There is no such thing as is_sponsor
to not display it for that single page
create a new page template and completely remove
<?php do_action('slideshow_deploy', '3484'); ?>
here is the naming structure
http://codex.wordpress.org/Template_Hierarchy
I have 2 template files , One template file is front-page.php and the other template is a custom one. Basically the code below is stating if it is front page then use this body class but if its anything else then use other body class. What I am trying to do is have my new template use the same body class as my front-page.php. I am having some issues making this occur. So basically,it needs to be "if front page or custom-template.php then use body class everything else "innerbody"
<?php if(w3c()){ ?><?php if(is_front_page() || is_page_template ('page-templates/front-page.php')){?><body> <?php } else{ ?><body id="innerbody"><?php } ?>
Generally used function for this is body_class(), and is used typically within the header.php template in the HTML body tag. Default classes that this function add are based upon a particular page that is displayed, so that they themselves are the solution for most of the stuff.
You can add additional body classes by using the body_class filter, add the following to the functions.php file:
add_filter( 'body_class', function( $classes ) {
// add custom class to the $classes array and return the $classes array
if ( is_front_page() || is_page( 'page-slug' ) ) {
$classes[] = 'innerbody';
}
return $classes;
});
Now you can use conditional tags inside that function to test the conditions that must be met to in order to take the specific action, in this case to add additional classes to the body tag. I recommend that you check the Template Hierarchy documentation also, it is the first step towards understanding the concept of themes and templates in WordPress.
Simply add another is_page_template() call to your if() function, and another OR (||) in your if().
<?php if(w3c()){ ?>
<?php if(is_front_page() || is_page_template ('custom-template.php') || is_page_template ('page-templates/front-page.php')){?>
<body>
<?php } else{ ?>
<body id="innerbody">
<?php } ?>