I want to display the custom post type archive of my plugin inside a normal page template. My approach was:
function my_include_template($template) {
global $post;
if ( is_post_type_archive('my_custom_post') ) {
$new_template = locate_template( array( 'page.php' ) );
if ( '' != $new_template ) {
return $new_template ;
}
}
return $template;
}
add_filter('template_include', 'my_include_template', 99);
This way the page.php template will be taken but the get_template_part() function of the template itself will be called for every post within the archive.
But in fact I don't want to do this, I simply want to output a list of all posts inside this archive by using the normal page template: e.g.
- post title 1
- post title 2
- post title 3...
Note: I don't want to create a custom template within my plugin due to the fact that In my opinion I cannnot rely on all the theme authors:
<?php get_header(); ?>
<div class="my-content">
...
</div>
<?php get_footer(); ?>
Because a custom template file like above, could break the layout if the theme has a non standard structure.
So this is the reason why it would be best to output my archive inside a normal page template of the theme itself.
Any suggestion how to handle this?
Update 1
I have to specify: Of course I can replace the content of a user selected "my-archive" page. This will work for the normal custom post archive so far.
My problem is that I additionally have a taxonomy as category for the posts. So my basic slugs look like:
- Single post: /article/postname/
- CPT archive: /articles/
- Category Taxonomy: /articles/category1/
Would be okay to use the same page for both archives, but of course when visiting /articles/category1/ only the posts of this category should be shown and the url should be kept. So I can't simply redirect to the /articles/ page.