At the moment I create a new page, set a featured image and link a certain CPT template to show all those CPT's (by using a query) with the featured image on top. However, this is in my opinion the wrong way to do this because each time I create a new CPT I'll have to create a new template. My page types now look like "default, cases, products, clients, ..." which is not the purpose of a template.
I tried using archive-CPT.php which will automatically loop through the correct CPT but the problem is that I can't use a featured image anymore. I could, but I want to change/remove/add the image via Wordpress like I do with pages...
How would I be able to achieve this the right way?
EDIT: archive-clients.php
<?php
while( have_posts() ) : the_post();
$header = get_the_post_thumbnail_url();
$title = get_post_meta(get_the_ID(), 'page_title', true);
$subtitle = get_post_meta(get_the_ID(), 'page_subtitle', true);
?>
<header class="page-header about-header" style="background-image:url(<?php echo $header; ?>)">
<h1 class="page-hero-title"><?php echo $title; ?></h1>
<h2 class="page-hero-subtitle"><?php echo $subtitle; ?></h2>
</header>
<?php
endwhile;
while( have_posts() )
: the_post();
?>
<div class="row clients">
<?php while( have_posts() ) : the_post(); ?>
<h1><php the_title(); ?></h1>
<?php endwhile; ?>
</div>
<?php get_footer(); ?>
archive-CPT.php
(not using it as a template, but generated by WP) then I'm not able to add an featured image. I want to avoid havingCases archive
orProduct archive
in my page templates because nothing else can use this..archive-{post_type}.php
is not generated by WP. The responsibility lies on the Theme. Why don't you share your code?page template
first but have changed it toarchive-client.php
which means I can't reach the page meta anymore..