예제 #1
0
/**
 * Display next post link that is adjacent to the current post.
 *
 * @since 1.5.0
 *
 * @param string $format Optional. Link anchor format.
 * @param string $link Optional. Link permalink format.
 * @param bool $in_same_cat Optional. Whether link should be in same category.
 * @param string $excluded_categories Optional. Excluded categories IDs.
 */
function next_post_link($format = '%link »', $link = '%title', $in_same_cat = false, $excluded_categories = '')
{
    adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
}
예제 #2
0
 /**
  * This function mimics the WordPress function adjacent_post_link()
  * because we cannot use that function properly.
  *
  * In the WordPress function, adjacent_post_link(), you are only allowed
  * to use 'category' for your taxonomy but this function adds a new parameter that 
  * allows you to designate which CPT-onomy you would like to use.
  *
  * @since 1.0.2
  * @uses $cpt_onomies_manager
  * @param string $format Link anchor format.
  * @param string $link Link permalink format.
  * @param bool $in_same_cpt_onomy Optional. Whether link should be in a same CPT-onomy.
  * @param array|string $excluded_term_ids Optional. Array or comma-separated list of excluded term IDs.
  * @param bool $previous Optional, default is true. Whether to display link to previous or next post.
  * @param string $cpt_onomy - name of the CPT-onomy for $in_same_cpt_onomy
  */
 function adjacent_post_link($format, $link, $in_same_cpt_onomy = false, $excluded_term_ids = '', $previous = true, $cpt_onomy = '')
 {
     global $cpt_onomies_manager;
     // If it's empty or not a valid CPT-onomy, then run the default WordPress function
     if (empty($cpt_onomy) || !$cpt_onomies_manager->is_registered_cpt_onomy($cpt_onomy)) {
         adjacent_post_link($format, $link, $in_same_cpt_onomy, $excluded_term_ids, $previous);
     } else {
         if ($previous && is_attachment()) {
             $post =& get_post($GLOBALS['post']->post_parent);
         } else {
             $post = $this->get_adjacent_post($in_same_cpt_onomy, $excluded_term_ids, $previous, $cpt_onomy);
         }
         if (!$post) {
             return;
         }
         $title = $post->post_title;
         if (empty($post->post_title)) {
             $title = $previous ? __('Previous Post', CPT_ONOMIES_TEXTDOMAIN) : __('Next Post', CPT_ONOMIES_TEXTDOMAIN);
         }
         $title = apply_filters('the_title', $title, $post->ID);
         $date = mysql2date(get_option('date_format'), $post->post_date);
         $rel = $previous ? 'prev' : 'next';
         $string = '<a href="' . get_permalink($post) . '" rel="' . $rel . '">';
         $link = str_replace('%title', $title, $link);
         $link = str_replace('%date', $date, $link);
         $link = $string . $link . '</a>';
         $format = str_replace('%link', $link, $format);
         $adjacent = $previous ? 'previous' : 'next';
         echo apply_filters("{$adjacent}_post_link", $format, $link);
     }
 }