首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在单个帖子页面上放置wordpress图像标题和内容时出现问题

在单个帖子页面上放置wordpress图像标题和内容时出现问题
EN

Stack Overflow用户
提问于 2015-01-02 08:13:14
回答 1查看 134关注 0票数 1

工作中试图获得一个自定义主题以上的帖子内容的单一帖子图像和标题。我可以在图片下方获取图片标题,在新div下获取剩余内容吗?

当前代码:

代码语言:javascript
复制
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <header class="entry-header">
        <?php the_title( '<h3 class="title no-underline">', '</h3>' ); ?>
    </header>

    <div class="entry-content news-item-copy">
        <?php
    $get_description = get_post(get_post_thumbnail_id())->post_excerpt;
    the_post_thumbnail();
    if(!empty($get_description)){//If description is not empty show the div
    echo '<div class="image-captions">' . get_post(get_post_thumbnail_id())->post_excerpt . '</div>';
    }
    ?>

        <div class="news-sharing">
        <a class="socialite twitter-share" href="" target="_blank" data-via="" data-text="New Website Launch — " data-url="" data-count="horizontal">Share on Twitter</a>
        <a class="facebook-like socialite" data-href="" target="_blank" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false">Like on Facebook</a>
        </div>

        <?php the_excerpt(); ?> 

        <?php
        wp_link_pages( array(
            'before' => '<div class="page-links">' . __( 'Pages:', 'themeName' ),
            'after'  => '</div>',
        ) );
        ?>
    </div><!-- .entry-content -->
</article><!-- #post-## -->

这适用于显示帖子图像和摘录,但不能显示带有标题的图像,也不能显示完整的帖子文本。

替换为:

代码语言:javascript
复制
<?php the_excerpt(); ?>

通过以下方式:

代码语言:javascript
复制
 <?php the_content(); ?>

再次返回包含图片的完整帖子内容。

EN

回答 1

Stack Overflow用户

发布于 2015-01-02 09:00:44

字幕也称为post_excerpt。

代码语言:javascript
复制
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <header class="entry-header">
        <?php the_title( '<h3 class="title no-underline">', '</h3>' ); ?>
    </header>

    <div class="entry-content news-item-copy">
        <?php
        if(has_post_thumbnail())
        {
            the_post_thumbnail();
            $thumbnail_id  = get_post_thumbnail_id(get_the_ID());
            $thumbnail_data = get_post($thumbnail_id);
            $caption = $thumbnail_data->post_excerpt;
            if(!empty($caption)){//If description is not empty show the div
                echo '<div class="image-captions">' . $caption . '</div>';
            }
        }
        ?>
        <div class="news-sharing">
            <a class="socialite twitter-share" href="" target="_blank" data-via="" data-text="New Website Launch — " data-url="" data-count="horizontal">Share on Twitter</a>
            <a class="facebook-like socialite" data-href="" target="_blank" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false">Like on Facebook</a>
        </div>

        <?php
        echo the_content();
        wp_link_pages( array(
            'before' => '<div class="page-links">' . __( 'Pages:', 'themeName' ),
            'after'  => '</div>',
        ) );
        ?>
    </div><!-- .entry-content -->
</article><!-- #post-## -->

在此之后,您的不需要添加特色/缩略图图像到帖子内容,它将不会再次出现在内容中。我希望现在这是有意义的。

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

https://stackoverflow.com/questions/27735959

复制
相关文章

相似问题

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