【问题标题】:custom Post content in WordPressWordPress中的自定义帖子内容
【发布时间】:2020-10-04 12:00:48
【问题描述】:

如您所知,以下代码在其 WordPress 中发布群组中的最新内容

<?php
            $my_query = new WP_Query('showposts=1&cat=172');
            while ($my_query->have_posts()):
            $my_query->the_post();
            $do_not_duplicate = $post->ID;
            ?>

我想对此代码进行更改,以便不显示组中的最后一篇文章,并且 , 并显示同组预决赛内容。 谢谢你

【问题讨论】:

    标签: wordpress wordpress-theming custom-wordpress-pages wordpress-rest-api


    【解决方案1】:

    我想您可能想看看偏移量和顺序参数。 我猜你问题中的快照就是你所说的“组”...... 根据您所说的最后一篇文章(最后发表或首次发表),您可能希望将顺序从“DESC”更改为“ASC”。

    <?php $query = new wp_query( array( 'post_type' => 'post', 'cat' => '172', 'post_status' => 'publish', 'posts_per_page' => '3', 'offset' => '1', 'order' => 'DESC' ) ); ?>
    <?php if ( $query->have_posts() ): while ( $query->have_posts() ): $query->the_post(); ?>
    <a aria-label="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php endwhile; endif; ?>
    

    gl.

    编辑:只是一个想法...您也可以简单地使用纯 CSS 并使用:last-child 定位您的最后一篇文章...请参阅https://developer.mozilla.org/fr/docs/Web/CSS/:last-child

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-11
      • 2014-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-02
      • 1970-01-01
      相关资源
      最近更新 更多