首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Is_single在genesis中不能正常工作

Is_single在genesis中不能正常工作
EN

Stack Overflow用户
提问于 2019-03-08 11:37:08
回答 1查看 376关注 0票数 0

我目前正在为我的网站创建一个子主题,它使用创世作为父主题。现在我正在根据我的选择制作单页。因此,我从html main中删除了entry header,并将其发布到entry-header之后。我的代码如下所示。

代码语言:javascript
复制
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
 }

如果不想创建主页的这种样式,应该只适用于单个页面。这就是我现在正在做的事情。

代码语言:javascript
复制
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的模板。任何帮助都将不胜感激。谢谢

EN

回答 1

Stack Overflow用户

发布于 2019-05-13 04:52:45

看起来你把条件标签放错了地方。需要在函数后面添加如下所示:

代码语言:javascript
复制
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

  }
}

根据我的测试,您的代码需要一些工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55056357

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档