how to get next/previous post hrefs and titles in wordpress

后端 未结 3 885
刺人心
刺人心 2021-02-04 14:17

It\'s about the view of a single post. I\'m trying to set the links for previous and next blogposts like this way:



        
3条回答
  •  闹比i
    闹比i (楼主)
    2021-02-04 14:59

    Got it.

    Now this is my code:

    $p = get_adjacent_post(1, '', 1);
    if(!empty($p)) echo '';
    $n = get_adjacent_post(1, '', 0);
    if(!empty($n)) echo '';
    

    The function returns an object of the prev/next post which I can use for generating my links. The first parameter is for restricting the post on the same cat.
    I searched in wordpress codex a few times yesterday but didn't come across this function, now stumled upon it by accident.

    If someone has a better/simpler/faster method please post to get an accepted answer.

提交回复
热议问题