与数字的分页不工作在wordpress页面模板

时间:2017-02-10 17:10:53

标签: php wordpress pagination

我有这个页面模板,分页只适用于"较旧 - 下一个"风格,但我希望显示为数字,例如" First 1 2 3 ... 5 6 7 Last"。

所以,我尝试了很多我在这里看到的答案,但都没有奏效。任何sugestions?

我的页面模板:

<?php
/* 
 *
 * Template Name: Agenda Template
 * 
 */
get_header(); ?>
<main>

<div class="main-wrapper">
<div class="container content-holder">
    <div class="row">

        <?php $title_position =   get_post_meta($post->ID, 'title-position', true);
             if ( $title_position == 'full-width' ){?>
            <div class="title-holder">
                <h1><?php the_title();?> </h1>
                <?php skin_post_meta(); ?>
            </div>
        <?php }?>

        <div class="content-wrapper col-md-8">

            <?php
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $page_id = get_the_ID();
            ?>

            <ul>
                <?php 
                    $current_date = get_the_time('U');
                    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;

                    $args = array(
                        'post_type'     => 'eventos',
                        'category_name' => 'agenda',
                        'post_status'   => 'publish',
                        'posts_per_page'=> 6,
                        'paged'         => $paged,
                        'orderby'       => '_start_eventtimestamp',
                        'order'         => 'ASC',
                        'meta_query'    => array(
                            array(
                            'key'       => '_start_eventtimestamp',
                            'value'     => $current_date,
                            'compare'   => '>',
                            ),
                        )
                    );

                    $getPosts = new WP_Query($args);
                    while($getPosts->have_posts()) : $getPosts->the_post(); 
                ?>

                <li style="list-style: none;" class="row">

                    <h3><a href="<?php the_permalink(); ?>"><?php the_title();?></a></h3>

                    <div class="col-xs-12 col-sm-3 col-md-3">
                        <?php if ( has_post_thumbnail() ) : ?>
                            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                                <?php the_post_thumbnail('thumbnail', array( 'class' => 'img-responsive img-box img-thumbnail' )); ?>
                            </a>
                        <?php endif; ?> 
                    </div>

                    <div class="col-xs-12 col-sm-9 col-md-9">
                        <div class="list-group">
                            <div class="list-group-item">
                                <div class="row-content">
                                    <div class="list-group-item-heading">
                                        <small>
                                            <div class="col-xs-6 col-sm-6 col-md-6">
                                                <h5>Início: </h5> 
                                                <i class="fa fa-calendar" aria-hidden="true"></i> 
                                                <small>
                                                    <?php $date = get_post_meta($post->ID,'_start_eventtimestamp', true); echo date('d' , $date);?>/ 
                                                    <?php $date = get_post_meta($post->ID,'_start_eventtimestamp', true); echo date('m', $date);?>/ 
                                                    <?php $date = get_post_meta($post->ID,'_start_eventtimestamp', true); echo date('Y' , $date);?>
                                                </small> <br>
                                                <i class="fa fa-clock-o" aria-hidden="true"></i>
                                                <small>
                                                    <?php $hour = get_post_meta($post->ID,'_start_eventtimestamp', true); echo date('H' , $hour);?>:
                                                    <?php $min = get_post_meta($post->ID,'_start_eventtimestamp', true); echo date('i' , $min);?>
                                                </small>
                                            </div>

                                            <div class="col-xs-6 col-sm-6 col-md-6">
                                                <h5>Término: </h5> 
                                                <i class="fa fa-calendar" aria-hidden="true"></i>
                                                <small>
                                                    <?php $date = get_post_meta($post->ID,'_end_eventtimestamp', true); echo date('d' , $date);?>/ 
                                                    <?php $date = get_post_meta($post->ID,'_end_eventtimestamp', true); echo date('m', $date);?>/ 
                                                    <?php $date = get_post_meta($post->ID,'_end_eventtimestamp', true); echo date('Y' , $date);?>
                                                </small> <br>
                                                <i class="fa fa-clock-o" aria-hidden="true"></i>
                                                <small>
                                                    <?php $hour = get_post_meta($post->ID,'_end_eventtimestamp', true); echo date('H' , $hour);?>:
                                                    <?php $min = get_post_meta($post->ID,'_end_eventtimestamp', true); echo date('i' , $min);?>
                                                </small>
                                            </div>

                                            <div class="col-xs-12 col-sm-12 col-md-12">
                                                <small>
                                                <i class="fa fa-map-marker" aria-hidden="true"></i>
                                                <?php 
                                                    $location = get_post_meta($post->ID,'_event_location', true); echo " $location";
                                                    if (empty($location)) {
                                                        echo " Local não definido.";
                                                    }
                                                ?>
                                                </small>
                                            </div>

                                        </small>

                                    </div>
                                </div>
                            </div>
                        </div>                            
                    </div>
                    <div class="row">
                        <div class="col-xs-12 col-sm-12 col-md-12">
                            <small>
                                <p style="text-align: justify;"><?php the_excerpt(); ?></p>
                            </small>
                        </div>
                    </div>

                </li>
                <hr>
                <?php endwhile;?>
            </ul>

            <?php
            $max_num_pages_1 = $max_num_pages->max_num_pages;
            sofg_pagination($max_num_pages_1,$paged,$page_id);
            ?>



            <!-- <?php if ($getPosts->max_num_pages > 1) { // check if the max number of pages is greater than 1  ?>
                <ul class="pager">
                    <li>
                        <?php echo get_next_posts_link( 'Mais Antigos', $getPosts->max_num_pages ); // display older posts link ?> 
                    </li>
                    <li>
                        <?php echo get_previous_posts_link( 'Mais Recentes' ); // display newer posts link ?>
                    </li>
                </ul>

            <?php } ?> -->



        </div><!-- .content-wrapper -->

        <?php get_sidebar(); ?>

    </div><!-- .row -->
</div><!-- .container -->

我尝试的最后一项功能(没有成功)就是:

function sofg_pagination($max_num_pages,$paged,$page_id){
if($max_num_pages > 1){
echo '<div class="post-wrap pgns">';
echo '<ul class="pagination_list">';
echo '<li><a href="'.get_permalink($page_id).'page/1">First</a></li>';
for($i=1; $i<= $max_num_pages; $i++){
    if($paged==$i){ 
        echo '<li class="active"><a href="'.get_permalink($page_id).'page/'.$i.'">'.$i.'</a></li>';
    }
    else{ echo '<li><a href="'.get_permalink($page_id).'page/'.$i.'">'.$i.'</a></li>'; }
}
echo '<li><a href="'.get_permalink($page_id).'page/'.$max_num_pages.'">Last</a></li>';
echo '</ul></div>';
}
} 

2 个答案:

答案 0 :(得分:1)

您可以尝试使用paginate_links,您可以找到文档here

答案 1 :(得分:1)

你可以使用&#34; WP-PageNavi&#34;插件。