0

I've been building my very first WordPress theme using the Advanced Custom Fields plugin. Here are the steps I've taken so far:

  1. Created custom post type via functions.php.
  2. Created archive-productions.php and customised the loop.
  3. Created single-productions.php and customised.

Everything is working perfectly!

I'd like to display archive-productions.php on the homepage, so i've created a page template. I've tried everything I can to get it working, but it's coming up blank.

I've spent many hours looking for a solution, but I've really hit a dead end. I always like to find my own solution, but on this occasion I need a push in the right direction. Your tips, links to tutorials or suggestions would be greatly appreciated.

Thank you!

Here's the loop I've tried on the page template:

<!-- Begin loop -->
<?php
   $args = array(
      'post_type' => 'productions_cpt'
      )
   );
?>

<?php $counter =0; ?>

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

<?php
  ++$counter;
  if($counter == 4) {
    $postclass = ' last';
    $counter = 0;
  } else { $postclass = ''; }
?>

<div class="thumb<?php echo $postclass; ?>">
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a>
<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
</div>

<?php endwhile; else: ?>
<p><?php _e('Sorry, no productions matched your criteria.'); ?></p>
<?php endif; ?>
<!-- End loop --> 
5
  • in your wordpress root directory search n open wp-config.php in this file look for define('WP_DEBUG', false); and change it to define('WP_DEBUG', true); now you can see error flashing on the page instead of a blank page Commented Oct 1, 2013 at 18:53
  • can you check the code ... you are not getting the posts after defining the arguments use get_posts() or wp_query to get the posts Commented Oct 1, 2013 at 18:55
  • I feel like such a noob. I just realised I have front-page.php set up with a standard loop. This explains why I wasn't seeing anything when I set a page template for the homepage. Thank you for your help! @wordpresser debug mode is great trick.
    – Sam
    Commented Oct 2, 2013 at 10:20
  • am glad it'd help you Commented Oct 2, 2013 at 11:07
  • Thanks to @MarutiMohanty too! Checked out the codex for get_posts() and wp_query.
    – Sam
    Commented Oct 2, 2013 at 11:09

1 Answer 1

0

Using a page template I inserted this code:

<?php
$args = array( 'post_type' => 'productions', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
    the_title();
    echo '<div class="entry-content">';
    the_content();
    echo '</div>';
endwhile;
?>

Works like a charm. Now I just need to customise the loop so it looks pretty!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.