I have a custom post type and a page like this for displaying the posts inside :
archive-(myCPT).php
I’ve created 2 posts, and one of them is the child.
How can I display just the parent page inside my archive-(myCPT).php
Here is a snippet from archive-(myCPT).php :
<?php
if( have_posts() ){
// normal blog layout
$x = 1;
while ( have_posts() ){
the_post();
get_template_part( 'inc/post-format/content-debate');
// advertising between posts
if($ad_posts_mode != 'none'){
// take into account ad frequency
if (($x % $ad_posts_frequency) == 0){
switch ($ad_posts_mode) {
case 'image':
echo '<div class="'.(($ad_posts_box) ? 'box' : '').' between_posts"><a target="_blank" href="'.of_get_option('ad_posts_image_link').'"><img src="'.of_get_option('ad_posts_image').'"></a></div>';
break;
case 'html':
echo '<div class="'.(($ad_posts_box) ? 'box' : '').' between_posts">'.apply_filters('shortcode_filter',do_shortcode(of_get_option('ad_posts_code'))).'</div>';
break;
}
}
}
$x++;
}
}
When a post (of ony type) is a child, its property
post_parent
is a number with the parentâs post ID. Posts without a parent have a value0
instead. So you can test this value:Another option is a filter on
pre_get_posts
(not tested, just an idea):