我如何获得当前类别的第一篇文章并回显链接?



我尝试创建一个代码,该代码将从类别中检索第一篇文章并回显链接。

但是,代码总是获得当前帖子的永久链接。谁能帮我修复它?

<?php
global $post;
$category = get_the_category($post->ID);
$category = $category[0]->cat_ID;
$array = new WP_Query(array(
'category__in' => array($category),
'post_per_page' => 1,
'order' => 'asc',
'orderby' => 'id'
));?>
<?php the_permalink($post->ID); ?>
$args = array(
'numberposts' => 1, 
'orderby' => 'post_date',
'order' => 'ASC', 
'fields'          => 'ids',
'category' => 8 //or use further logic to check in list
);
$post_cus = get_posts($args);
$first_post_id = $post_cus[0];
$post_url = get_the_permalink ($first_post_id);

最新更新