-
AuthorPosts
-
March 22, 2015 at 9:02 pm #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?
March 22, 2015 at 9:26 pm #416062Hi!
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_OverviewBest regards,
JosueMarch 22, 2015 at 10:03 pm #416073Hi 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)
picture 1the picture is shown in http://www.ltena.com/?page_id=411 (picture 2)
picure 2Ones 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 3I 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.
March 22, 2015 at 10:13 pm #416080Hi!
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.
March 22, 2015 at 11:41 pm #416138cheers, I have to wait for tomorrow to tesdt it. thanks in advance
March 22, 2015 at 11:45 pm #416141It should, i’ve tested it on my local install.
Regards,
JosueMarch 23, 2015 at 3:57 pm #416422This reply has been marked as private.March 23, 2015 at 8:59 pm #416698Hey!
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!
JosueMarch 23, 2015 at 10:19 pm #416758Hi 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
March 23, 2015 at 10:59 pm #416778Check 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!
JosueMarch 24, 2015 at 12:48 am #416818You 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!!March 24, 2015 at 1:37 am #416839The quotes were copied incorrectly too, that normally happens when you copy the snippet right from the mail notifications.
Regards,
JosueMarch 24, 2015 at 10:30 am #416975Hi 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: fieldcatnrWhat 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’);March 24, 2015 at 10:33 am #416976Hi!
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,
JosueMarch 24, 2015 at 10:37 am #416977djee… 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?
March 24, 2015 at 4:37 pm #417155 -
AuthorPosts
- You must be logged in to reply to this topic.