Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress From Bootstrap to WordPress Create Bootstrap Styled Theme Templates Creating a Portfolio Landing Page

How can I display more than 10 posts on the portfolio landing page?

Hi

How can I display more than 10 posts on the portfolio page?

My code is

<?php

/*
  Template Name: Full Riders Grid Template
*/

?>

<?php get_header(); ?>

<!-- Jumbotron -->
<div class="jumbotron">
  <div class="container">
    <h1><?php the_title(); ?></h1>
  </div>
</div>

<div class="container">

  <!-- Content -->
  <section>
  <div class="row">
    <div class="col-sm-12 col-md-12">

      <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

        <?php the_content(); ?>

      <?php endwhile; else: ?>

        <div class="pageheader">
          <h1>Oh no!</h1>
        </div>

        <p>No content is appearing for this page</p>

      <?php endif; ?>

    </div>

  </div>

  <div class="row">

    <?php 
      $args = array(
        'post_type' => 'fullrider'
      );
      $the_query = new WP_Query( $args );

    ?>

    <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

    <div class="col-sm-3 fullrider-piece">

      <?php 
        $thumbnail_id = get_post_thumbnail_id(); 
        $thumbnail_url = wp_get_attachment_image_src( $thumbnail_id, 'thumbnail-size', true ); 
      ?>

      <p>
        <a href="<?php the_permalink(); ?>">
          <img src="<?php echo $thumbnail_url[0]; ?>" alt="<?php the_title(); ?>">
          </a>
      </p>
      <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

    </div>

    <?php $fullrider_count = $the_query->current_post + 1; ?>
    <?php if ( $fullrider_count % 4 == 0 ): ?>

    </div>
    <div class="row">

    <?php endif; ?>

    <?php endwhile; endif; ?>

  </div>

  </section>
  <!--/ Content -->

</div>
<!--/ Container -->        

<?php get_footer(); ?>

And the page can be found at http://www.team-mash.co.uk/full-riders/

Thanks David

2 Answers

You can do this using the WP_Query function which can be found here . the code would look something like this

$args = array(
    'post_type' => 'post',
    'post_per_page' => 10
);
$query = new WP_Query( $args );

Hi Kelvin

Thanks for the reply. I've tried the code above but I still see only 10 posts.

I should maybe point out that I'm using the Custom Posts Types and Advanced Custom Fields plugins.

My code is

<?php 
      $args = array(
        'post_type' => 'fullrider',
        'post_per_page' => 10
      );
      $the_query = new WP_Query( $args );

?>

I also changed the 10 to 20 to see if that had an effect but I still only see 10.

Thanks David

yeah l am familiar with those plugins. what are you using the ACF for? what account is it getting. you made the arguments now what you have to do is run a loop after the loop has been runned if you have more than 10 that should work. ohh and take the post_per_page out pf the argument.