0

I am wondering how to make a Link "Go to first post" While I have opened some post?

Any suggestion is welcome.

Thank you.

1

I'll assume by "first" you mean "newest", since if it's the oldest, then all you'd need would be the url of that post.

$latest = get_posts(array('numberposts' => 1));
$url = get_permalink($latest[0]->ID);
echo "<a href='" . $url . "'>Go to first post</a>";

This should give you a link that always goes to whatever is the latest post on your site. Where you add the code is dependant on your theme, as well as your personal preferences.

0

Using bellow function in your theme for get first post link.

<?php
function get_first_post_link() {
    global $wpdb, $table_prefix;
    $result = $wpdb->get_row("select * from {$table_prefix}posts where post_type = 'post' and post_status = 'publish' ORDER BY `{$table_prefix}posts`.`ID` ASC LIMIT 1");
    if($result) {
        return get_permalink( $result->ID );
    }
}

echo get_first_post_link();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.