Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTimothy Hooker
15,323 PointsHow would you combine these two wordpress/php if statements? I'm loading the flexslider css on home page and work posts.
<?php
// Is Sub_Page function to find subpages
function is_subpage() {
global $post; // load details about this page
if ( is_page() && $post->post_parent ) { // test to see if the page has a parent
return $post->post_parent; // return the ID of the parent post
} else { // there is no parent so ...
return false; // ... the answer to the question is false
}
}
function theme_styles() {
wp_register_style( 'flexslider', get_template_directory_uri() . '/css/flexslider.css');
if( is_page( 'home' ) ) {
wp_enqueue_style( 'flexslider' );
}
if( is_page('work') == is_subpage() ) {
wp_enqueue_style( 'flexslider' );
}
}
?>
Jason Anello
Courses Plus Student 94,610 PointsTimothy,
Does your 2 if
statements work correctly and you're simply trying to refactor the code to make it simpler/shorter?
1 Answer
Andrew Shook
31,709 PointsTim, try using :
<?php
if ( is_page( 'home' ) || (is_page( 'work' ) == is_subpage() ) )
?>
It probably won't make a difference, but give it a shot. If that does work add this to your theme_styles function.
<?php
var_dump( is_front_page() ); //use this if you want the site's home page or use is_home() if you want the site's blog posts index page
var_dump( is_page( 'work' ) == is_subpage() ) ;
?>
Go to the pages and see what boolean values are returned. It should help you find out which condition is faliing.
Jason Anello
Courses Plus Student 94,610 PointsHi Andrew,
I think it shouldn't make a difference since the comparison operator has higher precedence than the logical OR operator.
Andrew Shook
31,709 PointsYeah I know, but a sanity check is always good.
Timothy Hooker
15,323 PointsTimothy Hooker
15,323 PointsI tried to this but it didn't work: