Support » Themes and Templates » Displaying Custom Post Types

  • Resolved artlover578


    Hello all,

    i have created a custom post type with custom taxonomies and custom meta fields, The post type is labelled “project”. I have create a “project-page.php” a single-project.php” and a “archive-project.php”, but i am not sure where to implement the code to display the actual posts. i know that the project-single.php is used to display the project by itself. the project-page.php is used to display the project items together on a static page. but i do not understand the concept of the archive page. could someone please assist me in configuring these page. or a starting point. i Have read the codex but the sample codes will not work.

    thank you.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You don’t actually need a page version to display your Custom Post Types.
    archive-project.php will essentially display the projects.

    Think of how index.php and single.php work for posts.
    Thats how archive-project.php and single-project.php will work for your projects!

    Hope that makes sense!

    Thread Starter artlover578


    Hello Lucymothership,

    Thank you for the immediate response it is much appreciated. The only reason i want to use a page template for the “project” type is because i have a nav item called portfolio which leads to the portfolio page which displays the custom “project” type. How would i call the posts from “project” type otherwise?

    How did you set up your navigation menu? Your nav item “portfolio” shouldn’t lead to a static page, it should lead to a page generated by archive-project.php.

    Thread Starter artlover578


    Hello StephenCottontail,

    I created a static page callled “project-page.php” Then i created a page called portfolio which is in the Nav Menu. and used the “project-page.php” as a template for my portfolio page.

    What is displayed when you click on your “portfolio” nav item?

    Thread Starter artlover578


    at the moment nothing because i have yet to setup up a WP_Query on the page. i was wondering what the best method is to display custom post types. in terms of security and proper codex.

    You can set up a loop to display your custom post type just like you would set up a normal loop. Check out WP_Query for all the information you need, but you would probably do something like this:

    $new_query_args = array(
        'post_type' => 'project'
    $new_query = new WP_Query( $new_query_args );
    if  ( $new_query->have_posts() ) :
        while ( $new_query->have_posts() ) : $new_query->the_post()
            ... display the post ...
    Thread Starter artlover578


    I assume that the query would go into my static “portfolio-page.php”? i already tried it i am getting a 500 server error, there must be a mistake in the code.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Displaying Custom Post Types’ is closed to new replies.