【问题标题】:How to show recently added posts to my custom post category?如何在我的自定义帖子类别中显示最近添加的帖子?
【发布时间】:2013-12-17 14:46:45
【问题描述】:

我在一个 wordpress 网站上工作,想在我的自定义帖子类别中显示标题及其最近添加的帖子的永久链接,我尝试了许多来自网络的推荐,但都失败了。

这里的任何人,建议我显示自定义帖子类型类别的 php 代码 - 最近添加。

谢谢

【问题讨论】:

  • 您想在前端创建的自定义类别中列出最近的帖子吗?
  • 不,我想在我的自定义模板中显示最近的自定义帖子类型 POST
  • 您要显示多少最近的自定义帖子?

标签: wordpress custom-post-type


【解决方案1】:

试试这个:

<?php
    $post_type = 'your custom post type';
    $posts_per_page = '5';
    $queryObject = new WP_Query( 'post_type='. $post_type .'&posts_per_page='. $posts_per_page );
    // The Loop!
    if ($queryObject->have_posts()) {
?>
        <ul>
<?php
            while ($queryObject->have_posts()) {
                $queryObject->the_post();
?>
                <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></li><?php
            }
?>
        </ul>
<?php
    }
?>

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-29
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    • 2020-05-11
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多