我目前正在为我的网站创建一个子主题,它使用创世作为父主题。现在我正在根据我的选择制作单页。因此,我从html main中删除了entry header,并将其发布到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作为home的模板。任何帮助都将不胜感激。谢谢
发布于 2019-05-13 04:52:45
看起来你把条件标签放错了地方。需要在函数后面添加如下所示:
add_action( 'genesis_after_header', 'gp_page_header');
function gp_page_header(){
if ( is_singular( 'post' ) ) {
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
$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
}
}根据我的测试,您的代码需要一些工作。
https://stackoverflow.com/questions/55056357
复制相似问题