• [ Moderator note: moved to Fixing WordPress. Please do not use Developing With WordPress for these topics. ]

    I’m using ACF for a WordPress site for the first time. I have a template file that I use across a number of pages – topimage-agency.php – and I need to make a paragraph within it dynamic.
    I’ve created the custom field using wysiwyg editor and selected the main Agency Page.
    Obviously I haven’t set the template up with its own page so I’ve had to select one (Agency). The code is dynamic on the Agency page and all works fine however it doesn’t show/work any differently on any of the Agency sub pages. Is there a way I can make elements of a template dynamic using ACF or any other way?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Are you saying that you have many pages for Agencies, and need them to share a piece of editable content?

    Thread Starter mikewhitehead00

    (@mikewhitehead00)

    @jakept I have one main page and a number of sub pages that all share a template for the top part of the page. There’s just one paragraph as part of the template that needs to be editable content. So, short answer is yes.

    With Advanced Custom Fields you can pass the ID of another page to the_field() function to get the value from that page, rather than the current page:

    <?php the_field( 'my_field', 123 ); ?>
    

    That will output the value for my_field as entered on the page/post with ID 123.

    I typically don’t like doing this, because page IDs can change between installs and it means you can’t change where the value is coming from the back-end. For things like this, I’d suggest adding a field to the Customizer. You can read the docs for the Customize API here.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Using advanced custom field plugin for a template file.’ is closed to new replies.