Support

Account

Home Forums Front-end Issues Querying ACF fields; want to paginate the results

Solved

Querying ACF fields; want to paginate the results

  • Hi all,
    Not sure if this pertains specifically to ACF, but I’ll keep this short. I’m sending a query for all post types with an associated category type to pull in. If I can find posts, produce an article block for the post type for each result. Not to complicated right? Now, I want to create a pagination element if/when the results produce greater than 8.

    My current (still being developed) environment with the front-end of the query can be found here:
    http://test-hdwg.pantheon.io/news/

    My current template being utilized for this page (news.php) contains the following:

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

    Just to be clear, this is not an issue, but more-so a request from more experience developers on how to approach a task utilizing ACF elements. Any help would be greatly appreciated!

  • Unfortunate, but I found my answer elsewhere.

    For those interested in a similar approached, please see: http://stackoverflow.com/questions/29234517/querying-advanced-custom-fields-want-to-paginate-the-results

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Querying ACF fields; want to paginate the results’ is closed to new replies.