- This topic has 7 replies, 3 voices, and was last updated 4 months ago by
Tom.
-
AuthorPosts
-
October 21, 2020 at 5:29 am #1498244
David
Hello!!
I have been studying the posts about the implementation of advanced custom types and custom fields in Generatepress templates. I don’t know if I have it figured out. Before I start testing in code I would like you to confirm if the following is correct:I have created two ACT: ‘ong’ and ‘causa’ and their custom fields.
As I have read here in the support forum the steps to show the page of each of these ACT are the following:
1º Copy page.php and rename it with the name of each ACT: ong.php and causa.php
2º Move this files to child folder.
3º Copy content-page.php in child folder and rename it with the name of content-ong.php and content-causa.php
4º In the code of ong.php and causa.php replace the line generate_do_template_part(‘page’) with both
get_template_part(‘content’,’ong’);
get_template_part(‘content’,’cause’);If everything is ok I need to know in which files do I have to put the HTML and the values of the custom fields of each ACT to design the custom page?
Thank you very much in advance.October 21, 2020 at 5:48 am #1498269David
StaffCustomer SupportHi there,
question before diving into rebuilding those templates. Have you looked at whether Hooking in the custom fields would be a viable solution?
https://docs.generatepress.com/article/hooks-element-overview/
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 21, 2020 at 12:47 pm #1498888David
Excuse me, it sounds very interesting about the elements but I have looked at it and I think it needs time to learn how to use it.
Can you solve my doubt based on what I have proposed? Later I will dedicate more time to Elements because it seems to be very practical.
Thank you very much.October 22, 2020 at 1:34 am #1499418David
StaffCustomer SupportYour proposed method is correct.
It is to these files that you would make the edits to include your custom fields:
3º Copy content-page.php in child folder and rename it with the name of content-ong.php and content-causa.php
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 24, 2020 at 5:06 am #1502193David
Sorry again, but this is not working. I think that the theme is not getting the new templates of the ong and causa.
Would you take a look please and tell me what I am doing wrong?
Thank you very much!October 24, 2020 at 10:11 am #1502628Tom
Lead DeveloperLead DeveloperI don’t believe you’ve named your post type files correctly.
Post types have two parts – archives and single posts. There are different templates for both, as shown here: https://developer.wordpress.org/themes/template-files-section/custom-post-type-template-files/
So the archive would be named
archive-{post-type}.php
and the single posts would besingle-{post-type}.php
.Then, when you do this:
get_template_part( 'content', 'cause' );
WordPress looks for a file like this:
content-cause.php
to insert into that area.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentOctober 24, 2020 at 12:06 pm #1502726David
Hi Tom, thanks for your answer. So I dont have to copy page.php and rename it to causa.php? simply copy single.php and rename it to single-causa.php? Also with archive.php.
And into the single-causa.php do I have to change anything?
There is a line with: generate_do_template_part(‘single’);
I have changed (‘single’) for (‘causa’) and (‘single’,’causa’ ) and returns nothing. How I said to WordPress that the CPT causa has a different template with its custom fields? because I think that it is loading the main file single.php without the custom fields.
I am very lost with this issue…
Thanks in advance!!October 25, 2020 at 11:47 am #1503798Tom
Lead DeveloperLead DeveloperCorrect. You can replace this:
generate_do_template_part( 'single' );
With this:
get_template_part( 'content', 'causa' );
And that will load your
content-causa.php
file in that location.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.