在get_The_except()中输出的"Read More"链接;其他模板上的摘录链接到正确的帖子,但在下面的代码中(在另一个模板上),"阅读更多"链接指向用户当前所在的页面,而不是帖子的永久链接。我看到其他人在其他论坛上发布了同样的问题,但在有解决方案之前,他们都被关闭了。
如有任何帮助,我们将不胜感激。
foreach($pr_content as $ID) {
$post_temp = $post;
setup_postdata(get_post($ID));
$excerpt = get_the_excerpt();
$post = $post_temp;
echo '<article>';
echo '<h4><a href="'.get_the_permalink($ID).'">'.get_the_title($ID).'</a></h4>';
echo $excerpt;
echo '</article>';
}
将get_the_permalink($ID)
更改为get_permalink($ID)
您没有放入$ID,因为$ID不是post-ID
所以你必须放<?php get_the_ID(); ?>
所以你的代码就像
foreach($pr_content as $ID) {
$post_temp = $post;
setup_postdata(get_post($ID));
$excerpt = get_the_excerpt();
$post = $post_temp;
echo '<article>';
echo '<h4><a href="'.get_the_permalink(get_the_ID()).'">'.get_the_title(get_the_ID()).'</a></h4>';
echo $excerpt;
echo '</article>';
}
我最终改变了提取数组的方式。感谢您的反馈。这种方法解决了这个问题。
if($pr_content) {
$the_query = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => -1,
'post__in' => $pr_content,
'post_status' => 'any',
));
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<article>
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<?php the_excerpt(); ?>
</article>
<?php endwhile; wp_reset_postdata(); ?>
<?php } ?>