• Resolved antforshaw

    (@antforshaw)


    Hi,

    I am currently trying to create a custom post layout for my smart filters and have been following the instructions but do not appear to be able to get it to work.

    The instructions mention the required ID, and I have assumed that I am supposed to replace the _ID portion of the filter name with the internal ID of the filter I am targetting:

    /**
     * Creating a custom post template
     * @param {string} layout - HTML markup
     * @param {int} post_id - Post ID
     * @param {int} filter_id - Filter ID
     * @returns {string} HTML markup card post
     */
    function my_custom_post_layout($layout, $post_id, $filter_id) {  
       $layout  = '<h2>'.get_the_title($post_id).'</h2>';
       $layout .= '<p>'.wp_trim_words(get_the_content($post_id), 30).'</p>';
       $layout .= '<a href="'.get_the_permalink($post_id).'">Read More</a>;   
       return $layout;
    }
    add_filter('ymc_post_custom_layout_ID', 'my_custom_post_layout', 10, 3);

    Am I supposed to refactor the add_filter parameter to look something like:

    add_filter('ymc_post_custom_layout_32245', 'my_custom_post_layout', 10, 3);

    OR, do I pass the ID into the custom function call? i.e:

    function my_custom_post_layout($layout, $post_id, "32245")

    Apologies if this appears to be a stupid question, but I just cant get it to work!

    Many thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter antforshaw

    (@antforshaw)

    Sussed it! This one can be closed.. I was trying to use the full ID of the container but just realised I only need to add the numeric part:

    ymc-smart-filter-container-6 would result in my just adding 6 to the param:

    add_filter('ymc_post_custom_layout_6', 'my_custom_post_layout', 10, 3);
    
    Plugin Author YMC

    (@wssoffice21)

    Hi Antforshaw!
    This should be a number that corresponds to the ID of the ID of the container. I’m glad you solved this task. Contact if you have any questions.

    Plugin Author YMC

    (@wssoffice21)

    Hi!

    Please use the new entry to filter to avoid errors. Add 5 parameters instead of 3. Ex: add_filter(‘ymc_post_custom_layout_1’, ‘custom_post_layout_1’, 10, 5);

    See doc.

    • This reply was modified 1 year, 8 months ago by YMC.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Post Cards’ is closed to new replies.