首页 > 解决方案 > Wordpress 网站只显示最新帖子

问题描述

我的 WordPress 网站是一个编码网站,最近我在主页上创建了一个新块来处理来自我的一个类别的所有最新帖子。但问题是第一个或最新的帖子在页面上返回一个空白区域。我的页面上有其他块可以执行此操作,但这个问题不会发生在他们身上,我只复制了他们的代码。我试图更改帖子的类别,它适用于其他人。只有新创建的类别块会产生此问题。我已经检查了空帖子的元素,它不会像下一个帖子那样返回 href 块。

<div style="border: 2px solid #23429a; width: 210px; float: left; border-top-left-radius:3px; border-top-right-radius:3px;" >
       <!--TITLE-->
       <div style="background-color: #23429a; color: white; padding: 6.3px 6px; font-size: 16px;">
         <b>My category</b>
       </div>
       <!--CONTENT-->
       <div style="height: 190px; margin-top: -8px; margin-bottom: -8px;">
             <div class="test" style="margin: 10px 5px">
                <?php $the_thirdquery = new WP_Query(array('cat' => 32, 'posts_per_page' => 4)); ?>
                <table style="font-size: 14px; margin: auto;">
                  <tbody>
                <?php while ($the_thirdquery -> have_posts()) : $the_thirdquery -> the_post(); ?>
                    <tr style="height: 35px;">
                      <td width="30px">
                         <font style="vertical-align: inherit;">
                            <font style="vertical-align: inherit;"><?php the_time('m/d'); ?></font>
                         </font>
                      </td>
                      <td style="padding-left:20px;">
                        <div style="font-size: 13px; width: 140px;">
                        <?php if ($custom_post_type == "Clinic") { ?>
                          <a href= "<?php the_permalink(); ?>" target="_blank"> <?php the_title(); ?></a>
                        <?php } ?>
                        </div>
                      </td>
                     <!-- <td style="text-align: right; padding-left:25px;" width="20px">
                      <font style="vertical-align: inherit;">
                        <font style="vertical-align: inherit;"> -->
                          <?php $custom_post_type = get_post_meta($post->ID, 'custom_element_grid_class_meta_box', true);?>
                          <!-- <?php #echo $custom_post_type;?> -->
                        <!-- </font>
                      </font>
                    </td> -->
                    </tr>
                <?php
                endwhile;
                ?>
                </tbody>
                </table>
                <?php
                wp_reset_postdata();
                ?>
             </div>
         </div>
    </div>

对不起我的代码。

但是还有其他人经历过这种情况吗?

标签: phpwordpress

解决方案


如果您遇到$the_thirdquery了几行的问题,那么我认为您在数组中没有足够的 args 来完成您想要从WP_Query. 此外,我不确定$custom_post_type调用来自何处或被用作在if()块之后声明的调用。如果它是自定义帖子类型,请将其添加到$args. 试试这个,看看它是怎么回事,然后评论你的结果。

$args = array(
  'cat' => 32,
  'posts_per_page' => 4,
  'post_type' => 'clinic',
  'orderby' => 'date',
  'order' => 'DESC',
);
$query = new WP_Query($args);
if($query->have_posts()):while($query->have_posts()):$query->the_post(); {
  // add your code here for the query.
}

推荐阅读