<?php
/**
* Template Name: Portfolio Archive
* Description: Used as a page template to show page contents, followed by a loop through a CPT archive
*
* Usage:
* if you are using a well-written theme:
* make a copy of the page.php template to keep the default theme template
* and inject the CPT loop into the new template
*
* otherwise:
* use this template as is to start from scratch
*
* Naming:
* because of the Wordpress' Template Hierarchy, each CPT has its own archive
* named: archive-{$post_type}.php, so for 'portfolio' it's archive-portfolio.php
* (reference: https://codex.wordpress.org/images/9/96/wp-template-hierarchy.jpg)
*/
?>
<?php get_header() ?>
<?php
// prepare for the loop
$post_type = 'portfolio';
$query = new WP_Query( "post_type={$post_type}&nopaging=1" );
?>
<?php // run the loop ?>
<?php if ( $query->have_posts() ) : ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<!-- template for each custom post in the archive -->
<!-- example: -->
<a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a>
<?php endwhile; ?>
<?php else: ?>
<!-- template for empty archive -->
<?php endif; ?>
<?php get_footer() ?>