Is_single在创世纪中无法正常工作

时间:2019-03-08 03:37:08

标签: wordpress-theming genesis

我目前正在为我的网站创建一个子主题,该主题使用创世纪作为父主题。 现在,我根据自己的选择制作单页纸。 因此,我正在从html main中删除条目标头,并将其发布在条目标头之后。 我的代码看起来像这样。

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作为首页的模板。 任何帮助将不胜感激。谢谢

1 个答案:

答案 0 :(得分:0)

好像您将条件标签放在错误的位置。需要在这样的功能之后添加:

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

  }
}

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

相关问题