How can I make a banner only appear on the index page of my wordpress theme but when the click to the second or any other page from the pagination of recent posts I do not want this to appear. Any suggestions?
Thanks
You can use the conditional is_paged()
if( !is_paged() ) {
// Show what you wanna show
}
It's only going to show on the first page, on page 2, 3, 4... it's not going to show.
You can use below condition...
if(is_home() || is_front_page()) {
// Write your code which you want to display on home page only
}
Related
I have added a video to the homepage header of my wordpress theme but it also displays on the blog page.
my php is
if ( is_home() || is_front_page() ) {
echo '
<div class="overlay-caption">
<h1 class="home-h1">Join Us</h1>
With over 30 years of experience your adventure with us will be fun, memorable and help you pursue your passion for photography.
</div>
<div class="videoWrapper">
<iframe width="560" height="315" src="https://www.youtube.com/embed/3tmFvHviYcY?rel=0&autoplay=1&modestbranding=1&controls=0&loop=1&playlist=3tmFvHviYcY" frameborder="0" allowfullscreen autoplay="1"></iframe>
</div>';
}
else {}
?>
Now if i try only is_front_page it doesn’t appear on the homepage, if I try is_home it work but also shows up on the blog page.
I want the header on the blog page to be a standard header image, and I just want the homepage to display the video from the code I have included. Do I need to switch the conditional statement to a different order, or do I have the syntax completely wrong?
Thanks,
The basic difference between the is_home() and is_front_page() is as follows.
is_home()
The blog homepage is the page that shows the time-based blog content of the site.
is_home() is dependent on the site’s “Front page displays” Reading Settings ‘show_on_front’ and ‘page_for_posts’.
If a static page is set for the front page of the site, this function will return true only on the page you set as the “Posts page”.
is_front_page()
This Conditional Tag checks if the main page is a posts or a Page. This is a boolean function, meaning it returns either TRUE or FALSE. It returns TRUE when the main blog page is being displayed and the Settings->Reading->Front page displays is set to "Your latest posts", or when is set to "A static page" and the "Front Page" value is the current Page being displayed.
Hence now the code is as follows.
<?php
if(is_front_page() || is_home())
{
// The Code will execute if it is a 'Front Page'
// OR
// if the page is a 'Home Page'
}
if(is_front_page() && is_home())
{
// Here the code will execute if the page is
// A Front Page and as well as the Home Page
}
?>
Hence it depends on the situation of how you need to display the video over the page and to toggle around the condition that works on.
Or you try is_page() condition and that will make up the trick for you.
// When any single Page is being displayed.
is_page();
// When Page 42 (ID) is being displayed.
is_page( 42 );
// When the Page with a post_title of "Contact" is being displayed.
is_page( 'Contact' );
// When the Page with a post_name (slug) of "about-me" is being displayed.
is_page( 'about-me' );
Hope this explanation would be clear for you to understand better.
Thanks:) Happy coding.
The order of the statements here is critical, try flipping them around such as:
if(is_front_page() || is_home())
You can also use:
if(!is_front_page() && is_home())
Try something like this
if ( is_front_page() && is_home() ) {
// Default homepage
}
I have set everything, including set the front page to "Home" page in reading setting, here is the screenshot:
And I added:
if( !is_home() && !is_front_page()) {
echo "string";
}
But I still get "string" at the top of home page, as you can see in the screenshot.
Could anyone tells me why?
Thanks for any helps :-)
is_front_page() returns true if the user is on the page or page of posts that is set to the front page on Settings->Reading->Front page displays
So if you set about us as the front page then this conditional will only be true if showing the about us page.
is_home() return true when on the posts list page, This is usually the page that shows the latest 10 posts.
If the settings under Front page displays are left at default then the home page will return true for both is_front_page() and is_home()
An example of using is_home():
You have set your posts page to a page called News.
A user navigates there and in the header you want to show additional
navigation
You could use is_home() to do this.
Example:
// Add below code in your functions.php
add_action('loop_start', 'Test_hook_check');
function Test_hook_check(){
if( !is_front_page() ) {
echo "string";
}
}
You need to use is_front_page() for static pages.
I have a left and right advertising plugin, but want to show it only to main page (index page)
I have tryed to put a if conditions in plugin but doesn`t work. How to do it correctly?
This is floatads.js file code: http://pastebin.com/qeUHPn08
This is float_left_right_ads.php file code: http://pastebin.com/xm6GxF4d
Thanks for all info and help!
The front page is the main page if you chose it so in the dashboard setting. Inside
if ( is_front_page() ) {
// display your advertisment plugin
}
I want to hide the top slider part from the blog pages but in the first blog page I want to keep it. You can check this link: http://site4preview.site90.net/wordpress/ . There are two pages in the page navigation. I want to hide the slider from all pages starting from the page number 2 except 1. So is there any way to do it please ? Thanks in advance.
You need to check if that page is a "pagination" page, for this you must use is_paged().
Try this.
<?php
if( !is_paged() ) {
//Slider Goes Here
}
?>
EDIT:
You could just hide with CSS, it's not the best solution, but it get the job done.
If you have multiple sliders you could use this cascade to be more precise
.paged .block-content .widget-area .recent-posts-flexslider-class {
display: none
}
just hide all sliders under the paged pages
.paged .recent-posts-flexslider-class {
display: none;
}
or, if you know CSS hide the div you want utilizing the class .paged that shows only when you're visualizing a paged template
In a previous post (Don't show this if the url contains the following) I asked how I would go about having my header echo a div if the user loaded a URL with /blog in the header.
What I didn't take into consideration, was that I don't want the div to display if its not just got /blog in the url, but if its any blog post, not just the index page of the blogs.
How do I run a bit of code from my header.php if the page I'm looking at is a blog post?
You would use the Wordpress functions is_single() and is_page.
if(!is_single() && !is_page() && !is_home() && !is_archive())
{
/* This will not display for any post, page, the home page, or an archive.
You can remove each is statement according to your needs */
}
For only posts, only use is_single, the same for page, home, and archive.
The full listing of is_statements can be found here. Here are some others:
is_home() : Home Page
is_front_page : Front Page
is_single() : Single Post
is_admin() : Admin Panel
is_sticky() : Sticky Post
is_page() : Page
is_category
is_tag
is_author
It's been long since I've played with wordpress but you can achieve a lot with using the conditional tags:
http://codex.wordpress.org/Conditional_Tags
Seems like is_single() might do what you want. Eg:
if (!is_single())
{
// display div
}