【发布时间】:2026-02-01 15:30:02
【问题描述】:
我正在尝试在一个 div 中使用帖子图像/缩略图,并在自定义布局上使用新 div 中的内容。在显示图像后尝试获取内容时遇到问题。
这可以使我的帖子标题和图像进入所需的布局,但不显示图像标题–
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( '<h3 class="title no-underline">', '</h3>' ); ?>
</header><!-- .entry-header -->
<div class="news-images">
<div id="news-swiper" class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide" data-caption="">
<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>
</div>
</div>
</div>
</div>
<div class="news-sharing">
<?php wpsocialite_markup(); ?>
</div>
这是我试图获取剩余帖子内容并遇到问题的地方。
<div class="news-item-copy">
<?php the_excerpt(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'themeName' ),
'after' => '</div>',
) );
?>
</div>
</article>
我使用<?php the_excerpt(); ?> 只是将内容放置在所需的位置,但显然因为它是摘录,它没有显示完整的内容。想法是将带有标题的特色图片/缩略图放在顶部,社交分享放在中间,内容放在最后。
【问题讨论】:
标签: php wordpress custom-post-type