Wordpress 如何从特定类别中提取最新帖子
我试图从“本地新闻”类别中提取最新的帖子,但我只看到这一类别中存在的两篇帖子中的一篇。我不确定是我的if语句和/或while循环导致了问题。这是我第一次开发一个WP主题并使用PHP,所以我对如何解决这个问题有点困惑。我不知道如何关闭if语句或while循环而不导致严重错误或语法错误Wordpress 如何从特定类别中提取最新帖子,wordpress,wordpress-theming,Wordpress,Wordpress Theming,我试图从“本地新闻”类别中提取最新的帖子,但我只看到这一类别中存在的两篇帖子中的一篇。我不确定是我的if语句和/或while循环导致了问题。这是我第一次开发一个WP主题并使用PHP,所以我对如何解决这个问题有点困惑。我不知道如何关闭if语句或while循环而不导致严重错误或语法错误 如果($q->have_posts()):{ while($q->have_posts()):the_post(){ 下面我已经修复了我注意到的最初问题: <?php $args = arra
如果($q->have_posts()):{
while($q->have_posts()):the_post(){
下面我已经修复了我注意到的最初问题:
<?php
$args = array(
'category_name' => 'local-news',
'post_type' => 'post',
'orderby' => 'date',
'order' => 'DESC',
'posts_per_page' => 6
);
$q = new WP_Query($args);
if ( $q->have_posts() ) :
while ( $q->have_posts() ) :
$q->the_post();
?>
<div class="card-body pb-0">
<div class="latest_news_cont">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
<a href="<?php the_permalink(); ?>">
<h5>
<?php the_title(); ?>
</h5>
</a>
<?php the_excerpt(); ?>
<p style="text-align:center;"><a href="<?php the_permalink(); ?>" class="readmore_news">Read more</a></p>
<br>
</div>
</div>
<div class="card-body pb-0">
<div class="latest_news_cont">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
<a href="<?php the_permalink(); ?>">
<h5>
<?php the_title(); ?>
</h5>
</a>
<?php the_excerpt(); ?>
<p style="text-align:center;"><a href="<?php the_permalink(); ?>" class="readmore_news">Read more</a></p>
<br>
</div>
</div>
<?php
endwhile;
endif;
我明白了,有很多语法问题和开放的php标签
在您的
调用中缺少了一些;
,这是完整的代码吗?按原样,这应该不起作用。PHP在启动HTML时仍然打开。@mikerojas我添加了两个标记,我的所有原始代码都在其中。它仍然不能按原样工作吗?另外,修复缺少的;
也是问题所在吗?