【发布时间】:2015-01-02 00:13:14
【问题描述】:
正在尝试在自定义主题中的帖子内容上方获取单个帖子图片和标题。 我可以在图片下方获取图片标题,在新 div 下方获取剩余内容吗?
当前代码:
<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-## -->
这适用于显示帖子图像和摘录,但不适用于带有标题的图像,而不是完整的帖子文本。
替换这个:
<?php the_excerpt(); ?>
与:
<?php the_content(); ?>
再次返回完整的帖子内容,包括图片。
【问题讨论】:
-
我建议在...问题帖子的开头提出您的问题。 :) 如果我们需要搜索问题到底是什么,那么帮助那个人就更困难了。
-
在获取图像/缩略图标题时,我能够弄清楚问题的前半部分。替换 使用上面的新代码。仍在尝试弄清楚如何获取“新闻共享”div下方的帖子内容。
标签: php wordpress custom-post-type