Support

Account

Home Forums General Issues Adding a custom field to loop-index.php

Solving

Adding a custom field to loop-index.php

  • I am at a total loss with the documentation and hope someone can help me. There are several plugins out there for multiple authors. But I want to display an author and a photographer, that contributed the picture to the post (and not call him author hehe).

    I installed the plugin “AFC” to generate a custom field named “fotograf” (yeah, you guessed that). Since I am no developer I did not understand where I would have to place the code within loop-index.php to show the field (if not void) in a post.

    That’s the code I get that I have to include in <b>loop-index.php</b> I guess? But where?

    <?php $fotograf_checked_values = get_field( ‘fotograf’ ); ?>
    <?php if ( $fotograf_checked_values ) : ?>
    <?php foreach ( $fotograf_checked_values as $fotograf_value ): ?>
    <?php echo esc_html( $fotograf_value ); ?>
    <?php endforeach; ?>
    <?php endif; ?>

    At row 259 the author is mentioned at “echo “<div class=’blog-meta’>”;”, so I figured it should be near that row, right?
    https://prnt.sc/1umfxjx

    I also found “author” mentioned again at row 508
    https://prnt.sc/1umfy59


    Second challenge: where to place (what) code in single.php 🙂

    I tried to figure out what part has been changed in this documentation https://www.advancedcustomfields.com/resources/adding-fields-posts/ to find out what has been placed to show the new custom fields. But again… I am at a complete loss. At what row do I need to add code to show the photographers name (if field is not empty)?

    And do I have to change something here too to use loop-index.php?
    https://prnt.sc/1umfwe5

    I appreciate all the help I can get 🙂
    Thanks very much, Michelle

    PS: not sure if this is the right place as a community discussion post or if I should open a support ticket

  • Is there seriously no one who can help me getting startet after 6 weeks?

  • The issue is that you are asking about where in the code of a specific theme that your would add code to show an ACF field. The answer depends how the existing code in that theme and what template files exist in that theme.

    Answering this requires an understanding of the theme that you are using. The odds of someone here being able to help you in your specific situation is going to be small.

    You would have a better chance of an answer by asking the developers of this theme or even other users of the theme how to show a custom field value in a specific place in the theme.

  • That kinda answers my question I guess. Do I understand it right, that the whole documentation is for wordpress-standard-themes only and I won’t stand a chance to implement an afc without help in a child theme of a non-wordpress-theme.

    Guess I have either to pay the 50$ to be able to ask a question in the community of that template regarding this plug in or find another plugin that doesn’t need developent skills.

  • ACF will work with any theme. The documentation is just general how to, like how to get a field. This can be used in any theme. You have to understand how the theme works and what the theme offers to know where and how to add code. ACf can be used anywhere that the WP functions get_post_meta() and get_option() can be used, which is nearly anywhere.

    Yes, for the most part you want to use a child theme because if you make changes to a theme they will be overwritten when the theme is updated.

    Some themes supply hooks for adding content to different places while others require that you copy a template to the child theme and then edit it.

    I and others can guide you in the use of ACF but will not likely be able to help you with implementation in a specific theme.

    I would suggest that you figure out how the theme works. Instead of trying to output an acf field simple try to add some text where you want it to appear, for example

    
    echo 'this is a test';
    

    once you have your test text appearing where and how you want it on the page then you can replace it with the value of a field.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.