- This topic has 11 replies, 4 voices, and was last updated 3 years ago by Elvin.
-
AuthorPosts
-
February 3, 2021 at 9:07 am #1644469sporenborg
After I’ve been trying to figure out how to implement the ACF (advanced custom fields) in my GP environment for some time now without success and going crazy in the process, here are my questions for the pros:
1) Is it correct that I copy the single.php or page.php from the GP theme folder to the GP-child theme folder and give the filename a prefix for example “projects-single.php”?
2) Is it correct that I use my ACF code
<?php the_field( 'project_title' ); ?> <?php the_field( 'project_customer_website' ); ?> <?php the_field( 'project_customer_description' ); ?> <?php $project_picture = get_field( 'project_picture' ); ?> <?php if ( $project_picture ) : ?> <img src="<?php echo esc_url( $project_picture['url'] ); ?>" alt="<?php echo esc_attr( $project_picture['alt'] ); ?>" /> <?php endif; ?>
– as an example – after the code
/** * generate_after_entry_header hook. * * @since 0.1 * * @hooked generate_post_image - 10 */ ………………"
and before the code
/** * generate_after_entry_content hook. …………"
in front of it?
3) Where do I have to tell WordPress that I have now created a new projects-single.php?
4) Where can I select in a new post that I would like to use this projects-single.php template?
There used to be a plugin “ACF Frontend Display”, but unfortunately it is no longer available for download. With this plugin you could easily integrate the ACF into any page.
Many thanks in advance!
February 4, 2021 at 3:48 am #1645330DavidStaffCustomer SupportHi there,
not in the order of your questions but these are the top level steps you require:
1. you need to register your custom post type:
https://developer.wordpress.org/plugins/post-types/registering-custom-post-types/
There are some tools to make that simpler:
https://generatewp.com/post-type/
This sets the parameters of what the CPT can do, the slug for the templates to be used and where its displayed in the Dashboard Menu.
2. Then you require your templates.
Take a copy of your the
single.php
and thecontent-single.php
Rename them so they match the slug of your CPT eg.
project.php
andcontent-project.php
3. In your project.php file you will need to update this line:
https://github.com/tomusborne/generatepress/blob/e030f57d2c26991074a6868265737424dac567d0/single.php#L29 where
single
becomesproject
4. Then you will edit the content-project.php to add your ACF Content etc.
Thats the simple overview of it…..
There are other tools that allow you to do this such as CPT UI or Toolset.
February 20, 2021 at 7:46 am #1665736MarcusVery helpful overview. Thank you David!
February 20, 2021 at 8:51 am #1665783DavidStaffCustomer SupportYou’re welcome !
February 22, 2021 at 3:36 am #1667456sporenborgThank you very much, for your great support, David! Thanks to your clear instructions, I was able to get the ACF running on my Website.
February 22, 2021 at 4:50 am #1667526DavidStaffCustomer SupportAwesome – glad to hear that!
April 19, 2021 at 3:16 am #1739886sporenborgHello David, I have to open the topic again and ask you for advice.
1) Your tutorial worked very well, however, I currently have the problem that the global settings of the customizer are not applied. Can it be because the single.php is now called single-project.php? Do I have to leave out the prefix “single-“?
2) And another question: In my case, I would like to display the logos of the customers on the start page. This currently works only before the generateblocks or after the generateblocks content. Can I include the logos by ID in the middle of the gblocks or in another way?
thanks a lot!
April 19, 2021 at 5:15 am #1739982DavidStaffCustomer Support1. The name of the template should not matter. What customizer setting isn’t applying to the template?
2. Unfortunately not – post templates calls
the_content
function – what they do not do is output stuff withinthe_content
. As you’re using ACF you could simply introduce more custom fields for to split your content into pieces.April 19, 2021 at 6:03 am #1740020sporenborgCurrently nothing is applying to the custom page content. I’m using custom CSS classes. Could that be the problem? Or maybe there’s something I’m not including in the file? Is it possible to add custom options for custom templates in customizer?
April 19, 2021 at 11:43 pm #1741175DavidStaffCustomer SupportIs it possible to see a post using the CPT ?
April 20, 2021 at 1:01 am #1741245sporenborgof course …
April 21, 2021 at 12:18 am #1742710ElvinStaffCustomer SupportHi there,
For #1)
Can you specify which ones are you pertaining to?
If it’s the title text, color, and the other things on the ACF field output:
It won’t apply because you’re using a completely different class compared to the default template the theme uses.
Customizer settings apply its settings through the default class selectors, and since you’ve changed that on your template for the ACF field output, the global customizer settings won’t apply to them.
For #2)
I’m not exactly sure I imagine what you’re trying to do. Can you provide any mockup image of how you want it to appear?
Is the logo dynamically changing depending on the post? (coming from ACF?)
Let us know.
-
AuthorPosts
- You must be logged in to reply to this topic.