Premium support

Please log in to post in these forums. If you didn't create an account when you purchased, please contact us.

Free support

If you haven't purchased GP Premium, support for the free theme can be found on WordPress.org.

[Resolved] Creating pages based on Custom Post Type

Home Forums Support Creating pages based on Custom Post Type

This topic contains 5 replies, has 2 voices, and was last updated by  Tom 3 months, 1 week ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #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 ) ); ?>

    Thanks
    Charles

    #490963

    Tom
    Lead Developer

    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?

    #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?

    Thanks
    Charles

    #491808

    Tom
    Lead Developer
    #492442

    Perfect! Thanks so much.
    Charles

    #492666

    Tom
    Lead Developer
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.