Site logo

Archived topic

Applying blog archive and single post settings to custom type post

5 replies · Started by Dominik Mukrecki on May 17, 2019

Viewing posts 1–6 of 6

Hi!

I would like to ask you how can I adapt appearance of custom post archive and single custom post? Changing settings via Customizer won't affect this. I use GP child theme.

I prepared some files:

single-(here goes CPT name).php
archive-(here goes CPT name).php
content-(here goes CPT name).php

EDIT: by a CPT I mean "Custom Post Type".

First of all I put them into main directory for a GP child theme. For example I would like to add comments link for CPT archive. The same as for blog archive. Is there any solution for example using functions.php? Or should I modify files listed above? In which way?

I achieve something using basic PHP, but if there is more sophisticated solution I will be grateful :)

Thanks a lot for amazing work! It seems like GP is a killer choice for all my amateur WordPress projects.

Regards,
Dominik

Hi there,

Are you only wanting to add the comments link (like regular posts) to your CPT posts? If so, that should be pretty easy to achieve without using template files.

For example:

1. Create a new Hook Element: https://docs.generatepress.com/article/hooks-element-overview/
2. Set the hook to after_content
3. Check the Execute PHP checkbox
4. Add the comments link function to the hook content:

<span class="comments-link">
    <?php comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) ); ?>
</span>

Then set the Display Rules to your CPT archive/posts.

Amazing!

It worked immediately. I found that snippet in the theme files recently, but I didn't know how to add it. It is so simple :)

Thank you a lot, I'll let you know if something new is needed to improve on my site.

Regards,
Dominic

Awesome! Glad I could help :)

Hi, I've followed your instructions but I can't get it to work. Since this is a year old post, is something changed due to newer versions of GP?

Thanks,
Igor

Hi there,

nothing has changed in GP that would affect that code from working.
Raise a new topic and explain the issue and share a link to your site and we can have a look.

This archived topic is closed to new replies.