Wordpress get_header_image 和 Nivo 滑块切换 - PHP If Else 语句?

发布于 2024-12-10 07:31:54 字数 1329 浏览 2 评论 0原文

好的,这是我的问题。我希望能够使用 get_header_image 和 Nivo Slider 在自定义标头之间切换。有一次我完成了这项工作,将代码合并到 If...Elseif...Else 语句中。现在我无法复制它。当前代码显示标题图像及其下方的滑块。任何帮助将不胜感激。

<?php
// Check if this is a post or page, if it has a thumbnail, and if it's a big one
if( 
    is_singular() 
    && current_theme_supports('post-thumbnails') 
    && has_post_thumbnail( $post->ID ) 
    &&( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) 
    && $image[1] >= HEADER_IMAGE_WIDTH 
) :
    // Houston, we have a new header image!
    echo get_the_post_thumbnail( $post->ID );
elseif ( get_header_image() ) : 
?>
    <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
<?php 
endif; 
?>

<div id="slider">
<?php
$tmp = $wp_query;
$wp_query = new WP_Query( array ('post_type'=>'page','post__in'=>array(1814)));
if(have_posts()) :
    while(have_posts()) :
        the_post();
?>
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('nivothumb'); ?></a>
<?php
    endwhile;
endif;

$wp_query = $tmp; 
?>
</div><!-- close #slider -->

Okay so here's my issue. I want to be able to toggle between a custom header using get_header_image and Nivo Slider. At one point I had this working, having merged the code into a If...Elseif...Else statement. Now I can't replicate it. The current code display both the header image and the slider beneath it. Any help would be greatly appreciated.

<?php
// Check if this is a post or page, if it has a thumbnail, and if it's a big one
if( 
    is_singular() 
    && current_theme_supports('post-thumbnails') 
    && has_post_thumbnail( $post->ID ) 
    &&( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) 
    && $image[1] >= HEADER_IMAGE_WIDTH 
) :
    // Houston, we have a new header image!
    echo get_the_post_thumbnail( $post->ID );
elseif ( get_header_image() ) : 
?>
    <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
<?php 
endif; 
?>

<div id="slider">
<?php
$tmp = $wp_query;
$wp_query = new WP_Query( array ('post_type'=>'page','post__in'=>array(1814)));
if(have_posts()) :
    while(have_posts()) :
        the_post();
?>
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('nivothumb'); ?></a>
<?php
    endwhile;
endif;

$wp_query = $tmp; 
?>
</div><!-- close #slider -->

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

东风软 2024-12-17 07:31:54
<?php
if( 
    is_singular() 
    && current_theme_supports('post-thumbnails') 
    && has_post_thumbnail( $post->ID ) 
    &&( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) 
    && $image[1] >= HEADER_IMAGE_WIDTH )
{
  echo get_the_post_thumbnail( $post->ID );
}
elseif ( get_header_image() )
{ ?>
    <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="   <?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
<?php } ?>
<?php
if( 
    is_singular() 
    && current_theme_supports('post-thumbnails') 
    && has_post_thumbnail( $post->ID ) 
    &&( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) 
    && $image[1] >= HEADER_IMAGE_WIDTH )
{
  echo get_the_post_thumbnail( $post->ID );
}
elseif ( get_header_image() )
{ ?>
    <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="   <?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
<?php } ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文