function link_rel_prev_next() { // <link rel="home" title="Home" href="http://url/of/home/page" /> $prev_url = ''; $next_url = ''; if (!is_singular()) { $prev_url = get_previous_posts_page_link(); $next_url = get_next_posts_page_link(); if (!empty($prev_url)) { printf('<link rel="prev" href="%s" />' . "\n", $prev_url); } if (!empty($next_url)) { printf('<link rel="next" href="%s" />' . "\n", $next_url); } } else { global $post; // $up_post = get_post($post->post_parent); // // $prev_post = get_previous_post(); // if ( !empty( $prev_post->ID)) // printf( '<link rel="prev" title="%s" href="%s" />' . "\n", $prev_post->post_title , get_permalink($prev_post->ID) ); // // $next_post = get_next_post(); // if ( !empty($next_post->ID)) // printf( '<link rel="next" title="%s" href="%s" />' . "\n", $prev_post->post_title , get_permalink($next_post->ID) ); safe_link_rel('next', get_post($post->parent)); safe_link_rel('prev', get_previous_post()); safe_link_rel('next', get_next_post()); } }
/** * Display or return the previous posts page link. * * @since 0.71 * * @param bool $echo Optional. Echo or return; * @return string|void The previous posts page link if `$echo = false`. */ function previous_posts($echo = true) { $output = esc_url(get_previous_posts_page_link()); if ($echo) { echo $output; } else { return $output; } }
function previous_posts() { echo clean_url(get_previous_posts_page_link()); }
function wp_head() { if (is_feed()) { return; } if (aioseop_mrt_exclude_this_page()) { return; } static $aioseop_dup_counter = 0; $aioseop_dup_counter++; if ($aioseop_dup_counter > 1) { echo "\n<!-- Debug Warning: All in One SEO Pack Pro meta data was included again from " . current_filter() . " filter. Called {$aioseop_dup_counter} times! -->\n"; return; } if (is_home() && !is_front_page()) { $post = $this->get_blog_page(); } else { $post = $this->get_queried_object(); } global $wp_query; global $aioseop_options; $meta_string = null; $description = ''; if (is_single() || is_page()) { $aiosp_disable = htmlspecialchars(stripslashes(get_post_meta($post->ID, '_aioseop_disable', true))); if ($aiosp_disable) { return; } if (empty($aioseop_options['aiosp_enablecpost'])) { $wp_post_types = get_post_types(array('_builtin' => true)); // don't display meta if SEO isn't enabled on custom post types -- pdb if (!is_singular($wp_post_types) && !is_front_page()) { return; } } else { if (!empty($aioseop_options['aiosp_cpostadvanced'])) { $wp_post_types = $aioseop_options['aiosp_cpostactive']; if (empty($aioseop_options['aiosp_cpostactive'])) { return; } if (!is_singular($wp_post_types) && !is_front_page()) { return; } } } } $force_rewrites = 1; if (isset($aioseop_options['aiosp_force_rewrites'])) { $force_rewrites = $aioseop_options['aiosp_force_rewrites']; } if (!empty($aioseop_options['aiosp_rewrite_titles']) && $force_rewrites) { // make the title rewrite as short as possible if (function_exists('ob_list_handlers')) { $active_handlers = ob_list_handlers(); } else { $active_handlers = array(); } if (sizeof($active_handlers) > 0 && $this->strtolower($active_handlers[sizeof($active_handlers) - 1]) == $this->strtolower('All_in_One_SEO_Pack::output_callback_for_title')) { ob_end_flush(); } else { $this->log("another plugin interfering?"); // if we get here there *could* be trouble with another plugin :( $this->ob_start_detected = true; if (function_exists('ob_list_handlers')) { foreach (ob_list_handlers() as $handler) { $this->log("detected output handler {$handler}"); } } } } echo "\n<!-- All in One SEO Pack {$this->version} by Michael Torbert of Semper Fi Web Design"; if ($this->ob_start_detected) { echo "ob_start_detected "; } echo "[{$this->title_start},{$this->title_end}] "; echo "-->\n"; $is_front_page = is_front_page(); $is_front_page_keywords = $is_front_page && $aioseop_options['aiosp_home_keywords'] && !$this->is_static_posts_page() || $this->is_static_front_page(); $blog_page = $this->get_blog_page($post); if ($is_front_page_keywords) { $keywords = trim($this->internationalize($aioseop_options['aiosp_home_keywords'])); } elseif ($this->is_static_posts_page() && !$aioseop_options['aiosp_dynamic_postspage_keywords']) { // and if option = use page set keywords instead of keywords from recent posts $keywords = stripslashes($this->internationalize(get_post_meta($post->ID, "_aioseop_keywords", true))); } elseif (!empty($blog_page) && !$aioseop_options['aiosp_dynamic_postspage_keywords']) { $keywords = stripslashes($this->internationalize(get_post_meta($blog_page->ID, "_aioseop_keywords", true))); } else { $keywords = $this->get_all_keywords(); } if (is_category() && $this->show_page_description()) { $description = $this->internationalize(category_description()); } elseif (is_tag() && $this->show_page_description()) { $description = $this->internationalize(tag_description()); } elseif (is_tax() && $this->show_page_description()) { $description = $this->internationalize(term_description()); } elseif (is_author() && $this->show_page_description()) { $description = $this->internationalize(get_the_author_meta('description')); } else { if ($is_front_page) { $description = trim(stripslashes($this->internationalize($aioseop_options['aiosp_home_description']))); } else { if (is_single() || is_page() || is_home() || $this->is_static_posts_page()) { $description = $this->get_aioseop_description($post); } } } /* if ( $this->is_static_front_page() ) $description = trim( stripslashes( $this->internationalize( $aioseop_options['aiosp_home_description'] ) ) ); elseif ( !empty( $blog_page ) ) $description = $this->get_post_description( $blog_page ); if ( empty( $description ) && is_object( $post ) && !is_archive() && empty( $blog_page ) ) $description = $this->get_post_description( $post ); $description = apply_filters( 'aioseop_description', $description ); */ if (isset($description) && $this->strlen($description) > $this->minimum_description_length && !($is_front_page && is_paged())) { $description = trim(strip_tags($description)); $description = str_replace('"', '"', $description); // replace newlines on mac / windows? $description = str_replace("\r\n", ' ', $description); // maybe linux uses this alone $description = str_replace("\n", ' ', $description); if (!isset($meta_string)) { $meta_string = ''; } // description format $description_format = $aioseop_options['aiosp_description_format']; if (!isset($description_format) || empty($description_format)) { $description_format = "%description%"; } $description = str_replace('%description%', apply_filters('aioseop_description_override', $description), $description_format); $description = str_replace('%blog_title%', get_bloginfo('name'), $description); $description = str_replace('%blog_description%', get_bloginfo('description'), $description); $description = str_replace('%wp_title%', $this->get_original_title(), $description); if ($aioseop_options['aiosp_can'] && is_attachment()) { $url = $this->aiosp_mrt_get_url($wp_query); if ($url) { $matches = array(); preg_match_all('/(\\d+)/', $url, $matches); if (is_array($matches)) { $uniqueDesc = join('', $matches[0]); } } $description .= ' ' . $uniqueDesc; } $meta_string .= sprintf("<meta name=\"description\" content=\"%s\" />\n", $description); } $keywords = apply_filters('aioseop_keywords', $keywords); if (isset($aioseop_options['aiosp_togglekeywords'])) { $togglekeywords = $aioseop_options['aiosp_togglekeywords']; } else { $togglekeywords = 0; } if (isset($keywords) && $togglekeywords == 0 && !empty($keywords) && !(is_home() && is_paged())) { if (isset($meta_string)) { $meta_string .= "\n"; } $keywords = wp_filter_nohtml_kses(str_replace('"', '', $keywords)); $meta_string .= sprintf("<meta name=\"keywords\" content=\"%s\" />\n", $keywords); } $is_tag = is_tag(); $robots_meta = ''; if (is_category() && !empty($aioseop_options['aiosp_category_noindex']) || !is_category() && is_archive() && !$is_tag && (is_date() && !empty($aioseop_options['aiosp_archive_date_noindex']) || is_author() && !empty($aioseop_options['aiosp_archive_author_noindex'])) || $is_tag && !empty($aioseop_options['aiosp_tags_noindex']) || is_search() && !empty($aioseop_options['aiosp_search_noindex'])) { $robots_meta = 'noindex,follow'; } else { if (is_single() || is_page()) { $post_type = get_post_type(); $aiosp_noindex = htmlspecialchars(stripslashes(get_post_meta($post->ID, '_aioseop_noindex', true))); $aiosp_nofollow = htmlspecialchars(stripslashes(get_post_meta($post->ID, '_aioseop_nofollow', true))); $aiosp_noodp = htmlspecialchars(stripslashes(get_post_meta($post->ID, '_aioseop_noodp', true))); $aiosp_noydir = htmlspecialchars(stripslashes(get_post_meta($post->ID, '_aioseop_noydir', true))); if ($aiosp_noindex || $aiosp_nofollow || $aiosp_noodp || $aiosp_noydir || !empty($aioseop_options['aiosp_cpostnoindex']) || !empty($aioseop_options['aiosp_cpostnofollow'])) { $noindex = "index"; $nofollow = "follow"; $noodp = $noydir = ''; if ($aiosp_noindex == 'on' || $aiosp_noindex == '' && !empty($aioseop_options['aiosp_cpostnoindex']) && in_array($post_type, $aioseop_options['aiosp_cpostnoindex'])) { $noindex = "no" . $noindex; } if ($aiosp_nofollow == 'on' || $aiosp_nofollow == '' && !empty($aioseop_options['aiosp_cpostnofollow']) && in_array($post_type, $aioseop_options['aiosp_cpostnofollow'])) { $nofollow = "no" . $nofollow; } if ($aiosp_noodp) { $nofollow .= ',noodp'; } if ($aiosp_noydir) { $nofollow .= ',noydir'; } $robots_meta = $noindex . ',' . $nofollow; } } } $robots_meta = apply_filters('aioseop_robots_meta', $robots_meta); if (!empty($robots_meta)) { $meta_string .= '<meta name="robots" content="' . esc_attr($robots_meta) . '" />' . "\n"; } if ($is_front_page) { foreach (array('google' => 'google-site-verification', 'bing' => 'msvalidate.01', 'pinterest' => 'p:domain_verify') as $k => $v) { if (!empty($aioseop_options["aiosp_{$k}_verify"])) { $meta_string .= '<meta name="' . $v . '" content="' . trim(strip_tags($aioseop_options["aiosp_{$k}_verify"])) . '" />' . "\n"; } } } foreach (array('page_meta', 'post_meta', 'home_meta', 'front_meta') as $meta) { if (!empty($aioseop_options["aiosp_{$meta}_tags"])) { ${$meta} = html_entity_decode(stripslashes($aioseop_options["aiosp_{$meta}_tags"])); } else { ${$meta} = ''; } } if (is_page() && isset($page_meta) && !empty($page_meta) && (!$is_front_page || empty($front_meta))) { if (isset($meta_string)) { $meta_string .= "\n"; } $meta_string .= $page_meta; } if (is_single() && isset($post_meta) && !empty($post_meta)) { if (isset($meta_string)) { $meta_string .= "\n"; } $meta_string .= $post_meta; } $googleplus = $publisher = $author = ''; if (!empty($post) && isset($post->post_author) && empty($aioseop_options['aiosp_google_disable_profile'])) { $googleplus = get_the_author_meta('googleplus', $post->post_author); } if (empty($googleplus) && !empty($aioseop_options['aiosp_google_publisher'])) { $googleplus = $aioseop_options['aiosp_google_publisher']; } if ($is_front_page && !empty($aioseop_options['aiosp_google_publisher'])) { $publisher = $aioseop_options['aiosp_google_publisher']; } $publisher = apply_filters('aioseop_google_publisher', $publisher); if (!empty($publisher)) { $meta_string = '<link rel="publisher" href="' . esc_url($publisher) . '" />' . "\n" . $meta_string; } if (is_singular() && !empty($googleplus)) { $author = $googleplus; } else { if (!empty($aioseop_options['aiosp_google_publisher'])) { $author = $aioseop_options['aiosp_google_publisher']; } } $author = apply_filters('aioseop_google_author', $author); if (!empty($author)) { $meta_string = '<link rel="author" href="' . esc_url($author) . '" />' . "\n" . $meta_string; } if ($is_front_page && !empty($front_meta)) { if (isset($meta_string)) { $meta_string .= "\n"; } $meta_string .= $front_meta; } else { if (is_home() && !empty($home_meta)) { if (isset($meta_string)) { $meta_string .= "\n"; } $meta_string .= $home_meta; } } $prev = $next = ''; if (is_home() || is_archive() || is_paged()) { global $wp_query; $max_page = $wp_query->max_num_pages; $page = $this->get_page_number(); if ($page > 1) { $prev = get_previous_posts_page_link(); } if ($page < $max_page) { // $next = get_next_posts_page_link( $max_page ); $paged = $GLOBALS['paged']; if (!is_single()) { if (!$paged) { $paged = 1; } $nextpage = intval($paged) + 1; if (!$max_page || $max_page >= $nextpage) { $next = get_pagenum_link($nextpage); } } } } else { if (is_page() || is_single()) { $numpages = 1; $multipage = 0; $page = get_query_var('page'); if (!$page) { $page = 1; } if (is_single() || is_page() || is_feed()) { $more = 1; } $content = $post->post_content; if (false !== strpos($content, '<!--nextpage-->')) { if ($page > 1) { $more = 1; } $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content); $content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content); $content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content); // Ignore nextpage at the beginning of the content. if (0 === strpos($content, '<!--nextpage-->')) { $content = substr($content, 15); } $pages = explode('<!--nextpage-->', $content); $numpages = count($pages); if ($numpages > 1) { $multipage = 1; } } if (!empty($page)) { if ($page > 1) { $prev = _wp_link_page($page - 1); } if ($page + 1 <= $numpages) { $next = _wp_link_page($page + 1); } } if (!empty($prev)) { $prev = $this->substr($prev, 9, -2); } if (!empty($next)) { $next = $this->substr($next, 9, -2); } } } $prev = apply_filters('aioseop_prev_link', $prev); $next = apply_filters('aioseop_next_link', $next); if (!empty($prev)) { $meta_string .= "<link rel='prev' href='" . esc_url($prev) . "' />\n"; } if (!empty($next)) { $meta_string .= "<link rel='next' href='" . esc_url($next) . "' />\n"; } if ($meta_string != null) { echo "{$meta_string}\n"; } if ($aioseop_options['aiosp_can'] && ($url = $this->aiosp_mrt_get_url($wp_query))) { $url = apply_filters('aioseop_canonical_url', $url); if (!empty($url)) { echo '<link rel="canonical" href="' . esc_url($url) . '" />' . "\n"; } } do_action('aioseop_modules_wp_head'); echo "<!-- /all in one seo pack -->\n"; }
/** * @param null $post * * @return array */ function get_prev_next_links($post = null) { $prev = $next = ''; $page = $this->get_page_number(); if (is_home() || is_archive() || is_paged()) { global $wp_query; $max_page = $wp_query->max_num_pages; if ($page > 1) { $prev = get_previous_posts_page_link(); } if ($page < $max_page) { $paged = $GLOBALS['paged']; if (!is_single()) { if (!$paged) { $paged = 1; } $nextpage = intval($paged) + 1; if (!$max_page || $max_page >= $nextpage) { $next = get_pagenum_link($nextpage); } } } } else { if (is_page() || is_single()) { $numpages = 1; $multipage = 0; $page = get_query_var('page'); if (!$page) { $page = 1; } if (is_single() || is_page() || is_feed()) { $more = 1; } $content = $post->post_content; if (false !== strpos($content, '<!--nextpage-->')) { if ($page > 1) { $more = 1; } $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content); $content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content); $content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content); // Ignore nextpage at the beginning of the content. if (0 === strpos($content, '<!--nextpage-->')) { $content = substr($content, 15); } $pages = explode('<!--nextpage-->', $content); $numpages = count($pages); if ($numpages > 1) { $multipage = 1; } } if (!empty($page)) { if ($page > 1) { $prev = _wp_link_page($page - 1); } if ($page + 1 <= $numpages) { $next = _wp_link_page($page + 1); } } if (!empty($prev)) { $prev = $this->substr($prev, 9, -2); } if (!empty($next)) { $next = $this->substr($next, 9, -2); } } } return array('prev' => $prev, 'next' => $next); }
<nav id="nav-below" class="navigation" role="navigation"> <div class="nav-previous"><a href="<?php echo get_previous_posts_page_link(); ?> ">Previous Page</a></div> <div class="nav-next"><a href="<?php echo get_next_posts_page_link(); ?> ">Next Page</a></div> </nav>
/** * Display or return the previous posts pages link. * * @since 0.71 * * @param boolean $echo Optional. Echo or return; */ function previous_posts( $echo = true ) { $output = clean_url( get_previous_posts_page_link() ); if ( $echo ) echo $output; else return $output; }
/** * Output rel links in the head to indicate previous and next pages in paginated archives and posts. * * @link http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html * * @since 2.2.0 */ function genesis_paged_rel() { global $wp_query; $prev = $next = ''; $paged = intval(get_query_var('paged')); $page = intval(get_query_var('page')); if (!is_singular()) { $prev = $paged > 1 ? get_previous_posts_page_link() : $prev; $next = $paged < $wp_query->max_num_pages ? get_next_posts_page_link($wp_query->max_num_pages) : $next; } else { //* No need for this on previews if (is_preview()) { return ''; } $numpages = substr_count($wp_query->post->post_content, '<!--nextpage-->') + 1; if ($numpages && !$page) { $page = 1; } if ($page > 1) { $prev = genesis_paged_post_url($page - 1); } if ($page < $numpages) { $next = genesis_paged_post_url($page + 1); } } if ($prev) { printf('<link rel="prev" href="%s" />' . "\n", esc_url($prev)); } if ($next) { printf('<link rel="next" href="%s" />' . "\n", esc_url($next)); } }
<div class="panel panel--subtle"> <nav class="pagination nav nav--pagination"> <?php // Navigation links. if (get_next_posts_link()) { echo '<a rel="next" href="' . get_next_posts_page_link() . '" class="btn next ss-navigateright">Next</a>'; } if (get_previous_posts_link()) { echo '<a rel="previous" href="' . get_previous_posts_page_link() . '" class="btn prev ss-navigateleft">Previous</a>'; } // Number of pages. echo 'Page ' . ($wp_query->query_vars['paged'] ?: 1) . ' of ' . $wp_query->max_num_pages; ?> </nav> </div><!--/.panel -->
/** * Print numeric pagination */ function numeric_posts_nav($custom_query = null) { if (is_singular() && $custom_query === null) { return; } global $wp_query; if ($custom_query) { $wp_query = $custom_query !== null ? $custom_query : $wp_query; } /** Stop execution if there's only 1 page */ if ($wp_query->max_num_pages <= 1) { return; } $paged = get_query_var('paged') ? absint(get_query_var('paged')) : 1; $max = intval($wp_query->max_num_pages); /** Add current page to the array */ if ($paged >= 1) { $links[] = $paged; } /** Add the pages around the current page to the array */ if ($paged >= 3) { $links[] = $paged - 1; $links[] = $paged - 2; } if ($paged + 2 <= $max) { $links[] = $paged + 2; $links[] = $paged + 1; } echo '<div class="numbered-pagination"><ul class="unstyled inline">' . "\n"; /** Previous Post Link */ if (get_previous_posts_link()) { printf('<li><a href="%s" class="prev">%s</a></li>' . "\n", get_previous_posts_page_link(), print_image('arrow_blue.svg')); } /** Link to first page, plus ellipses if necessary */ if (!in_array(1, $links)) { $class = 1 == $paged ? ' class="active"' : ''; printf('<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url(get_pagenum_link(1)), '1'); if (!in_array(2, $links)) { echo '<li>…</li>'; } } /** Link to current page, plus 2 pages in either direction if necessary */ sort($links); foreach ((array) $links as $link) { $class = $paged == $link ? ' class="active"' : ''; printf('<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url(get_pagenum_link($link)), $link); } /** Link to last page, plus ellipses if necessary */ if (!in_array($max, $links)) { if (!in_array($max - 1, $links)) { echo '<li>…</li>' . "\n"; } $class = $paged == $max ? ' class="active"' : ''; printf('<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url(get_pagenum_link($max)), $max); } /** Next Post Link */ if (get_next_posts_link()) { printf('<li><a href="%s" class="next">%s</a></li>' . "\n", get_next_posts_page_link(), print_image('arrow_blue.svg')); } echo '</ul></div>' . "\n"; }
function previous_posts_link($label = '« Previous Page') { global $paged; $link = ''; if (!is_single() && $paged > 1) { $link .= '<a href="'; $link .= clean_url(get_previous_posts_page_link()); $link .= '">' . preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) . '</a>'; } return $link; }
function ks_previous_posts_link() { if (is_single()) { return; } $defaults = array('anchor' => '<img localsrc="7" alt="« ">' . __('*.Prev', 'ktai_style'), 'accesskey' => '*', 'echo' => true); $r = _ks_parse_arg(func_get_args(), $defaults); if (isset($r['label'])) { $r['anchor'] = $r['label']; } $paged = intval(get_query_var('paged')); $output = ''; if ($paged > 1) { $output = '<a href="' . KtaiStyle::strip_host(clean_url(_ks_quoted_remove_query_arg('kp', get_previous_posts_page_link()))) . '"' . ks_accesskey_html($r['accesskey']) . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $r['anchor']) . '</a>'; } if ($r['echo']) { echo $output; } return $output; }