mh_postnav

The MH Corporate lite mh postnav function.

Description

mh_postnav(); 

Usage

  1. if ( !function_exists( 'mh_postnav' ) ) { 
  2. require_once '/functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = mh_postnav(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/functions.php  
  1. function mh_postnav() { 
  2. global $post; 
  3. $parent_post = get_post($post->post_parent); 
  4. $attachment = is_attachment(); 
  5. $previous = ($attachment) ? $parent_post : get_adjacent_post(false, '', true); 
  6. $next = get_adjacent_post(false, '', false); 
  7.  
  8. if (!$next && !$previous) 
  9. return; 
  10.  
  11. if ($attachment) { 
  12. $attachments = get_children(array('post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => $parent_post->ID)); 
  13. $count = count($attachments); 
  14. if ($attachment && $count == 1) { 
  15. $permalink = get_permalink($parent_post); 
  16. echo '<nav class="post-navigation clearfix" role="navigation">' . "\n"; 
  17. echo '<div class="post-nav left">' . "\n"; 
  18. echo '<a href="' . $permalink . '">' . __('← Back to post', 'mhc') . '</a>'; 
  19. echo '</div>' . "\n"; 
  20. echo '</nav>' . "\n"; 
  21. } elseif (!$attachment || $attachment && $count > 1) { 
  22. echo '<nav class="post-navigation clearfix" role="navigation">' . "\n"; 
  23. echo '<div class="post-nav left">' . "\n"; 
  24. if ($attachment) { 
  25. previous_image_link('%link', __('← Previous image', 'mhc')); 
  26. } else { 
  27. previous_post_link('%link', __('← Previous post', 'mhc')); 
  28. echo '</div>' . "\n"; 
  29. echo '<div class="post-nav right">' . "\n"; 
  30. if ($attachment) { 
  31. next_image_link('%link', __('Next image →', 'mhc')); 
  32. } else { 
  33. next_post_link('%link', __('Next post →', 'mhc')); 
  34. echo '</div>' . "\n"; 
  35. echo '</nav>' . "\n";