previous_post

Prints a link to the previous post.

Description

previous_post( , (string) $previous = 'previous post: ', (string) $title = 'yes', (string) $in_same_cat = 'no', (int) $limitprev = 1, (string) $excluded_categories = '' ); 

Parameters (6)

0. $format — Optional. (string) => '%'
The format.
1. $previous — Optional. (string) => 'previous post: '
The previous.
2. $title — Optional. (string) => 'yes'
The title.
3. $in_same_cat — Optional. (string) => 'no'
The in same cat.
4. $limitprev — Optional. (int) => 1
The limitprev.
5. $excluded_categories — Optional. (string) => ''
The excluded categories.

Usage

  1. if ( !function_exists( 'previous_post' ) ) { 
  2. require_once ABSPATH . WPINC . '/deprecated.php'; 
  3.  
  4. // The format. 
  5. $format = '%'; 
  6.  
  7. // The previous. 
  8. $previous = 'previous post: '; 
  9.  
  10. // The title. 
  11. $title = 'yes'; 
  12.  
  13. // The in same cat. 
  14. $in_same_cat = 'no'; 
  15.  
  16. // The limitprev. 
  17. $limitprev = 1; 
  18.  
  19. // The excluded categories. 
  20. $excluded_categories = ''; 
  21.  
  22. // NOTICE! Understand what this does before running. 
  23. $result = previous_post($format, $previous, $title, $in_same_cat, $limitprev, $excluded_categories); 
  24.  

Defined (1)

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

/wp-includes/deprecated.php  
  1. function previous_post($format='%', $previous='previous post: ', $title='yes', $in_same_cat='no', $limitprev=1, $excluded_categories='') { 
  2.  
  3. _deprecated_function( __FUNCTION__, '2.0.0', 'previous_post_link()' ); 
  4.  
  5. if ( empty($in_same_cat) || 'no' == $in_same_cat ) 
  6. $in_same_cat = false; 
  7. else 
  8. $in_same_cat = true; 
  9.  
  10. $post = get_previous_post($in_same_cat, $excluded_categories); 
  11.  
  12. if ( !$post ) 
  13. return; 
  14.  
  15. $string = '<a href="'.get_permalink($post->ID).'">'.$previous; 
  16. if ( 'yes' == $title ) 
  17. $string .= apply_filters('the_title', $post->post_title, $post->ID); 
  18. $string .= '</a>'; 
  19. $format = str_replace('%', $string, $format); 
  20. echo $format;