我目前正在为我的网站创建一个子主题,它使用Genesis作为父主题。现在我正在根据自己的选择制作单页。因此,我将从HTML main中删除条目标题,并在entry-header
. 我的代码如下所示。
remove_action( \'genesis_entry_header\', \'genesis_do_post_title\' );
remove_action( \'genesis_entry_header\', \'genesis_post_info\', 12 );
add_action( \'genesis_after_header\', \'gp_page_header\');
function gp_page_header(){
$image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), \'single-post-thumbnail\' );
?>
<div class="post-hero" style="background-repeat: no-repeat;background-size:cover;background-image: -webkit-radial-gradient(left top, circle cover, rgba(100, 66, 255, 0.9) 15%, rgba(0, 108, 255, 0.9) 50%, rgba(12, 180, 206, 0.9) 85%), url(\'<?php echo $image[0]; ?>\')">
<div class="wrap">
<?php
the_title( \'<h1 class="entry-title" itemprop="headline">\', \'</h1>\' );
genesis_post_info();
?>
</div>
</div>
<?php
}
如果不想为主页创建此样式,则应仅应用于单个页面。这就是我现在正在做的。
remove_action( \'genesis_entry_header\', \'genesis_do_post_title\' );
remove_action( \'genesis_entry_header\', \'genesis_post_info\', 12 );
if(is_single()) {
add_action( \'genesis_after_header\', \'gp_page_header\');
function gp_page_header(){
$image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), \'single-post-thumbnail\' );
?>
<div class="post-hero" style="background-repeat: no-repeat;background-size:cover;background-image: -webkit-radial-gradient(left top, circle cover, rgba(100, 66, 255, 0.9) 15%, rgba(0, 108, 255, 0.9) 50%, rgba(12, 180, 206, 0.9) 85%), url(\'<?php echo $image[0]; ?>\')">
<div class="wrap">
<?php
the_title( \'<h1 class="entry-title" itemprop="headline">\', \'</h1>\' );
genesis_post_info();
?>
</div>
</div>
<?php
}
}
但这种方式行不通。如果我使用条件标记,它就不起作用。我现在很困惑。此外,我正在使用
front-page.php
作为主页的模板。任何帮助都将不胜感激。
SO网友:Gufran Hasan
请采取行动add_action( \'genesis_after_header\', \'gp_page_header\');
在里面if condition
不是完整的代码。
if(is_single()){
add_action( \'genesis_after_header\', \'gp_page_header\');
}
Your updated code:
if(is_single()) {
add_action( \'genesis_after_header\', \'gp_page_header\');
}
function gp_page_header(){
$image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), \'single-post-thumbnail\' );
?>
<div class="post-hero" style="background-repeat: no-repeat;background-size:cover;background-image: -webkit-radial-gradient(left top, circle cover, rgba(100, 66, 255, 0.9) 15%, rgba(0, 108, 255, 0.9) 50%, rgba(12, 180, 206, 0.9) 85%), url(\'<?php echo $image[0]; ?>\')">
<div class="wrap">
<?php
the_title( \'<h1 class="entry-title" itemprop="headline">\', \'</h1>\' );
genesis_post_info();
?>
</div>
</div>
<?php
}