コード例 #1
0
/**
 * Display relational link for the previous post adjacent to the current post.
 *
 * @since 2.8.0
 *
 * @param string       $title          Optional. Link title format.
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term.
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default true.
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
 */
function prev_post_rel_link($title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category')
{
    echo get_adjacent_post_rel_link($title, $in_same_term, $excluded_terms, true, $taxonomy);
}
コード例 #2
0
 /**
  * @param array $args
  *
  * @return mixed|null
  */
 function get_adjacent_post_link($args = array())
 {
     if (!$this->has_post()) {
         $adjacent_post = null;
     } else {
         $args = wp_parse_args($args, array('format' => '<div class="nav-previous">%link</div>', 'link_format' => false, 'in_same_term' => false, 'excluded_terms' => '', 'taxonomy' => 'category', 'previous' => null));
         WPLib::push_post($this->_post);
         if (function_exists('get_adjacent_post_link')) {
             $adjacent_post = get_adjacent_post_link($args['format'], $args['link_format'], $args['in_same_term'], $args['excluded_terms'], $args['previous'], $args['taxonomy']);
         } else {
             /**
              * Add support to pre 3.7 WordPress
              *
              * @future Add error messages when taxonomy != category
              * @future and when 'link_format' is not false
              */
             $adjacent_post = get_adjacent_post_rel_link($args['format'], $args['in_same_term'], $args['excluded_terms'], $args['previous']);
         }
         WPLib::pop_post();
     }
     return $adjacent_post;
 }
コード例 #3
0
ファイル: link-template.php プロジェクト: vpatrinica/jfdesign
/**
 * Display relational link for the previous post adjacent to the current post.
 *
 * @since 2.8.0
 *
 * @param string $title Optional. Link title format.
 * @param bool $in_same_cat Optional. Whether link should be in same category.
 * @param string $excluded_categories Optional. Excluded categories IDs.
 */
function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '')
{
    echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true);
}
コード例 #4
0
ファイル: cpt-onomy.php プロジェクト: aarongillett/B22-151217
 /**
  * This function mimics the WordPress function get_adjacent_post_rel_link()
  * because we cannot use that function properly.
  *
  * In the WordPress function, get_adjacent_post_rel_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 $title Optional. Link title 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
  * @return string
  */
 function get_adjacent_post_rel_link($title = '%title', $in_same_cpt_onomy = false, $excluded_term_ids = '', $previous = true, $cpt_onomy = '')
 {
     global $cpt_onomies_manager;
     if (empty($cpt_onomy) || !$cpt_onomies_manager->is_registered_cpt_onomy($cpt_onomy)) {
         return get_adjacent_post_rel_link($title, $in_same_cpt_onomy, $excluded_term_ids, $previous);
     }
     if ($previous && is_attachment() && is_object($GLOBALS['post'])) {
         $post =& get_post($GLOBALS['post']->post_parent);
     } else {
         $post = $this->get_adjacent_post($in_same_cpt_onomy, $excluded_term_ids, $previous, $cpt_onomy);
     }
     if (empty($post)) {
         return;
     }
     if (empty($post->post_title)) {
         $post->post_title = $previous ? __('Previous Post', CPT_ONOMIES_TEXTDOMAIN) : __('Next Post', CPT_ONOMIES_TEXTDOMAIN);
     }
     $date = mysql2date(get_option('date_format'), $post->post_date);
     $title = str_replace('%title', $post->post_title, $title);
     $title = str_replace('%date', $date, $title);
     $title = apply_filters('the_title', $title, $post->ID);
     $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
     $link .= esc_attr($title);
     $link .= "' href='" . get_permalink($post) . "' />\n";
     $adjacent = $previous ? 'previous' : 'next';
     return apply_filters("{$adjacent}_post_rel_link", $link);
 }