• Resolved kbnetwork

    (@kbnetwork)


    Hi

    I need insert PHP code into menu item template…

    my code:

    <div style=”margin: 5px 20px 5px 0px ; width: 450px!important; height: auto!important; border-bottom: #c6c6c6 1px dotted;” class=”fl-menu-item” id=”fl-menu-item-[menu_item_id]-[menu_item_instance]”>
    <h4>[menu_item_title]
    <div class=”fl-menu-item-meta”>
    [menu_item_tags]
    <img src=”[menu_item_tag_icon_url]” alt=”[menu_item_tag_description]” />
    [/menu_item_tags]
    <span class=”fl-menu-item-price”>[menu_item_price]</span>
    <span class=”fl-currency-sign”>[currency_sign]</span>
    </div></h4>
    <div class=”fl-excerpt”>
    [menu_item_thumbnail]
    [menu_item_excerpt]
    <div>

    <?php
    $energia=[menu_item_energetic];
    $weglowodany=[menu_item_weglowodany];
    $bialko=[menu_item_bialko];
    $tluszcze=[menu_item_tluszcze];

    if(isset($energia, $weglowodany, $bialko, $tluszcze)){

    echo ‘<table style=”position: relative;top: 5px;margin-bottom:10px ;border: 1px solid #ccc; ” border=”1″ width=”450px” cellspacing=”0″ cellpadding=”0″>’;
    echo ‘<tr>’;
    echo ‘<td class=”fl-menu-item-tabs” width=”25%” style=”background: green;text-align: center”>Energia</td>’;
    echo ‘<td class=”fl-menu-item-tabs” width=”25%” style=”background: green;text-align: center”>Białko</td>’;
    echo ‘<td class=”fl-menu-item-tabs” width=”25%” style=”background: green;text-align: center”>Węglowodany</td>’;
    echo ‘<td class=”fl-menu-item-tabs” width=”25%” style=”background: green;text-align: center”>Tłuszcze</td>’;
    echo ‘</tr>’;
    echo ‘<tr>’;
    echo ‘<td class=”fl-menu-item-data”>[menu_item_energetic]</td>’;
    echo ‘<td class=”fl-menu-item-data”>[menu_item_bialko]</td>’;
    echo ‘<td class=”fl-menu-item-data”>[menu_item_weglowodany]</td>’;
    echo ‘<td class=”fl-menu-item-data”>[menu_item_tluszcze]</td>’;
    echo ‘</tr>’;
    echo ‘</table>’;
    }
    ?>
    </div>
    </div>
    <div class=”clear”></div>
    </div>

    any idea?

    https://wordpress.org/plugins/foodlist/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Denis V (Artprima)

    (@v-media)

    Direct php code in the template will never be officially supported due to security and template/business logic separation reasons.

    But you may create your own shortcode. Your shortcode class should extend Artprima\Text\Shortcode. To register a menu level shortcode do the following:

    YourCustomShortcode.php

    namespace YourCustomNamespace;
    
    use Artprima\Text\Shortcode;
    use Foodlist\Project\WordPress\Plugin\Foodlist\Manager;
    
    class YourCustomShortcode extends Shortcode
    {
        public function getTag()
        {
            return "your_custom_shortcode";
        }
    
        public function apply($attrs, $content = null)
        {
            /* ... your custom logic ... */
    
            return $yourCustomShortcodeOutput;
        }
    }

    functions.php

    require_once "YourCustomShortcode.php";
    add_action('foodlist_register_menu_shortcode', function($manager) {
        $manager->registerShortcode(new \YourCustomNamespace\YourCustomShortcode());
    });

    Similarly you can use
    foodlist_register_menuitem_shortcode
    foodlist_register_menusection_shortcode
    (these two due to the bug I found are currently not working, but will work after I release a bugfix, probably today).
    UPDATE: I already fixed this in Foodlist 1.9.

    Plugin Author Denis V (Artprima)

    (@v-media)

    BTW, please note that block elements (e.g. div) are not allowed in h4. (this is not related to the plugin itself, but still)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP code in menu item template’ is closed to new replies.