个性化阅读
专注于IT技术分析

Is_single在genesis中无法正常工作

我目前正在为我的网站创建一个以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


看起来你在错误的位置放置了条件标签。需要在这样的功能之后添加:

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)
未经允许不得转载:srcmini » Is_single在genesis中无法正常工作

评论 抢沙发

评论前必须登录!