function um_rel_canonical_() { if (!is_singular()) { return; } global $ultimatemember, $wp_the_query; if (!($id = $wp_the_query->get_queried_object_id())) { return; } if ($this->core['user'] == $id) { $link = $this->get_current_url(); echo "<link rel='canonical' href='{$link}' />\n"; return; } $link = get_permalink($id); if ($page = get_query_var('cpage')) { $link = get_comments_pagenum_link($page); } echo "<link rel='canonical' href='{$link}' />\n"; }
function canURL_rel_canonical() { if (!is_singular()) { return; } global $wp_the_query; if (!($id = $wp_the_query->get_queried_object_id())) { return; } $canonical = get_post_meta($id, 'canonical_URL', TRUE); if ($canonical) { echo "<link rel='canonical' href='{$canonical}' />\n"; return; } $link = get_permalink($id); if ($page = get_query_var('cpage')) { $link = get_comments_pagenum_link($page); } echo "<link rel='canonical' href='{$link}' />\n"; }
$current = $page; $max = 3; $end = $pages; $range = $current + $max < $end ? range($current, $current + $max) : range($current - ($current + $max - $end), $end); $output[] = '<div class="uk-grid tm-grid-block"><div class="uk-width-1-1"><div class="uk-panel uk-panel-space"><ul class="uk-pagination">'; $range_start = max($page - $max, 1); $range_end = min($page + $max - 1, $pages); if ($page > 1) { $link = $type === 'posts' ? get_pagenum_link($page - 1) : get_comments_pagenum_link($page - 1); $output[] = '<li><a href="' . $link . '"><i class="uk-icon-angle-double-left"></i></a></li>'; } for ($i = 1; $i <= $end; $i++) { if ($i == 1 || $i == $end || in_array($i, $range)) { if ($i == $page) { $output[] = '<li class="uk-active"><span>' . $i . '</span></li>'; } else { $link = $type === 'posts' ? get_pagenum_link($i) : get_comments_pagenum_link($i); $output[] = '<li><a href="' . $link . '">' . $i . '</a></li>'; } } else { $output[] = '#'; } } if ($page < $pages) { $link = $type === 'posts' ? get_pagenum_link($page + 1) : get_comments_pagenum_link($page + 1); $output[] = '<li><a href="' . $link . '"><i class="uk-icon-angle-double-right"></i></a></li>'; } $output[] = '</ul></div></div></div>'; $output = preg_replace('/>#+</', '><li><span>...</span></li><', implode("", $output)); echo $output; }
/** * get the comment pagenavi * * * @param string $class Class name * @param bool $below The position where show. * @return string * @version 1.0.0 * */ public static function get_comment_pagination(array $args = []) { global $post; /** * post comment status */ static $page_comments = null, $cpp = null, $thread_comments = null, $max_pages = null; if ($page_comments === null) { $page_comments = theme_cache::get_option('page_comments'); } /** if comment is closed, return */ if (!$page_comments) { return false; } /** * comments per page */ if (!$cpp === null) { $cpp = theme_cache::get_option('comments_per_page'); } /** * thread_comments */ if ($thread_comments === null) { $thread_comments = get_option('thread_comments'); } if ($max_pages === null) { $max_pages = get_comment_pages_count(null, get_option('comments_per_page'), theme_cache::get_option('thread_comments')); } /** * defaults args */ $defaults = ['classes' => 'comment-pagination', 'cpaged' => max(1, get_query_var('cpage')), 'cpp' => $cpp, 'thread_comments' => $thread_comments ? true : false, 'default_comments_page' => 'oldest', 'max_pages' => $max_pages]; $r = array_merge($defaults, $args); extract($r, EXTR_SKIP); /** If has page to show me */ if ($max_pages > 1) { $big = 999; $args = array('base' => str_replace($big, '%#%', get_comments_pagenum_link($big)), 'total' => $max_pages, 'current' => $cpaged, 'echo' => false, 'prev_text' => '<i class="fa fa-angle-left"></i>', 'next_text' => '<i class="fa fa-angle-right"></i>'); $comments_page_links = paginate_links($args); /** * add data-* attribute */ $comments_page_links = str_replace(' href=', ' data-post-id="' . $post->ID . '" data-cpage="' . $cpaged . '" href=', $comments_page_links); return '<div class="' . $classes . '">' . $comments_page_links . '</div>'; } }
function get_previous_comments_link($label = '') { return '<a href="' . esc_url(get_comments_pagenum_link($prevpage)) . '" ' . apply_filters('previous_comments_link_attributes', '') . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) . '</a>'; }
/** * Get the URL to a certain page. * * @param int $page_number The page number. * @param string $old_url Optional. The URL to add the page number to. * @return string $url The URL to the page number. */ public function get_page_url($page_number, $old_url = '') { return get_comments_pagenum_link($page_number + 1); }
/** * Return the previous comments page link. * * @since 2.7.1 * * @param string $label Optional. Label for comments link text. * @return string|null */ function get_previous_comments_link($label = '') { if (!is_singular() || !get_option('page_comments')) { return; } $page = get_query_var('cpage'); if (intval($page) <= 1) { return; } $prevpage = intval($page) - 1; if (empty($label)) { $label = __('« Older Comments'); } return '<a href="' . esc_url(get_comments_pagenum_link($prevpage)) . '" ' . apply_filters('previous_comments_link_attributes', '') . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) . '</a>'; }
/** * Output rel=canonical for singular queries. * * @since 2.9.0 */ function rel_canonical() { if (!is_singular()) { return; } if (!($id = get_queried_object_id())) { return; } $url = get_permalink($id); $page = get_query_var('page'); if ($page) { $url = trailingslashit($url) . user_trailingslashit($page, 'single_paged'); } $cpage = get_query_var('cpage'); if ($cpage) { $url = get_comments_pagenum_link($cpage); } echo '<link rel="canonical" href="' . esc_url($url) . "\" />\n"; }
/** * This is a function for generating canonical tag * @author Howard R <*****@*****.**> * @static * @global object $wp_the_query WordPress Query object * @return void */ public static function generate_canonical() { /** Original WordPress code **/ if (!is_singular()) { return; } global $wp_the_query; if (!($id = $wp_the_query->get_queried_object_id())) { return; } /** WPL canonical **/ if (self::$canonical) { echo PHP_EOL; echo '<link rel="canonical" href="' . self::$canonical . '" />'; return; } /** Original WordPress code **/ $link = get_permalink($id); if ($page = get_query_var('cpage')) { $link = get_comments_pagenum_link($page); } echo PHP_EOL; echo '<link rel="canonical" href="' . $link . '" />'; }
function wp_commentnavi($before = '', $after = '') { global $wp_query; $comments_per_page = intval(get_query_var('comments_per_page')); $paged = intval(get_query_var('cpage')); $commentnavi_options = get_option('commentnavi_options'); $numcomments = intval($wp_query->comment_count); $max_page = intval($wp_query->max_num_comment_pages); if (empty($paged) || $paged == 0) { $paged = 1; } $pages_to_show = intval($commentnavi_options['num_pages']); $pages_to_show_minus_1 = $pages_to_show - 1; $half_page_start = floor($pages_to_show_minus_1 / 2); $half_page_end = ceil($pages_to_show_minus_1 / 2); $start_page = $paged - $half_page_start; if ($start_page <= 0) { $start_page = 1; } $end_page = $paged + $half_page_end; if ($end_page - $start_page != $pages_to_show_minus_1) { $end_page = $start_page + $pages_to_show_minus_1; } if ($end_page > $max_page) { $start_page = $max_page - $pages_to_show_minus_1; $end_page = $max_page; } if ($start_page <= 0) { $start_page = 1; } if ($max_page > 1 || intval($commentnavi_options['always_show']) == 1) { $pages_text = str_replace("%CURRENT_PAGE%", number_format_i18n($paged), $commentnavi_options['pages_text']); $pages_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pages_text); echo $before . '<div class="wp-commentnavi">' . "\n"; switch (intval($commentnavi_options['style'])) { case 1: if (!empty($pages_text)) { echo '<span class="pages">' . $pages_text . '</span>'; } if ($start_page >= 2 && $pages_to_show < $max_page) { $first_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $commentnavi_options['first_text']); echo '<a href="' . esc_url(get_comments_pagenum_link()) . '" class="first" title="' . $first_page_text . '">' . $first_page_text . '</a>'; if (!empty($commentnavi_options['dotleft_text'])) { echo '<span class="extend">' . $commentnavi_options['dotleft_text'] . '</span>'; } } previous_comments_link($commentnavi_options['prev_text']); for ($i = $start_page; $i <= $end_page; $i++) { if ($i == $paged) { $current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $commentnavi_options['current_text']); echo '<span class="current">' . $current_page_text . '</span>'; } else { $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $commentnavi_options['page_text']); echo '<a href="' . esc_url(get_comments_pagenum_link($i)) . '" class="page" title="' . $page_text . '">' . $page_text . '</a>'; } } next_comments_link($commentnavi_options['next_text'], $max_page); if ($end_page < $max_page) { if (!empty($commentnavi_options['dotright_text'])) { echo '<span class="extend">' . $commentnavi_options['dotright_text'] . '</span>'; } $last_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $commentnavi_options['last_text']); echo '<a href="' . esc_url(get_comments_pagenum_link($max_page)) . '" class="last" title="' . $last_page_text . '">' . $last_page_text . '</a>'; } break; case 2: echo '<form action="' . admin_url('admin.php?page=' . plugin_basename(__FILE__)) . '" method="get">' . "\n"; echo '<select size="1" onchange="document.location.href = this.options[this.selectedIndex].value;">' . "\n"; for ($i = 1; $i <= $max_page; $i++) { $page_num = $i; if ($page_num == 1) { $page_num = 0; } if ($i == $paged) { $current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $commentnavi_options['current_text']); echo '<option value="' . esc_url(get_comments_pagenum_link($page_num)) . '" selected="selected" class="current">' . $current_page_text . "</option>\n"; } else { $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $commentnavi_options['page_text']); echo '<option value="' . esc_url(get_comments_pagenum_link($page_num)) . '">' . $page_text . "</option>\n"; } } echo "</select>\n"; echo "</form>\n"; break; } echo '</div>' . $after . "\n"; } }
echo $current + $x + 1; ?> </a></li> <?php } } /** * Next Link */ // anchor classes and target $classes = array('copy', 'next'); $params = $get; $params[$key] = $current + 1; if ($current === $pages) { array_push($classes, 'disabled'); } $href = get_comments_pagenum_link($current + 1); ?> <li class="<?php echo implode(' ', $classes); ?> "><a href="<?php echo $href; ?> "><?php echo $next; ?> </a></li> </ul> <?php }
/** * Pagination for various lists * @param string $type * @return html * @source http://yootheme.com (Warp Themes) */ function basey_pagination($type = 'posts') { global $wp_query, $post, $wpdb; if ($type === 'comments' && !get_option('page_comments')) { return; } if (!isset($page) && !isset($pages)) { if ($type === 'posts') { $page = get_query_var('paged'); $posts_per_page = intval(get_query_var('posts_per_page')); $pages = intval(ceil($wp_query->found_posts / $posts_per_page)); } else { $comments = $wpdb->get_var("\n\t\t\t\tSELECT COUNT(*)\n\t\t\t\tFROM {$wpdb->comments}\n\t\t\t\tWHERE comment_approved = '1'\n\t\t\t\tAND comment_parent = '0'\n\t\t\t\tAND comment_post_ID = {$post->ID}"); $page = get_query_var('cpage'); $comments_per_page = get_option('comments_per_page'); $pages = intval(ceil($comments / $comments_per_page)); } $page = !empty($page) ? intval($page) : 1; } $output = array(); if ($pages > 1) { $current = $page; $max = 3; $end = $pages; $range = $current + $max < $end ? range($current, $current + $max) : range($current - ($current + $max - $end), $end); $output[] = '<ul class="uk-pagination">'; $range_start = max($page - $max, 1); $range_end = min($page + $max - 1, $pages); if ($page > 1) { $link = $type === 'posts' ? get_pagenum_link($page - 1) : get_comments_pagenum_link($page - 1); $output[] = '<li><a href="' . $link . '"><i class="uk-icon-angle-double-left"></i></a></li>'; } for ($i = 1; $i <= $end; $i++) { if ($i == 1 || $i == $end || in_array($i, $range)) { if ($i == $page) { $output[] = '<li class="uk-active"><span>' . $i . '</span></li>'; } else { $link = $type === 'posts' ? get_pagenum_link($i) : get_comments_pagenum_link($i); $output[] = '<li><a href="' . $link . '">' . $i . '</a></li>'; } } else { $output[] = '#'; } } if ($page < $pages) { $link = $type === 'posts' ? get_pagenum_link($page + 1) : get_comments_pagenum_link($page + 1); $output[] = '<li><a href="' . $link . '"><i class="uk-icon-angle-double-right"></i></a></li>'; } $output[] = '</ul>'; $output = preg_replace('/>#+</', '><li><span>...</span></li><', implode("", $output)); echo $output; } }
/** * overrides the WP rel_canonical - use the correct canonical tags for virtual pages * */ public function vpt_rel_canonical() { if (!is_singular()) { return; } global $wp_the_query; if (!($id = $wp_the_query->get_queried_object_id())) { return; } if ($this->is_virtual_page() && $id == $this->template->ID) { global $wp_rewrite; $link = $wp_rewrite->get_page_permastruct(); $link = str_replace('%pagename%', get_page_uri($GLOBALS['post']), $link); $link = home_url($link); $revvurl = strrev($this->options['virtualpageurl']); $revlink = strrev($link); if ($revvurl) { // add slash if the custom permalink has slash if ($revvurl[0] == '/' && $revlink[0] != '/') { $link = $link . '/'; } elseif ($revvurl[0] != '/' && $revlink[0] == '/') { $link = substr($link, 0, -1); } } //$link = user_trailingslashit($link, $GLOBALS['post']->post_type); } else { $link = get_permalink($id); } if ($page = get_query_var('cpage')) { $link = get_comments_pagenum_link($page); } echo "<link rel='canonical' href='{$link}' />\n"; }
/** * Return Next Comments Link * * @param TimberPost $post * @param string $label * @param integer $max_page * @global integer $cpage * @return string */ function return_next_comments_link($post, $label = '', $max_page = 0) { global $cpage; if (!is_singular() || !get_option('page_comments')) { return; } $commentsPerPage = (int) get_option('comments_per_page'); $nextpage = intval($cpage) + 1; if (empty($max_page)) { $max_page = get_comment_pages_count($post->comments, $commentsPerPage); } if ($nextpage > $max_page) { return; } if (empty($label)) { $label = __('Newer Comments »'); } /** * Filter the anchor tag attributes for the next comments page link. * * @since 2.7.0 * * @param string $attributes Attributes for the anchor tag. */ return '<a href="' . esc_url(get_comments_pagenum_link($nextpage)) . '" ' . apply_filters('next_comments_link_attributes', '') . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) . '</a>'; }
/** * Returns comments pagination * @author Eric Wennerberg * @since 0.0.4 * @version 0.1.1 * @param array $args * @uses $this->helpers_pagination * @return str comments pagination markup */ function get_the_comments_pagination($args = array()) { $default = array('base' => str_replace(99999, '%#%', esc_url(get_comments_pagenum_link(99999))), 'format' => '?paged=%#%', 'type' => 'array', 'prev_text' => '<', 'next_text' => '>', 'end_size' => 0, 'mid_size' => 2, 'echo' => false, 'current_class' => ''); $opt = array_merge($default, $args); $return = $this->helpers_pagination(paginate_comments_links($opt), $opt['current_class']); return $return; }
/** * Display the previous comments page link. * * @since 2.7.0 * * @param string $label Optional. Label for comments link text. */ function previous_comments_link($label='') { if ( !is_singular() ) return; $page = get_query_var('cpage'); if ( !$page ) $page = 1; if ( $page <= 1 ) return; $prevpage = intval($page) - 1; if ( empty($label) ) $label = __('« Older Comments'); echo '<a href="' . clean_url(get_comments_pagenum_link($prevpage)); $attr = apply_filters( 'previous_comments_link_attributes', '' ); echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>'; }
/** * Returns the canonical URL for a post. * * When the post is the same as the current requested page the function will handle the * pagination arguments too. * * @since 4.6.0 * * @param int|WP_Post $post Optional. Post ID or object. Default is global `$post`. * @return string|false The canonical URL, or false if the post does not exist or has not * been published yet. */ function wp_get_canonical_url($post = null) { $post = get_post($post); if (!$post) { return false; } if ('publish' !== $post->post_status) { return false; } $canonical_url = get_permalink($post); // If a canonical is being generated for the current page, make sure it has pagination if needed. if ($post->ID === get_queried_object_id()) { $page = get_query_var('page', 0); if ($page >= 2) { if ('' == get_option('permalink_structure')) { $canonical_url = add_query_arg('page', $page, $canonical_url); } else { $canonical_url = trailingslashit($canonical_url) . user_trailingslashit($page, 'single_paged'); } } $cpage = get_query_var('cpage', 0); if ($cpage) { $canonical_url = get_comments_pagenum_link($cpage); } } /** * Filters the canonical URL for a post. * * @since 4.6.0 * * @param string $string The post's canonical URL. * @param WP_Post $post Post object. */ return apply_filters('get_canonical_url', $canonical_url, $post); }
function prologue_previous_comments_link($label = '') { $page = get_query_var('cpage'); if (!$page) { $page = 1; } if ($page <= 1) { return; } $prevpage = intval($page) - 1; if (empty($label)) { $label = __('« Older Comments'); } echo '<a href="' . clean_url(get_comments_pagenum_link($prevpage)); $attr = apply_filters('previous_comments_link_attributes', ''); echo "\" {$attr} rel=\"post-{$post->ID} cpage-{$prevpage}\">" . preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) . '</a>'; }
public function rel_canonical() { if (!is_singular()) { return; } global $wp_the_query; if (!($id = $wp_the_query->get_queried_object_id())) { return; } $link = $this->get_pagenum_link(get_query_var('paged'), get_permalink($id)); if ($page = get_query_var('cpage')) { $link = get_comments_pagenum_link($page); } echo '<link rel="canonical" href="' . $link . '" />' . "\n"; }
function mc_canonical() { // original code if (!is_singular()) { return; } global $wp_the_query; if (!($id = $wp_the_query->get_queried_object_id())) { return; } // original code $link = get_permalink($id); if ($page = get_query_var('cpage')) { $link = get_comments_pagenum_link($page); } if (isset($_GET['mc_id'])) { $mc_id = is_numeric($_GET['mc_id']) ? $_GET['mc_id'] : false; $link = add_query_arg('mc_id', $mc_id, $link); } echo "<link rel='canonical' href='{$link}' />\n"; }
/** * Workaround for get_comments_pagenum_link function * * @param integer $post_id * @param integer $pagenum * @param integer $max_page * @return string */ function _get_comments_pagenum_link($post_id, $pagenum = 1, $max_page = 0) { if (isset($GLOBALS['post']) && is_object($GLOBALS['post'])) { $old_post =& $GLOBALS['post']; } else { @($GLOBALS['post'] =& new stdClass()); $old_post = null; } $GLOBALS['post']->ID = $post_id; $link = get_comments_pagenum_link($pagenum, $max_page); if ($old_post) { $GLOBALS['post'] =& $old_post; } return $link; }
function paginate_dropdown($args = array()) { if ($this->type === 'comments' && !get_option('page_comments')) { return; } $before = ''; $after = ''; $empty = ' '; $ellipsis = "<li><span class='gap'>...</span></li>"; $range = 8; $anchor = 1; $gap = 0; $r = wp_parse_args($args, $this->options); extract($r, EXTR_SKIP); if (!isset($page) && !isset($pages)) { global $wp_query; if ($this->type === 'posts') { $page = get_query_var('paged'); $posts_per_page = intval(get_query_var('posts_per_page')); $pages = intval(ceil($wp_query->found_posts / $posts_per_page)); } else { $page = get_query_var('cpage'); $comments_per_page = get_option('comments_per_page'); $pages = get_comment_pages_count(); } $page = !empty($page) ? intval($page) : 1; } $prevlink = $this->type === 'posts' ? esc_url(get_pagenum_link($page - 1)) : get_comments_pagenum_link($page - 1); $nextlink = $this->type === 'posts' ? esc_url(get_pagenum_link($page + 1)) : get_comments_pagenum_link($page + 1); $output = stripslashes($before); if ($pages > 1) { $output .= '<div class="pagination-dropdown"><span>Goto :</span><div class="select-wrap"><i class="angle-downicon- ioa-front-icon"></i><select class="clearfix">'; if ($page > 1 && !empty($previouspage)) { $output .= sprintf('<option value="%s">%s</option>', $prevlink, stripslashes($previouspage)); } $min_links = $range * 2 + 1; $block_min = min($page - $range, $pages - $min_links); $block_high = max($page + $range, $min_links); $left_gap = $block_min - $anchor - $gap > 0 ? true : false; $right_gap = $block_high + $anchor + $gap < $pages ? true : false; if ($left_gap && !$right_gap) { $output .= sprintf('%s%s%s', $this->paginate_loop_dropdown(1, $anchor), $ellipsis, $this->paginate_loop_dropdown($block_min, $pages, $page)); } else { if ($left_gap && $right_gap) { $output .= sprintf('%s%s%s%s%s', $this->paginate_loop_dropdown(1, $anchor), $ellipsis, $this->paginate_loop_dropdown($block_min, $block_high, $page), $ellipsis, $this->paginate_loop_dropdown($pages - $anchor + 1, $pages)); } else { if ($right_gap && !$left_gap) { $output .= sprintf('%s%s%s', $this->paginate_loop_dropdown(1, $block_high, $page), $ellipsis, $this->paginate_loop_dropdown($pages - $anchor + 1, $pages)); } else { $output .= $this->paginate_loop_dropdown(1, $pages, $page); } } } if ($page < $pages && !empty($nextpage)) { $output .= sprintf('<option value="%s" class="next">%s</option>', $nextlink, stripslashes($nextpage)); } $output .= "</select></div></div>"; } $output .= stripslashes($after); if ($pages > 1 || $empty) { echo $output; } }
/** * Helper function for pagination which builds the page links. * * @param int $start * @param int $max * @param int $page * @return string */ public function paginate_loop($start, $max, $page = 0) { $output = ""; for ($i = $start; $i <= $max; $i++) { $p = $this->type === 'posts' ? esc_url(get_pagenum_link($i)) : get_comments_pagenum_link($i); $output .= $page == intval($i) ? "<li><span class='page current'>{$i}</span></li>" : "<li><a href='{$p}' title='{$i}' class='page'>{$i}</a></li>"; } return $output; }
function wpmanga_rel_canonical() { if (!is_singular()) { return; } //Check wpmanga project pages first $link = get_sPermalink(); if (!$link) { global $wp_the_query; if (!($id = $wp_the_query->get_queried_object_id())) { return; } $link = get_permalink($id); if ($page = get_query_var('cpage')) { $link = get_comments_pagenum_link($page); } } echo "<link rel='canonical' href='{$link}' />\n"; }
/** * Output rel=canonical for singular queries. * * @since 2.9.0 * * @global WP_Query $wp_the_query */ function rel_canonical() { if (!is_singular()) { return; } global $wp_the_query; if (!($id = $wp_the_query->get_queried_object_id())) { return; } $link = get_permalink($id); if ($page = get_query_var('cpage')) { $link = get_comments_pagenum_link($page); } echo "<link rel='canonical' href='{$link}' />\n"; }
function hocwp_rel_canonical() { if (!is_singular() || has_action('wp_head', 'rel_canonical')) { return; } global $wp_the_query; if (!($id = $wp_the_query->get_queried_object_id())) { return; } $link = get_permalink($id); if ($page = get_query_var('cpage')) { $link = get_comments_pagenum_link($page); } $link = apply_filters('hocwp_head_rel_canonical', $link, $id); echo "<link rel='canonical' href='{$link}' />\n"; }