我想要的东西可以在主页上显示某段代码,但在其他所有页面上都有其他内容。
我正在寻找类似的东西:
<?php is_front_page()
If true ( the-piece-of-code-I-wanna-use-on-the-homepage )
Else ( the-code-I-want-to-use-on-every-other-page )
; ?>
我知道上面的错误:P,我对php不太好。但我希望有人能给我一些有用的东西。
干杯。
编辑: 我希望它是这样的:
<?php if(is_front_page()){ echo "
<?php
// Check to see if the header image has been removed
$header_image = get_header_image();
if ( $header_image ) :
// Compatibility with versions of WordPress prior to 3.4.
if ( function_exists( 'get_custom_header' ) ) {
// We need to figure out what the minimum width should be for our featured image.
// This result would be the suggested width if the theme were to implement flexible widths.
$header_image_width = get_theme_support( 'custom-header', 'width' );
} else {
$header_image_width = HEADER_IMAGE_WIDTH;
}
?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<?php
// The header image
// Check if this is a post or page, if it has a thumbnail, and if it's a big one
if ( is_singular() && has_post_thumbnail( $post->ID ) &&
( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( $header_image_width, $header_image_width ) ) ) &&
$image[1] >= $header_image_width ) :
// Houston, we have a new header image!
echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
else :
// Compatibility with versions of WordPress prior to 3.4.
if ( function_exists( 'get_custom_header' ) ) {
$header_image_width = get_custom_header()->width;
$header_image_height = get_custom_header()->height;
} else {
$header_image_width = HEADER_IMAGE_WIDTH;
$header_image_height = HEADER_IMAGE_HEIGHT;
}
?>
<img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="" />
<?php endif; // end check for featured image or standard header ?>
</a>
<?php endif; // end check for removed header image ?>
"; } else { echo "
<?php if ( function_exists( 'show_simpleresponsiveslider' ) ) show_simpleresponsiveslider(); ?>
<?php if ( 'blank' == get_header_textcolor() ) : "; ?>
} ?>
答案 0 :(得分:0)
<?php
if(is_front_page()){
echo "code here for front page";
} else {
echo "code for other pages";
} ?>
这应该是你正在寻找的东西。 is_front_page()函数将返回true或false,然后显示正确的代码。
答案 1 :(得分:0)
您可以使用is_home函数。
<?php
if (is_home()) {
// This is a homepage
} else {
// This is not a homepage
}
?>