Php 摘录未显示在“上”;最新帖子“;地区为什么?
我正在开发一个wordpress主题,在主页的主要内容下有一个类似“最新帖子”的区域。自定义主题基于Adamos主题。到目前为止,我是在主要内容打印出来后使用的:Php 摘录未显示在“上”;最新帖子“;地区为什么?,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,我正在开发一个wordpress主题,在主页的主要内容下有一个类似“最新帖子”的区域。自定义主题基于Adamos主题。到目前为止,我是在主要内容打印出来后使用的: <?php wp_reset_query(); $args = array( 'numberposts' => '2' ); $recent_posts = wp_get_recent_posts($args); foreach( $recent_posts as $recent )
<?php
wp_reset_query();
$args = array( 'numberposts' => '2' );
$recent_posts = wp_get_recent_posts($args);
foreach( $recent_posts as $recent ){
setup_postdata($recent);
?>
<div class="index_recent_post">
<div class="index_recent_title">
<h3><?php echo '<a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"].'</a>'; ?></h3>
</div>
<?php
if ( has_post_thumbnail($recent["ID"]) ) {
echo get_the_post_thumbnail($recent["ID"], 'frontpage-thumbnail');
}
echo '<p>' . get_the_excerpt($recent["ID"]) . '</p>';
echo '<a href="' . get_permalink($recent["ID"]) . '" class="recent_link">MORE</a>';
?>
</div>
<?php
}
wp_reset_query();
?>
然而,尽管最新文章的每一项(标题、缩略图、链接)都能完美地工作,但摘录却不能:它显示为空。如果我删除wp\u reset\u query()
和setup\u postdata()
行,它会显示主帖子的摘录,但似乎没有任何方法可以让它显示最新帖子的摘录,即使最新帖子的其余信息显示得很完美
此外,无论文章是否有自定义摘录,摘录都不会显示,因此问题不在于函数查找自定义摘录而没有找到它。我可以通过$recent[“post_extract”]
获取自定义摘录,但只有当它是自定义摘录时,它才会获取它-如果自定义摘录不存在,它将不会基于内容构建一个,这不太理想
有人处理过这个问题吗?你能帮我找到问题所在吗?你能使用以下代码吗?我在本地服务器上测试了这个代码。它工作正常
wp_reset_query();
$args = array( 'numberposts' => '2' );
$recent_posts = wp_get_recent_posts($args);
foreach( $recent_posts as $recent ){
setup_postdata($recent);
?>
<div class="index_recent_post">
<div class="index_recent_title">
<h3><?php echo '<a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"].'</a>'; ?></h3>
</div>
<?php
if ( has_post_thumbnail($recent["ID"]) ) {
echo get_the_post_thumbnail($recent["ID"], 'frontpage-thumbnail');
}
//echo '<p>' . get_the_excerpt($recent["ID"]) . '</p>';
$content= $recent["post_content"];
$excerpt = wp_trim_words( $content, $num_words = 55, $more = null );
echo $excerpt;
echo '<a href="' . get_permalink($recent["ID"]) . '" class="recent_link">MORE</a>';
?>
</div>
<?php
}
wp_reset_query();
wp_reset_query();
$args=数组('numberposts'=>'2');
$recent_posts=wp_get_recent_posts($args);
foreach(最近发布的文章为$recent){
设置_postdata($最近);
?>
这样做了。必须先添加一个条件if($recent[“post_-extract”]==''){
,这样只有在没有自定义摘录的情况下才会生成此摘录,否则我们使用$extract=$recent[“post_-extract”]获取自定义摘录
。因此它的工作方式与它应该的差不多,虽然我不必像这样在系统中四处走动,但这是Wordpress。谢谢!在这种情况下,wp_reset_postdata()和wp_reset_query()之间有什么区别?在这种情况下,wp_reset_postdata()和wp_reset_query()之间有什么区别?