【问题标题】:Adding A-Z pagination in a custom Wordpress query在自定义 Wordpress 查询中添加 A-Z 分页
【发布时间】:2015-02-18 22:45:51
【问题描述】:

我设法设置了一个页面模板来显示我的自定义帖子类型“书籍”并按自定义字段(作者的第二个姓名)对其进行排序:

<?php 
            // Define custom query parameters
            $custom_query_args = array(  
                'post_type' => 'books',
                'showposts' => 10,
                'meta_key' => 'author_second_name',
                'orderby' => 'meta_value date',
                'order' => 'ASC'
            );

            // Get current page and append to custom query parameters array
            $custom_query_args['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;

            // Instantiate custom query
            $custom_query = new WP_Query( $custom_query_args );

            // Pagination fix
            $temp_query = $wp_query;
            $wp_query   = NULL;
            $wp_query   = $custom_query;

            // Output custom query loop
            if ( $custom_query->have_posts() ) : ?>

在我的存档页面上,我已经成功实现了 A-Z 分页,并尝试使用以下方法在我的作者页面上进行调整:

<?php echo "<a href=http://mywebsite.com/authors/?$query_string&number=true' ># </a> - ";

        foreach (range('A', 'Z') as $i)
        {
         $letter = strtolower($i);
            echo "<a href='mywebsite.com/authors/?$query_string&letter=$letter' >$i </a> - ";
        }
        echo "<a href=http://mywebsite.com/authors/?$query_string' >All </a>"; ?>

不出所料,这似乎不起作用。为了做到这一点,我已经编写了各种代码,并在原则上理解了其中的大部分内容,但在试图让它工作时有点卡住了。

谁能帮忙?

【问题讨论】:

    标签: php wordpress pagination advanced-custom-fields


    【解决方案1】:

    后来我发现了一种更好的方法来查询这里的所有内容:

    http://wordpress.mcdspot.com/2012/04/12/select-posts-on-the-first-letter-of-a-custom-field/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-24
      • 2015-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-10
      相关资源
      最近更新 更多