/** * Display adjacent post link. * * Can be either next post link or previous. * * @since 2.5.0 * * @param string $format Link anchor format. * @param string $link Link permalink 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 category IDs. * @param bool $previous Optional. Whether to display link to previous or next post. Default true. * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. */ function adjacent_post_link($format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category') { echo get_adjacent_post_link($format, $link, $in_same_term, $excluded_terms, $previous, $taxonomy); }
/** * @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; }
/** * Helper function to build a next and previous post navigation element on * single entries. This takes care of all the annoying formatting which usually * would need to be done within a template. * * I originally wanted to use the new get_the_post_navigation tag for this; * however, it's lacking a lot of the flexibility provided by using the old * template tags directly. Until WordPress core gets its act together, I guess * I'll just have to duplicate code for no good reason. * * @since 1.0.0 * @access public * @param array $args Empty array if no arguments. * @return string */ function carelib_get_post_navigation($args = array()) { if (is_attachment() || !is_singular()) { return; } $name = _carelib_get_post_type_name(get_queried_object()); $defaults = apply_filters("{$GLOBALS['carelib_prefix']}_post_navigation_defaults", array('post_types' => array(), 'prev_format' => '<span class="nav-previous">%link</span>', 'next_format' => '<span class="nav-next">%link</span>', 'prev_text' => __('Previous', 'carelib') . esc_html($name), 'next_text' => __('Next', 'carelib') . esc_html($name), 'in_same_term' => false, 'excluded_terms' => '', 'taxonomy' => 'category')); $args = wp_parse_args($args, $defaults); $types = (array) $args['post_types']; // Bail if we're not on a single entry. All post types except pages are allowed by default. if (!is_singular($types) || !in_array('page', $types, true) && is_page()) { return false; } $required = isset($args['prev_format'], $args['prev_text'], $args['next_format'], $args['next_text'], $args['in_same_term'], $args['excluded_terms'], $args['taxonomy']); // Bail if required args have been removed via a filter. if (!$required) { return false; } $links = ''; // Previous post link. Can be filtered via WP Core's previous_post_link filter. $links .= get_adjacent_post_link($args['prev_format'], $args['prev_text'], $args['in_same_term'], $args['excluded_terms'], true, $args['taxonomy']); // Next post link. Can be filtered via WP Core's next_post_link filter. $links .= get_adjacent_post_link($args['next_format'], $args['next_text'], $args['in_same_term'], $args['excluded_terms'], false, $args['taxonomy']); // Bail if we don't have any posts to link to. if (empty($links)) { return false; } return sprintf('<nav %s>%s</nav><!-- .nav-single -->', carelib_get_attr('nav', 'single'), $links); }
/** * Helper function to build a next and previous post navigation element on * single entries. This takes care of all the annoying formatting which usually * would need to be done within a template. * * I originally wanted to use the new get_the_post_navigation tag for this; * however, it's lacking a lot of the flexibility provided by using the old * template tags directly. Until WordPress core gets its act together, I guess * I'll just have to duplicate code for no good reason. * * @since 1.3.0 * @access public * @param $args array * @return string */ function flagship_get_post_navigation($args = array()) { $obj = get_post_type_object(get_post_type()); $name = isset($obj->labels->singular_name) ? ' ' . $obj->labels->singular_name : ''; $defaults = apply_filters('flagship_get_post_navigation_defaults', array('post_types' => array(), 'prev_format' => '<span class="nav-previous">%link</span>', 'next_format' => '<span class="nav-next">%link</span>', 'prev_text' => __('Previous', 'flagship-library') . esc_attr($name), 'next_text' => __('Next', 'flagship-library') . esc_attr($name), 'in_same_term' => false, 'excluded_terms' => '', 'taxonomy' => 'category')); $args = wp_parse_args($args, $defaults); // Bail if we're not on a single entry. All post types are allowed by default. if (!is_singular($args['post_types'])) { return; } $links = ''; // Previous post link. Can be filtered via WP Core's previous_post_link filter. $links .= get_adjacent_post_link($args['prev_format'], $args['prev_text'], $args['in_same_term'], $args['excluded_terms'], true, $args['taxonomy']); // Next post link. Can be filtered via WP Core's next_post_link filter. $links .= get_adjacent_post_link($args['next_format'], $args['next_text'], $args['in_same_term'], $args['excluded_terms'], false, $args['taxonomy']); // Bail if we don't have any posts to link to. if (empty($links)) { return; } $output = ''; $output .= '<nav ' . hybrid_get_attr('nav', 'single') . '>'; $output .= $links; $output .= '</nav><!-- .nav-single -->'; return $output; }
/** * Display adjacent post link. * * Can be either next post link or previous. * * @since 2.5.0 * @uses get_adjacent_post_link() * * @param string $format Link anchor format. * @param string $link Link permalink format. * @param bool $in_same_cat Optional. Whether link should be in a same category. * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. * @param bool $previous Optional, default is true. Whether to display link to previous or next post. * @return string */ function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) { echo get_adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, $previous); }