查询高级自定义字段;希望对结果进行分页


Querying Advanced Custom Fields; want to paginate the results

不确定这是否专门涉及高级自定义字段,但我会简短地说。我对PHP还比较陌生,想知道处理这项任务的最佳方法此外,这是一个WordPress(4.1.1)环境

我正在发送一个查询,查询所有具有相关类别类型的帖子类型,以便拉入并显示。如果查询可以找到帖子,则会生成<文章>为每个结果添加额外的html。不是很复杂吧?

现在,如果/当查询产生大于8个结果时,我想创建一个分页元素。

环境前端的查询结果可以找到:http://test-hdwg.pantheon.io/news/

用于此页面的模板(news.php)包含以下内容:

<?php /* Template Name: News */ ?>
<?php get_header(); ?>
        <main id="primary" class="content-area">
          <div class="jumbotron">
            <div class="row">
              <div class="intro">
                <p><?php the_field('news_heading') ?></p>
              </div>
            </div>
          </div>
          <div class="news">
            <div class="row news-articles">
              <div class="column-wrapper">
                <div class="small-4 columns news-left-column">
                  <div class="select-dropdown">
                    <button href="#" data-dropdown="dropdown-items" aria-controls="dropdown-items" aria-expanded="false" class="dropdown">Select a news category</button>
                    <ul id="dropdown-items" data-dropdown-content class="f-dropdown" aria-hidden="true" tabindex="-1">
                      <?php $args = array(
                        'exclude'            => '',
                        'title_li'           => __( '' ),
                        'show_option_none'   => __( '<li><a href="#primary">No categories</a></li>' ),
                        'taxonomy'           => 'category',
                        'child_of'           => 2,
                        'current_category'   => 0
                      ); ?>
                      <?php wp_list_categories($args); ?>
                      <li class="cat-item cat-item-all-news"><a href="/news" alt="View all News" title="View all News">All News</a>
                    </ul>
                  </div>
                  <div class="news-block">
                    <span class="news-block-heading">Email Newsletters</span>
                    <div class="news-inner-block">
<?php if( have_rows('newsletters_list') ): ?>
  <?php while( have_rows('newsletters_list') ): the_row(); ?>
                      <span class="year"><?php the_sub_field('newsletter_year'); ?></span>
    <?php if( have_rows('newsletter_resource') ): ?>
                      <ul>
      <?php while( have_rows('newsletter_resource') ): the_row(); ?>
                        <li><a href="<?php the_sub_field('newsletter_url'); ?>" target="_blank"><?php the_sub_field('newsletter_title'); ?></a></li>
      <?php endwhile; ?>
                      </ul>
    <?php endif; ?>
  <?php endwhile; ?>
<?php endif; ?>
                    </div>
                  </div>
                </div>
                <div class="small-8 columns news-right-column">
<?php query_posts( 'post_type=post&cat=' ); ?>
  <?php if ( have_posts() ) : ?>
    <?php while ( have_posts() ) : the_post(); ?>
                  <article class="large-6 columns ui-article-block">
                    <h3><?php echo get_the_date( 'd M Y' ); ?></h3>
                    <hr/>
                    <h2><?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?></h2>
                    <h1><?php the_title(); ?></h1>
                    <p>
      <?php
        $content = get_the_content();
        $content = strip_tags($content);
        echo substr($content, 0, 175) . "..."; // set a character cut-off at 175 characters
      ?>
                    </p>
                    <a href="<?php the_permalink(); ?>" alt="Read more about the article: <?php the_title_attribute(); ?>" title="Read more about the article: <?php the_title_attribute(); ?>" class="button postfix">Read More</a>
                  </article>
    <?php endwhile; ?>
  <?php else : ?>
                  <div class="large-8 columns">
                    <p class="lead">Well this is embarrassing. There are currently no news articles.</p>
                  </div>
  <?php endif; ?>
<?php wp_reset_query(); ?>
                </div>
              </div>
            </div>
          </div>
        </main>
<?php get_footer(); ?>

需要明确的是,这不是一个问题,而是更多经验丰富的开发人员关于如何利用Advanced Custom Field元素处理任务的请求(如果这很重要的话)。

如有任何帮助,我们将不胜感激!

编辑

本次编辑是在OP澄清问题性质后进行的。

这里的教程解释了如何在初学者级别处理帖子中的数字导航。