0

I am very new to WP coding. I am working for a University where each faculty has been allocated a CPT. We would like it so that the CPT archive looks the same as the main site. I have created the archive-post-type.php file but am at a total loss from there. From what I have seen in other questions is that the homepage is key?

I have this

<?php

        // Start the Loop.
        while ( have_posts() ) : the_post();

            /*
             * Include the post format-specific template for the content. If you want to
             * use this in a child theme, then include a file called called content-___.php
             * (where ___ is the post format) and that will be used instead.
             */
            get_template_part( 'content-fbe', get_post_format() );

        endwhile;
        // Previous/next page navigation.
        twentyfourteen_paging_nav();

    else :
        // If no content, include the "No posts found" template.
        get_template_part( 'content', 'none' );

    endif;
?>

Any suggestions would be really appreciated.

1

1 Answer 1

0

Re-name your CPT archive to home.php

Then use pre_get_posts to alter the home page query so only CPT's display

function wpsites_home_page_cpt_filter($query) {
if ( !is_admin() && $query->is_main_query() && is_home() ) {
$query->set('post_type', array( 'your-cpt' ) );
    }
  }

add_action('pre_get_posts','wpsites_home_page_cpt_filter');

Replace your-cpt with the name of your custom post type.

Note: pre_get_posts won't work with the is_front_page() conditional tag.

3
  • Does && is_home() mean the homepage of the site? What's happening now is the CPT is displaying the archive in the homepage. Is that right? As I am trying to create 4 homepage like styles for each custom post type archive page.
    – Ollie
    Aug 18, 2014 at 5:36
  • My question subject should be more Homepage as CPT archive, if that helps...
    – Ollie
    Aug 18, 2014 at 5:44
  • Tested and works. Rename archive-cpt.php to home.php where cpt is the name of your custom post type Aug 18, 2014 at 6:55

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.