每个页面的 wordpress 不同横幅图像 - 动态
wordpress different banner images for each pages - dynamically
我的网站由 5 个内页组成,我想为每个页面使用不同的横幅图片。该页面带有侧边栏,但我想要一个全宽横幅,所以我使用了从 wordpress 及其工作中获得的代码
这是代码..
<div class="banner">
<?php
if( is_page('About') ) $img = 'bannerAbout.jpg';
elseif( is_page('Services') ) $img = 'bannerServices.jpg';
elseif( is_page('Testimonials') ) $img = 'bannerTestimonials.jpg';
elseif( is_page('Testimonials') ) $img = 'bannerTestimonials.jpg';
elseif( is_home() ) $img = 'bannerBlog.jpg';
else $img = 'banner.jpg';?>
<img alt="" src="<?php bloginfo('stylesheet_directory'); ?>/images/<?php echo $img;?>" />
</div>
我的问题是,如何在这段代码中调用每个页面的 'Featured Image'? $img=""
之间
或者任何插件?
如果我能调用特色图片,那么上传图片就很容易了,否则我需要一直使用FTP来改变。
请帮我。
提前致谢
将此代码添加到您的主题 functions.php
add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
这将为 post 和页面
启用特色图片
然后在您的 page.php 文件中添加此代码
在内容和侧边栏之前
<?php
global $post;
echo get_the_post_thumbnail($post->ID, 'full'); // visit http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail for more info
?>
在每个条件下放置下面的代码
global $post
echo get_the_post_thumbnail( $post->ID,'full' );
full
将采用您上传的图像的完整尺寸
我的网站由 5 个内页组成,我想为每个页面使用不同的横幅图片。该页面带有侧边栏,但我想要一个全宽横幅,所以我使用了从 wordpress 及其工作中获得的代码
这是代码..
<div class="banner">
<?php
if( is_page('About') ) $img = 'bannerAbout.jpg';
elseif( is_page('Services') ) $img = 'bannerServices.jpg';
elseif( is_page('Testimonials') ) $img = 'bannerTestimonials.jpg';
elseif( is_page('Testimonials') ) $img = 'bannerTestimonials.jpg';
elseif( is_home() ) $img = 'bannerBlog.jpg';
else $img = 'banner.jpg';?>
<img alt="" src="<?php bloginfo('stylesheet_directory'); ?>/images/<?php echo $img;?>" />
</div>
我的问题是,如何在这段代码中调用每个页面的 'Featured Image'? $img=""
之间或者任何插件?
如果我能调用特色图片,那么上传图片就很容易了,否则我需要一直使用FTP来改变。 请帮我。 提前致谢
将此代码添加到您的主题 functions.php
add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
这将为 post 和页面
启用特色图片然后在您的 page.php 文件中添加此代码 在内容和侧边栏之前
<?php
global $post;
echo get_the_post_thumbnail($post->ID, 'full'); // visit http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail for more info
?>
在每个条件下放置下面的代码
global $post
echo get_the_post_thumbnail( $post->ID,'full' );
full
将采用您上传的图像的完整尺寸