0

i like to put a navigation link in my posts, can you help me?

How can do this? http://prntscr.com/64ksjd

I've this code but, it show 2 hiperlinks, i want 1 hyperlink:

    $post_id = $post->ID; // current post id
$cat = get_the_category(); 
$current_cat_id = $cat[0]->cat_ID; // current category Id 

$args = array('category'=>$current_cat_id,'orderby'=>'post_date','order'=> 'DESC');
$posts = get_posts($args);
// get ids of posts retrieved from get_posts
$ids = array();
foreach ($posts as $thepost) {
    $ids[] = $thepost->ID;
}
// get and echo previous and next post in the same category
$thisindex = array_search($post->ID, $ids);
$previd = $ids[$thisindex-1];
$nextid = $ids[$thisindex+1];

if (!empty($previd)){
?>
<a rel="prev" href="<?php echo get_permalink($previd) ?>">Previous</a>
<?php
}
if (!empty($nextid)){
?>
<a rel="next" href="<?php echo get_permalink($nextid) ?>">Next</a>
<?php
}
?>
  • One hyperlink is one hyperlink. It cannot perform two functions because it is one hyperlink. Perhaps I am misunderstanding your question. – jdm2112 Feb 13 '15 at 14:37
  • Yes i know, 1 hyperlinks is one hyperlinks, but i want to show 1 button to navigation in posts, its thats posible? – Ferrrmolina Feb 13 '15 at 14:38
  • What do you want your button to do? Go to the previous post or the next one? It´s not possible to have one button do both at the same time. – jzatt Feb 13 '15 at 15:00
  • i must display two buttons :/ Wherever, How can check if first or last post of category? – Ferrrmolina Feb 13 '15 at 15:02
  • 1
    In your code above if(!empty($previd)) and if(!empty($nextid)) checks if there is a previous/next post. If there isn't a next/prev post that means you're on the first/last. – jzatt Feb 13 '15 at 15:09

Your Answer

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

Browse other questions tagged or ask your own question.