В шапке сайта выводится изображение сайта (header_image): на главной странице, в категориях и страницах статей. Нужно указать, чтобы на страницах статей выводилось изображение статьи, а не header_image. С условием, если у статьи имеется изображение, а если не имеется, то header_image.
Код вывода по умолчанию такой:
if ( ! function_exists( 'oblique_header_style' ) ) :
/**
* Styles the header image and text displayed on the blog
*
* @see oblique_custom_header_setup().
*/
function oblique_header_style() {
if ( get_header_image() ) {
?>
<style type="text/css">
.site-header {
background: url(<?php echo get_header_image(); ?>) no-repeat;
background-position: center top;
background-attachment: fixed;
background-size: cover;
}
</style>
<?php
}
}
endif; // oblique_header_style
И нужно как-то встроить в background url примерно следующий код:
<?php if ( has_post_thumbnail() && ( get_theme_mod( 'post_feat_image' ) != 1 ) ) : ?>
<div class="single-thumb">
<?php the_post_thumbnail( 'oblique-single-thumb' ); ?>
</div>
<?php endif; ?>
Пробовал сделать так:
if ( get_header_image() && is_home() || is_archive() || is_search() ) {
?>
<style type="text/css">
.site-header {
background: url(<?php echo get_header_image(); ?>) no-repeat;
background-position: center top;
background-attachment: fixed;
background-size: cover;
}
</style>
<?php
} elseif ( get_header_image() && is_single() ) { ?>
<style type="text/css">
.site-header {
background: url(<?php echo the_post_thumbnail( 'oblique-single-thumb' ); ?>) no-repeat;
background-position: center top;
background-attachment: fixed;
background-size: cover;
}
</style>
<?php
}
}
endif; // oblique_header_style
Но в таком виде на главной странице и категориях все остается по-прежнему. А на страницах статей вместо бэкграунда темный блок, будто не находит фото.
Как это правильно сделать?
Вот так попробуйте:
if ( ! function_exists( 'oblique_header_style' ) ) :
/**
* Styles the header image and text displayed on the blog
*
* @see oblique_custom_header_setup().
*/
function oblique_header_style() {
if ( is_single() && has_post_thumbnail() ) {
$img = get_the_post_thumbnail_url( null, 'oblique-single-thumb' );
} else {
$img = get_header_image();
}
?>
<style type="text/css">
.site-header {
background: url(<?php echo $img; ?>) no-repeat;
background-position: center top;
background-attachment: fixed;
background-size: cover;
}
</style>
<?php
}
endif; // oblique_header_style
Современные инструменты для криптотрейдинга: как технологии помогают принимать решения
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости