每个页面的 wordpress 不同的横幅图像 - 动态 [英] wordpress different banner images for each pages - dynamically

查看:46
本文介绍了每个页面的 wordpress 不同的横幅图像 - 动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站由 5 个内页组成,我想为每个页面使用不同的横幅图片.该页面带有侧边栏,但我想要一个全宽横幅,所以我使用了从 wordpress 获得的代码及其工作

这是代码..

 

我的问题是,如何在此代码中调用每个页面的特色图片"?$img=""

之间

或者任何插件?

如果我可以调用特色图片,那么上传图片很容易,否则我需要一直使用FTP来更改.请帮我.提前致谢

解决方案

将此代码添加到主题的functions.php

add_theme_support('post-thumbnails', array('post', 'page'));

这将为帖子和页面启用特色图片

然后在您的 page.php 文件中添加此代码在内容和侧边栏之前

ID, 'full');//访问 http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail 了解更多信息?>

My website consist of 5 inner pages, and I want to use different banner images for each page. The page is with side bar, but I want a full width banner, so I used a code which I got from wordpress and its working

this is the code..

    <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>

My question is, How Can I call 'Featured Image' of each page in this code? between $img=""

Or any plug-for this?

If I can call the featured image, then its easy to upload images, otherwise I need to use FTP all the time to change. Please help me. Thanks in Advance

解决方案

Add this code to your theme's functions.php

add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );

this will enable featured image for post and page

Then in your page.php file add this code before content and sidebar

<?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
?>

这篇关于每个页面的 wordpress 不同的横幅图像 - 动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆