Home › Forums › Front-end Issues › Trying to modify template file…
Hi there,
I have added some ACF fields to a custom post type that’s a part of the theme I’m using (a portfolio layout). But the way the template has written the grid display, I’m having a difficult time adding these custom fields.
Here’s the code from the functions.php file I’m trying to modify:
if (!function_exists('mo_get_thumbnail')) {
/** IMP: Make sure you disable caching on get_the_image front by sending cache = false. */
function mo_get_thumbnail($args) {
global $mo_theme;
$context = $mo_theme->get_context('loop');
$defaults = array('format' => 'array',
'size' => 'full',
'image_scan' => false,
'youtube_scan' => false,
'wrapper' => true,
'show_image_info' => false,
'before_html' => '',
'after_html' => '',
'image_class' => 'thumbnail',
'image_alt' => '',
'image_title' => '',
'meta_key' => array(),
'style_size' => false,
'the_post_thumbnail' => true, // Keep this true to enable featured posts
'force_aqua_resizer' => true,
'taxonamy' => 'category',
'cache' => false, // WordPress handles image caching for you.
);
$args = wp_parse_args($args, $defaults);
/* Extract the array to allow easy use of variables. */
extract($args);
$output = '';
//image_size can be an array with height and width key value pairs or a string
if (is_string($image_size)) {
$image_size = mo_get_image_size_array($image_size);
$args['force_aqua_resizer'] = false; // we have the wp sizes taken care of
}
$args['height'] = $image_size['height'];
$args['width'] = $image_size['width'];
$thumbnail_urls = mo_get_thumbnail_urls($args);
//create the thumbnail
if (!empty($thumbnail_urls)) {
$thumbnail_src = $thumbnail_urls[0];
$thumbnail_element = $thumbnail_urls[1];
$post_id = get_the_ID();
$post_title = get_the_title($post_id);
$post_link = get_permalink($post_id);
if (empty($before_html)) {
$before_html = '<a title="' . $post_title . '" href="' . $post_link . ' ">';
$after_html = '</a>' . $after_html;
}
if ($wrapper) {
$wrapper_html = '<div class="image-area">';
$before_html = $wrapper_html . $before_html;
if (mo_show_image_info($context) || $show_image_info) {
$image_info = '';
$image_info .= '<div class="image-info">';
$image_info .= '<h3 class="post-title"><a title="' . $post_title . '" href="' . $post_link . ' ">' . $post_title . '</a></h3>';
$image_info .= '<h4> . $caption . </h4>';
$image_info .= mo_get_taxonamy_info($taxonamy);
$image_info .= '<div class="image-info-buttons">';
$rel_attribute = 'rel="prettyPhoto[' . $context . ']" ';
// point me to the source of the image for lightbox preview
$image_info .= '<a class="lightbox-link" ' . $rel_attribute . 'title="' . $post_title . '" href="' . $thumbnail_src . ' "><span>Preview</span></a>';
$image_info .= '</div>';
$image_info .= '<div class="image-info-tech">';
$image_info .= '<span style="font-family: FontAwesome;"><?php tech("symbol"); ?></span>';
$image_info .= '</div>';
$image_info .= '</div>';
$after_html .= $image_info;
}
$after_html .= '</div>'; // end of image-area
}
$output = $before_html;
$output .= $thumbnail_element;
$output .= $after_html;
}
return $output;
}
}
You can see where I’ve tried to simply add the <h4> field ‘Caption’ that I’d created. This just isn’t working. And when I try to use the php code from the documentation here it causes errors in the script.
Additionally I’m wanting to display items from a repeater field added to the custom post type. I’m just at a loss.
Thanks in advance.
Not sure if you’re still looking for help here.
Anywhere that you can use get_the_title($post_id);
and get_permalink($post_id);
, you should be able to use get_field('field_name', $post_id);
You should be able to get your fields from the post right below where the author of the theme gets the post title and permalink. If this doesn’t work the you’ll need to check with the author or the theme or the theme documentation.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.