Viewing 16 posts - 1 through 16 (of 16 total)
  • Author
    Posts
  • #416060

    Hi Everyone,

    Who can tell me which file of the enfold theme is responsible for creating the attachment page when clicking om a picture which is linked to its attachment page?

    #416062

    Hi!

    Enfold doesn’t include an attachment.php file so the single.php is showed, you can override this by creating an attachment.php file in your theme / child theme.

    More info:
    https://codex.wordpress.org/Template_Hierarchy#Visual_Overview

    Best regards,
    Josue

    #416073

    Hi Josue,

    Thanks for the quick reply. But I don’t intent to build an attachment.php. I just need to know where to put the code for ACF (advanced custom fields). In my WP media library I have a picture with default ‘caption’ and ‘description’ and also an extra field ‘titel van het werk’ (see picture 1)

    wordpress media library
    picture 1

    the picture is shown in http://www.ltena.com/?page_id=411 (picture 2)


    picure 2

    Ones you click the picture you are redirected to the attachment page. Which shows the ‘caption’ and ‘description’, but not (yet) the ‘titel van het werk’ as shown in http://www.ltena.com/?attachment_id=1006 as shown on picture 3


    picture 3

    I am trying to figure out where I can put the code. (I know which code to implement thanks to ACF)
    Example: in theme twentyfourteen I can add the code in the image.php, but I don’t know the file in enfold which is responsible for the attachment-page. Any Ideas?

    • This reply was modified 9 years, 9 months ago by alteba.
    #416080

    Hi!

    Try with this in your child theme functions.php:

    function filter_attachment_content($content) {
    	if(is_singular('attachment')){
    		$acf = "ACF_code_here";
    	}
    	return $content.$acf;
    }
    add_filter('the_content', 'filter_attachment_content');

    Cheers!
    Josue

    • This reply was modified 9 years, 9 months ago by Josue.
    #416138

    cheers, I have to wait for tomorrow to tesdt it. thanks in advance

    #416141

    It should, i’ve tested it on my local install.

    Regards,
    Josue

    #416422
    This reply has been marked as private.
    #416698

    Hey!

    The whole content of your child functions.php should be like this:

    <?php
    function filter_attachment_content($content) {
    if(is_singular(‘attachment’)){
    $acf = get_field(‘field_name’);
    }
    return $content.$acf;
    }
    add_filter(‘the_content’, ‘filter_attachment_content’);

    Cheers!
    Josue

    #416758

    Hi Josue,

    Sorry to disappoint you but it didn’t do what it supposed to do.
    I stil don’t see the extra fields in the attachment page.
    The code in the WP quick bar is indeed gone.

    I have no glue what to do!
    I tried your code in the fonctions.php of the enfold child theme.
    I even added ?> behind your code so it closes the <?php
    Or placed the code in the funcions.php of the parent enfold theme (non-child theme)
    but nothing helped.

    Sorry to be such a burden but do you have any ideas left?
    Cheers,

    Bart

    #416778

    Check it now, here’s the code you needed to use:

    <?php
    function filter_attachment_content($content) {
    if(is_singular('attachment')){
    	$acf = get_field('fieldtitel');
    }
    return $content.$acf;
    }
    add_filter('the_content', 'filter_attachment_content');
    

    Cheers!
    Josue

    #416818

    You are one patient guy. Thank you very much as it is working
    Cheers. Where can I send you the beer?

    don’t tell me it was just the ‘fieldtitel’
    Big thumbs up for you!!

    #416839

    The quotes were copied incorrectly too, that normally happens when you copy the snippet right from the mail notifications.

    Regards,
    Josue

    #416975

    Hi Josue,

    One last question, if I may:
    What if I have multiple fields to display.
    eg.
    I have created a field with field name: fieldtitel
    and another with field name: fieldcatnr

    What would the code then look like?
    Is it correct to state:

    <?php
    function filter_attachment_content($content) {
    if(is_singular(‘attachment’)){
    $acf = get_field(‘fieldtitel,fieldcatnr’);
    }
    return $content.$acf;
    }
    add_filter(‘the_content’, ‘filter_attachment_content’);

    #416976

    Hi!

    Should be like:

    <?php
    function filter_attachment_content($content) {
    if(is_singular('attachment')){
    	$acf = get_field('fieldtitel').'<br>';
    	$acf .= get_field('fieldcatnr');
    }
    return $content.$acf;
    }
    add_filter('the_content', 'filter_attachment_content');

    Regards,
    Josue

    #416977

    djee… you’re quick. it works!! great. thanks a lot again!

    Is this plain PHP? or is there more to learn to write this kind of code?

    #417155

    Hey!

    You should head over to – https://developer.wordpress.org/reference/ :)

    Best regards,
    Yigit

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