Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #604960

    Hi There,
    I’ve been searching for a way to add a shortcode to the Masonry Excerpt. I have found several threads on this but none seem to help me.
    I found the masonry_entries.php file here: wp-content\themes\enfold\config-templatebuilder\avia-shortcodes\masonry_entries.php, and then created a child theme version using this http://kriesi.at/documentation/enfold/add-new-or-replace-advanced-layout-builder-elements-from-child-theme/:

    /* Pull Shortcodes from folder... */
    add_filter('avia_load_shortcodes', 'avia_include_shortcode_template', 15, 1);
    function avia_include_shortcode_template($paths)
    {
    $template_url = get_stylesheet_directory();
    array_unshift($paths, $template_url.'/shortcodes/');
    
    return $paths;
    }

    Then I found several posts that mention changing the code of masonry_entries:
    https://kriesi.at/support/topic/theme-shortcode-in-the-excerpt/

    However my masonry_entries.php file only goes to line 331, and the code snippets that they say to look for don’t exist. I’m using version 3.4.1.

    I have created custom post types, and have listed them in the masonry grid. I have also created custom meta data for each cpt. The title and exerpt are showing, but I would like to pull through some of the custom meta data from the cpt. However the shortcode is only displayed as this: [custom_field field="price" this_post="1" limit="0" after=" Vatu" between=", " /]

    Is there anything I can do? Is the difference between the advice from 2015 and now because of a version change?

    Cheers,
    Wade.

    #605681

    Hi Wade!

    Thank you for using Enfold.

    What specific changes are you trying to implement? The masonry script is now located in the helper-masonry.php file. If you need an immediate and fully customized solution, please contact our partner codeable: http://kriesi.at/contact/customization

    Best regards,
    Ismael

    #606380

    Hi Ismael,
    Thanks for getting back to me. I simply want to be able to display shortcodes within the excerpt of the masonry. At the moment it doesn’t display. The shortcodes aren’t theme specific ones, they are from a plugin that creates custom meta fields.

    Thanks,
    Wade.

    #606397

    I have added in the following line to the helper-masonry.php file.

    Line 406: $this->loop[$key][‘content’] = do_shortcode($entry->post_excerpt);

    With that shortcodes work. However, it only lets me enter in theme shortcodes, and it won’t display custom shortcodes. Is this code only meant to show avia shortcodes, or is it simply a matter of the custom shortcodes plugin not working properly in your opinion?

    #606957

    Hi!

    What is the shortcode and the plugin? Did you add it in the Excerpt module?

    Cheers!
    Ismael

    #607314

    Hi Ismael,
    The plugin is called Get Custom Field Values. I have done more playing around with it, and it seems that I have to manually enter in the post ID to the shortcode or it doesn’t find the data. It does show up when I put the post ID in the shortcode, but that’s not ideal as the client won’t want to manually enter in the post ID each time. I’m assuming that there isn’t anything that you can help with that, so I’ve been playing with a workaround.

    I’ve played with the helper-masonry.php file and have changed the following:

    $this->loop[$key]['content'] = $entry->post_excerpt;

    to this:
    $this->loop[$key]['content'] = $entry->price;

    (price is a custom field I created.) This displays well, but I would like to display other fields here too. Is there any way I can loop through multiple custom fields for the content area? such as price, mileage, doors, fuel_type etc…?

    Thanks Wade.

    • This reply was modified 8 years, 5 months ago by wadetaylornz.
    #607819

    Hey!

    It must be possible, have you contacted the plugin author? Most probably he knows exactly how to guide you to that process.

    Best regards,
    Basilis

    #607948

    Thank for getting back to me Basilis,
    Sorry but it’s an Enfold question I have. I meant how do I loop through multiple fields in the helper-masonry.php? Currently I can get it to display either the excerpt, or any one custom field I want, but I would like to display more than one custom field.

    For example on line 406 of helper-masonry.php, this line calls the excerpt:
    $this->loop[$key]['content'] = $entry->post_excerpt;

    If I change it to this I can call in the field called ‘price’:
    $this->loop[$key][‘content’] = $entry->price;

    I want to basically do the following but can’t get it to work as I can’t figure out how to display multiple fields here:
    $this->loop[$key][‘content’] = $entry->price <br />, fuel_type, mileage, post_excerpt;

    Can anyone help with this?
    Thanks Wade

    #608698

    Hey!

    Ask the plugin author how to properly fetch the data. If the plugin is using the default custom fields, the get_post_meta function should work: https://developer.wordpress.org/reference/functions/get_post_meta/

    $price = get_post_meta( $id, 'price', true );
    $this->loop[$key]['content']		= $price . $entry->post_excerpt;

    Regards,
    Ismael

    #608891

    Ok I think I’ve found the answer for anyone looking to enter custom data into the masonry area.

    Line 293 of the helper-masonry.php file looks like this:
    $items .= "<div class='av-masonry-entry-content entry-content' {$markup}>{$content}</div>";
    I simply added in the custom field that I created before the excerpt: {$your_meta_field}
    $items .= "<div class='av-masonry-entry-content entry-content' {$markup}>{$price}<br />{$content}</div>";

    Then on the line 406 I added in this line (where price is my custom field):
    $this->loop[$key]['price'] = $entry->price;

    Cheers,
    Wade.

    #609314

    Hi Wade,

    Great, glad you found a solutions and thanks for sharing!

    Regards,
    Rikard

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