Support » Developing with WordPress » Display Custom Post Type on a WordPress Page

  • Resolved ecohostingservices


    I am working on a website about a disused Church and Graveyard that a group of people are going to restore it for events etc. The church has a graveyard and since it was a family run church there are at least 4 Barons buried there so it is of historical interest to the local community and vistors. Ideally, we want to add the graves to the website and who is buried there.

    I have created a Custom Post Type called Graves and I can get it working on the template files. But I’d rather create a normal WordPress Page called Graves and add some relevant written content first and below that, the Custom Post Type called Graves would populate it like an archive page.

    I was thinking that I would need an actual Template file (Template Name: Graves Page Template) that would show up in the Page Attributes and I could select it for that particular page called ‘Graves’ and that would show me all the added graves as well as the written text above.

    In the archive-grave.php template I have added the written content and it does what I want but it is not ideal as only I can change or add to the written content.

    So how can I do it please?

    Kind regards


Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Colin,

    You can just do this with single page template.

    Support you have created page template than following code would go into that :

    // First we need to show content from WordPress editor so use this code:
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    endwhile; else: ?>
    <p>Sorry, no posts matched your criteria.</p>
    <?php endif; ?>

    The above would show you content from editor.

    Now below that you can write code which show your custom post type entries like this :

    $loop = new WP_Query( array( 'post_type' => 'graves', 'posts_per_page' => 10 ) ); 
    while ( $loop->have_posts() ) : $loop->the_post();
    the_title( '<h2 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2>' ); 
        <div class="entry-content">
            <?php the_content(); ?>
    <?php endwhile; ?>

    Above code will print custom post type entries.

    • This reply was modified 6 months, 3 weeks ago by Denish Patel.

    Hi Denish
    Thank you for your help.

    I have the content from the page called ‘Graves’ and underneath the 3 graves I have added so far.

    It just needs styling so that the graves are in a grid format so it is now looking at the theme files to style each one.

    Thanks for your help, I am getting there now.

    Many Thanks


Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display Custom Post Type on a WordPress Page’ is closed to new replies.