douewei1665 2013-11-14 18:19
浏览 78
已采纳

使用post_type('page')的Wordpress分页问题

I am having a great problem with pagination using a custom template(page-location.php). I created a custom loop in that template to query child pages. Everything looks great so far except the pagination's not showing up. I tried both with plugins and wordpress default pagination functions. What am I doing wrong here? Can you please give me a moment and explain why it's not showing up? Thanks in advance! Please have a look at the codes! I tried every solutions out there.. This site is my last hope. ***Please note that post_type = 'page', not POST.

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

    <?php $options = get_option('katerina_custom_settings'); ?>

    <div class="container main-content">

        <h1><?php wp_title(''); ?></h1>

        <div class="row">

        <?php $this_page_id=$wp_query->post->ID; ?>

        <?php 
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $my_query = new WP_Query("post_type=page&post_parent=$this_page_id&posts_per_page=2&paged=$paged");         
                if ($my_query->have_posts() ) : while ($my_query->have_posts()) : $my_query->the_post(); ?>

            <div id="post-<?php the_ID(); ?>" <?php post_class('article span4 clearfix'); ?>>

                <?php if (has_post_thumbnail()) : ?>

                    <figure class="article-preview-image">
                        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
                    </figure>

                <?php endif; ?>

                <article class="content clearfix">
                    <?php if (get_the_title() != '') : ?>
                        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                    <?php else : ?>
                        <a href="<?php the_permalink(); ?>"><?php _e('Permalink to the post', 'adaptive-framework'); ?></a>
                    <?php endif; ?>
                    <?php the_content(); ?>
                    <a href="<?php the_permalink(); ?>" class="button">Details</a>
                </article>

                <div class="meta-data clearfix">
                    <ul class="meta-comments pull-left">
                        <li class="article-meta-comments">
                            <?php
                            // Only show the comments link if comments are allowed and it's not password protected

                                if (comments_open() && !post_password_required()) { 
                                    comments_popup_link('0', '1', '%', 'article-meta-comments');
                                }
                            ?>
                        </li>
                        <li class="article-meta-like"><a href="">10</a></li>
                    </ul>

                    <ul class="social-share pull-right">
                        <li class="fb"><a href="#">Share on Facebooks</a></li>
                        <li class="google"><a href="#">Share via Google</a></li>
                        <li class="twitter"><a href="#">Share via Twitter</a></li>
                    </ul>
                </div>  
            </div>
            <?php endwhile; ?>
        <?php endif; ?>

            <?php wp_reset_postdata(); ?>           
        </div>
        <!-- end row -->

    </div>
        <div class="container">
        <div class="pagination pull-right">
            <?php if(function_exists('tw_pagination')) 
                tw_pagination();
            ?>  
        </div>
    </div>
    <!-- end main-content -->


<?php get_footer(); ?>
  • 写回答

1条回答 默认 最新

  • douliangli6407 2013-11-14 20:22
    关注

    You should try this

    <div class="pagination pull-right">
            <?php if(function_exists('tw_pagination')) 
                tw_pagination($my_query);
            ?>  
        </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch