[Resolved] How to implement ACF (advanced custom fields) to GP/GB

Home Forums Support [Resolved] How to implement ACF (advanced custom fields) to GP/GB

Home Forums Support How to implement ACF (advanced custom fields) to GP/GB

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1644469
    sporenborg

    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!

    #1645330
    David
    Staff
    Customer Support

    Hi 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 the content-single.php

    Rename them so they match the slug of your CPT eg.

    project.php and content-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 becomes project

    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.

    #1665736
    Marcus

    Very helpful overview. Thank you David!

    #1665783
    David
    Staff
    Customer Support
    #1667456
    sporenborg

    Thank you very much, for your great support, David! Thanks to your clear instructions, I was able to get the ACF running on my Website.

    #1667526
    David
    Staff
    Customer Support

    Awesome – glad to hear that!

    #1739886
    sporenborg

    Hello 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!

    #1739982
    David
    Staff
    Customer Support

    1. 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 within the_content. As you’re using ACF you could simply introduce more custom fields for to split your content into pieces.

    #1740020
    sporenborg

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

    #1741175
    David
    Staff
    Customer Support

    Is it possible to see a post using the CPT ?

    #1741245
    sporenborg

    of course …

    #1742710
    Elvin
    Staff
    Customer Support

    Hi 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.

    A wise man once said:
    "Have you cleared your cache?"

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.