Yoast SEO在页面上显示错误页面标题

时间:2016-05-16 12:49:30

标签: php wordpress wordpress-plugin

我们在网站上添加了Yoast SEO,并为页面标题添加了

  %%title%% %%page%% %%sep%% %%sitename%%

但我们共有7页,显示“第5页,共10页”。不知道为什么它在页面标题上显示错误的页码。

这是我们的index.php文件

<?php get_header(); ?>
<div class="page-container">
    <div class="grid-wrap">

        <div class="grid-col col-full bp3-col-one-third display-desk">
            <div class="grid-wrap">
                <div class="grid-col col-full bp2-col-one-half bp3-col-full">
                    <div class="mini-menu">
                        <h3>About Treework</h3>
                        <?php wp_nav_menu (array ('theme_location' => 'about-menu'));?> 
                    </div>
                </div>
                <div class="grid-col col-full bp2-col-one-half bp3-col-full">
                    <?php the_block('Quote'); ?>

                    <?php get_the_block('Quote'); ?>
                </div>
                <div class="grid-col col-full bp2-col-one-half bp3-col-full">
                    <?php $cat_id = 8; //the certain category ID
                            $latest_cat_post = new WP_Query( array('posts_per_page' => 1, 'category__in' => array($cat_id)));
                            if( $latest_cat_post->have_posts() ) : while( $latest_cat_post->have_posts() ) : $latest_cat_post->the_post();  ?>
                        <a href="<?php echo get_permalink(); ?>"><div class="latest-post">

                            <p class="latest-date">Latest - <?php echo get_the_date(); ?></p>
                            <h4><?php the_title(); ?></h4>  

                            <div class="excerpt"><?php the_excerpt(); ?></div>

                            <p class="readmore">Read more <span class="right-arrow"></span></p>
                            <div class="clear"></div>
                        </div></a>
                    <?php endwhile; endif; ?>
                    <?php wp_reset_postdata(); ?>
                    <?php rewind_posts(); ?>
                </div>
            </div>
        </div>

        <div class="grid-col col-full bp3-col-two-thirds">
            <div class="grid-wrap">
                <div class="grid-col col-full">
                    <p id="breadcrumbs">
                        <?php if ( function_exists('yoast_breadcrumb') ) {
                            yoast_breadcrumb('');
                        } ?>
                    </p>
                </div>
                <?php 
                    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                    $cat_id = 8; //the certain category ID
                    $latest_cat_post = new WP_Query( 
                            array('posts_per_page' => 5, 
                                  'order' => 'DESC',
                                  'category__in' => array($cat_id),
                                  'paged' => $paged));

                    if( $latest_cat_post->have_posts() ) : while( $latest_cat_post->have_posts() ) : $latest_cat_post->the_post();  ?>
                <div class="grid-col col-full">
                    <a href="<?php echo get_permalink(); ?>"><div class="latest-post">
                        <p class="latest-date"><?php echo get_the_date(); ?></p>
                        <h2><?php  the_title(); ?></h2> 

                        <div class="excerpt"><?php the_excerpt(); ?></div>

                        <p class="readmore">Read more <span class="right-arrow"></span></p>
                        <div class="clear"></div>
                    </div></a>
                </div>
                <?php endwhile; endif; ?>
                <?php
                    $temp = $wp_query; // since wpbeginner_numeric_posts_nav works with the global $wp_query, temporarily replace it with the current query
                    $wp_query = $latest_cat_post;
                    wpbeginner_numeric_posts_nav(); 
                    $wp_query = $temp;
                ?>
                <?php wp_reset_postdata(); ?>
                <?php rewind_posts(); ?>
            </div>
        </div>


        <div class="grid-col col-full bp3-col-one-third display-mob">
            <div class="grid-wrap">
                <div class="grid-col col-full bp2-col-one-half bp3-col-full">
                    <div class="mini-menu">
                        <h3>About Treework</h3>
                        <?php wp_nav_menu (array ('theme_location' => 'about-menu'));?> 
                    </div>
                </div>
                <div class="grid-col col-full bp2-col-one-half bp3-col-full">
                    <?php the_block('Quote'); ?>

                    <?php get_the_block('Quote'); ?>
                </div>
                <div class="grid-col col-full bp2-col-one-half bp3-col-full">
                    <?php $cat_id = 8; //the certain category ID
                            $latest_cat_post = new WP_Query( array('posts_per_page' => 1, 'category__in' => array($cat_id)));
                            if( $latest_cat_post->have_posts() ) : while( $latest_cat_post->have_posts() ) : $latest_cat_post->the_post();  ?>
                        <a href="<?php echo get_permalink(); ?>"><div class="latest-post">
                            <p class="latest-date">Latest - <?php echo get_the_date(); ?></p>
                            <h4><?php the_title(); ?></h4>  

                            <div class="excerpt"><?php the_excerpt(); ?></div>

                            <p class="readmore">Read more <span class="right-arrow"></span></p>
                            <div class="clear"></div>
                        </div></a>
                    <?php endwhile; endif; ?>
                            <?php wp_reset_postdata(); ?>
                            <?php rewind_posts(); ?>
                </div>
            </div>
        </div>


    </div>
</div>


  <?php get_footer(); ?>

并且对于分页我们正在使用此功能

  function wpbeginner_numeric_posts_nav() {

if( is_singular() )
    return;

global $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="navigation"><ul>' . "\n";

/** Previous Post Link */
if ( get_previous_posts_link() )
    printf( '<li>%s</li>' . "\n", get_previous_posts_link() );

/** 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>%s</li>' . "\n", get_next_posts_link() );

echo '</ul></div>' . "\n";

}

0 个答案:

没有答案