1
我正在建立一個使用Genesis框架的網站。我遇到了一個問題,即在每個頁面添加一個自定義標題,並使用管理區域中的精選圖像鏈接進行發佈。現在,精選圖片標題將不會顯示在我指定爲「閱讀」設置下的「博客」頁面的頁面上。WordPress的創世紀主題顯示使用特色圖像的自定義標題/背景圖像
這是網站的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
}
}
有誰知道我可以使用功能的圖像顯示在每一頁上自定義標題?
大加讚賞。奇蹟般有效。 –