Permanent link to oldest wordpress post

I kept the Prev-Next option on one post page to navigate through posts and this is what I use for the next button.   <?php echo get_permalink(get_adjacent_post(false,'',false)); ?>

But I can't figure out how to associate this same button with the very first posts when there are no new posts to show. The reason is that messages are used to display products.

Note that this code is used to associate the Prev button on the oldest entry with the last entry I used.

<?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;
                    }?>

      

+3


source to share


1 answer


add args to request any messages that are part of the products.

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

      



$ args should be something like this (make sure it returns all product messages):

$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 
);

      

+2


source







All Articles