最新公告
  • 欢迎您光临知事网,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!立即加入我们
  • WordPress函数get_the_content()用法 调用当前文章的正文内容

    描述:

    获取当前文章的正文内容

    用法:

    <?php get_the_content( $more_link_text, $stripteaser ) ?>

    参数:

    $more_link_text
    
    (string) (可选) 当有更多文本时的内容。
    
    默认值: null
    
    $stripteaser
    
    (boolean) (可选) 在更多的文本之前删除摘要内容。
    
    默认值: false

    示例:

    <?php
    $content = get_the_content('Read more');
    print $content;
    ?>

    源文件:

    unction get_the_content( $more_link_text = null, $strip_teaser = false, $post = null ) {
    global $page, $more, $preview, $pages, $multipage;
    
    $_post = get_post( $post );
    
    if ( ! ( $_post instanceof WP_Post ) ) {
    return '';
    }
    
    if ( null === $post ) {
    $elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' );
    } else {
    $elements = generate_postdata( $_post );
    }
    
    if ( null === $more_link_text ) {
    $more_link_text = sprintf(
    '<span aria-label="%1$s">%2$s</span>',
    sprintf(
    /* translators: %s: Post title. */
    __( 'Continue reading %s' ),
    the_title_attribute(
    array(
    'echo' => false,
    'post' => $_post,
    )
    )
    ),
    __( '(more&hellip;)' )
    );
    }
    
    $output = '';
    $has_teaser = false;
    
    // If post password required and it doesn't match the cookie.
    if ( post_password_required( $_post ) ) {
    return get_the_password_form( $_post );
    }
    
    if ( $elements['page'] > count( $elements['pages'] ) ) { // if the requested page doesn't exist
    $elements['page'] = count( $elements['pages'] ); // give them the highest numbered page that DOES exist
    }
    
    $page_no = $elements['page'];
    $content = $elements['pages'][ $page_no - 1 ];
    if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
    if ( has_block( 'more', $content ) ) {
    // Remove the core/more block delimiters. They will be left over after $content is split up.
    $content = preg_replace( '/<!-- \/?wp:more(.*?) -->/', '', $content );
    }
    
    $content = explode( $matches[0], $content, 2 );
    
    if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) {
    $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
    }
    
    $has_teaser = true;
    } else {
    $content = array( $content );
    }
    
    if ( false !== strpos( $_post->post_content, '<!--noteaser-->' ) && ( ! $elements['multipage'] || $elements['page'] == 1 ) ) {
    $strip_teaser = true;
    }
    
    $teaser = $content[0];
    
    if ( $elements['more'] && $strip_teaser && $has_teaser ) {
    $teaser = '';
    }
    
    $output .= $teaser;
    
    if ( count( $content ) > 1 ) {
    if ( $elements['more'] ) {
    $output .= '<span id="more-' . $_post->ID . '"></span>' . $content[1];
    } else {
    if ( ! empty( $more_link_text ) ) {
    
    /**
    * Filters the Read More link text.
    *
    * @since 2.8.0
    *
    * @param string $more_link_element Read More link element.
    * @param string $more_link_text Read More text.
    */
    $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink( $_post ) . "#more-{$_post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
    }
    $output = force_balance_tags( $output );
    }
    }
    
    return $output;
    }
    找互联网优质资源,上知事网!
    知事网 » WordPress函数get_the_content()用法 调用当前文章的正文内容

    常见问题FAQ

    网盘提取密码在哪里?
    在网站右侧有个“文件密码”,点击复制即可!
    网站的积分如何获得?
    注册登录后,每天签到可获得2个积分,每天可签到一次!

    发表评论

    • 1255会员总数(位)
    • 665资源总数(个)
    • 3本周发布(个)
    • 0 今日发布(个)
    • 3459稳定运行(天)

    提供最优质的资源集合

    Mac软件 Dedecms源码
    升级SVIP尊享更多特权立即升级