I'm trying to have a different template for the second page of posts, here's the code I came up with.
<?php
if ( is_home() ) { ?>
SOME HTML
<?php } else if (is_page('chi-sono')){ ?>
SOME HTML
<?php } else if (is_paged()){} else{}?>
It seems straightforward to me but the elseif is_paged() doesn't work, what am I doing wrong? I also tried
$paged = (get_query_var('paged'));
elseif ($paged >= 2)
is_home() return true on blog page so you are not going on is_paged().
try this
if (is_home()) {
if (is_paged()) {
echo 'second page';
} else {
echo 'home page';
}
}
Related
I'm trying to get if its home page or not. (I mean all kind of home page in wordpress: Default, static, blog). I wrote this code in function.php file but in all pages I get "not home"!!
if ( is_front_page() && is_home() ) {
die("home");
} elseif ( is_front_page() ) {
die("home");
} elseif ( is_home() ) {
die("home");
} else {
die("not home");
}
Set home page screenshot https://prnt.sc/rbfgy8
Add this code in theme functions.php
//Put the condition in wp_footer hook to see the result
add_action('wp_footer', 'custom_wp_footer_fun');
function custom_wp_footer_fun(){
if ( is_front_page() && is_home() ) {
echo 'home';
} elseif ( is_front_page() ) {
echo 'home';
} elseif ( is_home() ) {
echo 'home';
} else {
echo 'not home';
}
}
I'm currently adding this to the header.php page to add a script to a single wordpress page:
<?php if( $post->post_name == "my-page" ) { ?>
//script here
<?php } ?>
Works great. how do I add another page to this? I tried:
<?php if( $post->post_name == array("my-page", "my-page-two") ) { ?>
//script here
<?php } ?>
but it didn't work.
I'm trying to alter the experience of the user by changing the page templates based on URL UTM variables.
Example, if the utm_source=google I want to show the person the page-google.php.
Here's the code I have so far.
<?php if ( isset( $_GET['utm_source'] ) && $_GET['utm_source'] == 'test' )
{
get_page_template(test);
}
else {
get_page_template(gallery);
}
?>
I'm not sure 1) if this is the right way 2) where it should be placed in wordpress.
Thanks for your help!
in page.php
<?php if ( isset( $_GET['utm_source'] ) && $_GET['utm_source'] == 'test' ) {
get_template_part('test');
}
else {
get_template_part('gallery');
}
?>
this is if test.php is in your sites theme directory
Quick overview of what i am trying to do. I have a template layout that has 3 columns the left and right column are widget areas. What i would like to do is test for if both widget areas are active, one of widget areas are active, or if none are active (ie. have widget content).
Examples code:
<?php if ( is_active_sidebar( 'sidebar_1' && 'sidebar_2') ) { ?>
<div class="bothSidebarsActive"></div>
<?php } elseif ( is_active_sidebar( 'sidebar_1' || 'sidebar_2' ) { ?>
<div class="OneTheSidebarsActive"></div>
<?php } else { ?>
<div class="noneOfTheSidebarsAreActive"></div>
<?php }; ?>
I have had limited success getting the IF or ELSEIF to return true, but never all three states. Anybody know what i am doing wrong ?
Thank you for any and all assistance.
elseif ( 'employees_sidebar' || 'contact_sidebar' ) looks like your issue to me. You should be using the is_active_sidebar function here also. Like this:
<?php } elseif ( is_active_sidebar('employees_sidebar') || is_active_sidebar('contact_sidebar') ) { ?>
Ok thanks to - BULK for the assistance the code now works, here it is in case anybody else comes across this same issue.
functional code:
<?php if ( is_active_sidebar ( 'employees_sidebar' ) && is_active_sidebar ( 'contact_sidebar' ) ) { ?>
<div class="bothSidebarsActive"></div>
<?php } elseif ( is_active_sidebar ( 'employees_sidebar' ) || is_active_sidebar ( 'contact_sidebar' ) ) { ?>
<div class="OneSidebarActive"></div>
<?php } else { ?>
<div class="noneOfTheSidebarsAreActive"></div>
<?php } ?>
I have this bit of code in my header:
<?php if (has_nav_menu('sub-header-menu', 'responsive')) { ?>
<?php wp_nav_menu(array(
'container' => '',
'menu_class' => 'sub-header-menu',
'theme_location' => 'sub-header-menu')
);
?>
<?php } ?>
And I need something that will make it only show on the blog page and the children for that page (i.e the categories).. I'm not great with PHP but I guess this would be something simple
Just add a page Id of your blog page in you condition.
$parentPageId = is_subpage();
if (has_nav_menu('sub-header-menu', 'responsive') &&
(is_page( $blogPageId ) || $parentPageId == $blogPageId))
You can alos check your page using slug.
is_page( 'blog' )
Function to get Parent Page Id if exists.
function is_subpage() {
global $post;
if ( is_page() && $post->post_parent ) {
return $post->post_parent;
} else {
return false;
}
}
Find out the ID of the blog page $blogid = 123 (for example) and then check with if ($page->ID == $blogid) { /*show menu*/ }