0

I want to make a permalink to my most recent blog post. I would use this link as a navbar link. The reason I'm not putting code straight into the navbar is because I am using a widget which will not let me get into the code, and my coding knowledge is next to none. Could someone ELI5 how to do this and where to insert any php if needed. Thanks in advance.

EDIT: Could you also explain how I would implement the PHP code or where I would put it in the WordPress environment.

-2

Use get_posts with posts_per_page => 1 to get only one latest result. You can than use get_permalink() to get the permalink.

$args = array(
         'posts_per_page'   => 1,
        'orderby' => 'date',
        'order'   => 'DESC',
            ) ;
$latest_posts = get_posts($args);
$permalink = get_permalink($latest_posts[0]->ID);
  • 1
    Please correct your mark-up. Your code is also very error prone. You should also add proper explanation to how your code works and what it actually does. (As it stands, all it does is breaking reservered global variables) – Pieter Goosen Jun 30 '16 at 11:57
-2

You Can just add the tag the_permalink() in the The Wordpress Loop with the parameters as order:desc inside anchor tags of yours for example if you want to display the heading tag as a permalink you just can

">Lorem Ipsum } } ?>
  • 1
    Please see How to Answer and also correct your mark-up. Simply dumping code is not a good quality answer – Pieter Goosen Jun 30 '16 at 11:55
  • Please edit your answer, and add an explanation to: why could that solve the problem? – fuxia Jun 30 '16 at 12:29

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.