lundi 16 mai 2016

Yoast SEO showing wrong page title on page

We added Yoast SEO in our website and added this for page title

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

But we have total 7 pages and its showing "page 5 of 10". Dont know why its showing wrong page numbers on page title.

Here is our index.php file

<?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(); ?>

and for pagination we are using this function

  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";

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire