获取wordpress中最早的帖子的永久链接

问题描述 投票:4回答:1

我在单个帖子页面中保留了上一个-下一个选项,可以浏览这些帖子,这就是我使用的下一个按钮。<?php echo get_permalink(get_adjacent_post(false,'',false)); ?>但是,当没有更多新帖子要显示时,我想不出一种将相同按钮链接到第一篇帖子的方法。原因是帖子用于展示产品。

请注意:要将最早的帖子中的“上一页”按钮链接到我已使用此代码的最新帖子。

<?php $next_page=get_permalink(get_adjacent_post(false,'',true)); 
    $current_page=get_permalink();
    if($next_page==$current_page){
        $args = array( 'numberposts' => '1', 'category' => CAT_ID );
        $recent_posts = wp_get_recent_posts( $args );
        foreach( $recent_posts as $recent ){
            echo get_permalink($recent["ID"]);
        }
    } else {
        echo $next_page;
    }
?>
php wordpress
1个回答
3
投票

添加参数以查询产品所包含的帖子。

$posts_array = get_posts( $args );
get_permalink($posts_array[0]->ID); // First posts;

$ args应该是这样的(确保它返回所有产品的帖子):

$args = array(
    'offset'           => 0,
    'category'         => '',
    'category_name'    => '',
    'orderby'          => 'ASC',
    'order'            => 'DESC',
    'include'          => '',
    'exclude'          => '',
    'meta_key'         => '',
    'meta_value'       => '',
    'post_type'        => 'post',
    'post_mime_type'   => '',
    'post_parent'      => '',
    'post_status'      => 'publish',
    'suppress_filters' => true 
);
© www.soinside.com 2019 - 2024. All rights reserved.