This topic contains 5 replies, has 2 voices, and was last updated by Tom 11 months, 2 weeks ago.
February 7, 2018 at 6:53 am #490444
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 ) ); ?>
CharlesFebruary 7, 2018 at 7:58 pm #490963
Tom Lead Developer
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?February 8, 2018 at 12:33 pm #491588
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?
CharlesFebruary 8, 2018 at 8:04 pm #491808
Tom Lead Developer
This topic might be helpful: https://generatepress.com/forums/topic/displaying-posts-navigation-on-cpts/
Let me know 🙂February 9, 2018 at 11:41 am #492442
Perfect! Thanks so much.
CharlesFebruary 9, 2018 at 7:52 pm #492666
You must be logged in to reply to this topic.