Beispiel #1
0
/**
 * 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));
    }
}
/**
 * Calculate and return the canonical URL.
 *
 * @since 2.2.0
 *
 * @return string The canonical URL, if one exists.
 */
function genesis_canonical_url()
{
    global $wp_query;
    $canonical = '';
    $paged = intval(get_query_var('paged'));
    $page = intval(get_query_var('page'));
    if (is_front_page()) {
        if ($paged) {
            $canonical = get_pagenum_link($paged);
        } else {
            $canonical = trailingslashit(home_url());
        }
    }
    if (is_singular()) {
        $numpages = substr_count($wp_query->post->post_content, '<!--nextpage-->') + 1;
        if (!($id = $wp_query->get_queried_object_id())) {
            return;
        }
        $cf = genesis_get_custom_field('_genesis_canonical_uri');
        if ($cf) {
            $canonical = $cf;
        } elseif ($numpages > 1 && $page > 1) {
            $canonical = genesis_paged_post_url($page, $id);
        } else {
            $canonical = get_permalink($id);
        }
    }
    if (is_category() || is_tag() || is_tax()) {
        if (!($id = $wp_query->get_queried_object_id())) {
            return;
        }
        $taxonomy = $wp_query->queried_object->taxonomy;
        $canonical = $paged ? get_pagenum_link($paged) : get_term_link((int) $id, $taxonomy);
    }
    if (is_author()) {
        if (!($id = $wp_query->get_queried_object_id())) {
            return;
        }
        $canonical = $paged ? get_pagenum_link($paged) : get_author_posts_url($id);
    }
    if (is_search()) {
        $canonical = get_search_link();
    }
    return apply_filters('genesis_canonical_url', $canonical);
}