我正在使用Genesis框架构建站点。我在向每个页面添加自定义标题并使用管理区域中的特色图片链接发布时遇到了问题。现在,在“阅读”设置下,我分配给“博客”页面的页面上不会显示特色图片标题。
这是网站URL,http://ajcustomfinishes.starfireclients.com/。
这是我正在使用的功能:
// Create new image size for our hero image
add_image_size( 'hero-image', 1400, 400, TRUE ); // creates a hero image size
// Hook after header area
add_action( 'genesis_after_header', 'bw_hero_image' );
function bw_hero_image() {
// If it is a page and has a featured thumbnail, but is not the front page do the following...
if (has_post_thumbnail() && is_page() ) {
// Get hero image and save in variable called $background
$image_desktop = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'hero-image' );
$image_tablet = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'large' );
$image_mobile = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'medium' );
$bgdesktop = $image_desktop[0];
$bgtablet = $image_tablet[0];
$bgmobile = $image_mobile[0];
// You can change above-post-hero to any class you want and adjust CSS styles
$featured_class = 'above-post-hero';
?>
<div class='<?php echo $featured_class; ?>'><h1 class="custom-title">AJ Customs Finishes in Las Vegas<br>Call 702-795-7338 today!</h1></div>
<style>
<?php echo ".$featured_class "; ?> {background-image:url( <?php echo $bgmobile; ?>);height:176px;}
@media only screen and (min-width : 480px) {
<?php echo ".$featured_class "; ?> {background-image:url(<?php echo $bgtablet;?>);height:276px;}
}
@media only screen and (min-width : 992px) {
<?php echo ".$featured_class "; ?> {background-image:url(<?php echo $bgdesktop;?>);height:400px;}
}
</style>
<?php
}
}
有人知道我如何使用精选图片在每个页面上显示自定义标题吗?
您的代码中有此情况,如果您在阅读设置中将页面设置为博客,则为FALSE:
if (has_post_thumbnail() && is_page() ) {
is_page()在博客帖子首页(您为阅读中的帖子设置的页面)上为false。
您需要将此条件设置为is_home()为true,即可以将代码重新设置为:
if (has_post_thumbnail() && is_page() || is_home()) {
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句