wordpress-theming - Is_single 在创世中无法正常工作
问题描述
我目前正在为我的网站创建一个子主题,它使用 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 作为主页的模板。任何帮助将不胜感激。谢谢
解决方案
看起来你在错误的地方有条件标签。需要在这样的函数之后添加:
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
}
}
根据我的测试,您的代码需要一些工作。
推荐阅读
- python-3.x - 更改绘图轴的单位
- apache - RewriteRules 不加载某些 css。js和图片
- django - 使用 django-extra-views 自动完成
- swift - 将 NSManagedObject 传递给子上下文不起作用
- python - 如何从单选按钮中获取值?
- react-native - navigation.getParent() 总是返回 undefined
- gitlab - 在 gitlab 中启动双管道
- python - 如何在 Pandas 中确定在给定方程的情况下哪些列的行值会产生最终的真值
- pine-script - 查找最近的先前较高枢轴点,然后查找从那时起直到当前价格的最低枢轴点(松树)
- reactjs - 将 websocket 与消息服务一起使用的最佳实践