Site logo

Archived topic

Creating pages based on Custom Post Type

5 replies · Started by Charles on February 7, 2018

Viewing posts 1–6 of 6

The site I'm working on has a home page of excerpts (like a news site). All of the content is entered in a Custom Post Type in the Dashboard, so each excerpt has to link to the full article on a page based on the Custom Post Type. So I need the page to contain the following:

- Custom Post Type Title (eg. News, Environment, Heritage, etc.)
- The latest article taken from that Custom Post Type (this is working using the more link)
- Excerpts from other articles in that Custom Post Type at the bottom of the page
- Previous and Next links

My questions are:
- Should I use a custom page or post template, or categories.php (which isn't in the parent theme), or archives.php?
- How do I add the Custom Post Type title (is that the same as the Category title)?
- How do I enable and customize the Previous and Next links?
- Can I use the same template for each Custom Post Type or do I need to create a separate template for each one?

I am currently using this code to get each excerpt on the home page, but it's hard coded to the name (in this case "news").

<?php $loop = new WP_Query( array( 'post_type' => 'news', 'posts_per_page' => 1 ) ); ?>

Thanks
Charles

Hi there,

1. Since it's your home page, you can create a new file named front-page.php, which will be used automatically for your home page.

Otherwise, I would go the custom page template route.

2. As long as you're within the loop, you should be able to use the_title() to grab the title of the post.

3. Are they all within their own loops on the home page, or are these separate pages?

Sorry, I should have been more explicit. The home page is done and working. They are all separate loops.

I figured out content-single.php is the full post article content template and $post_type = get_post_type( $post->ID ); will get me the Custom Post Type Name based on the article/post being viewed, for the Page Title - which is what I wanted, not the actual Post title.

Now I just need to know how to implement the previous and next links. I see the code in the content-single.php, but where do you turn it on? And how can I customize it, if say, I want the title of the next and previous post?

Thanks
Charles

Perfect! Thanks so much.
Charles

You're welcome :)

This archived topic is closed to new replies.