Title: [Plugin: Mini Loops] How about inserting PHP code into Item format ?
Last modified: August 20, 2016

---

# [Plugin: Mini Loops] How about inserting PHP code into Item format ?

 *  Resolved [sugardaddy](https://wordpress.org/support/users/sugardaddy/)
 * (@sugardaddy)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-mini-loops-how-about-inserting-php-code-into-item-format/)
 * For anything else, I wouldn’t have to use PHP inside this plugin, but… I need
   to hardcode gettext expressions. And I’m a bit lazy : I don’t want to duplicate
   all my widgets in all langages I need (and use conditionnal tags).
    Is there 
   a way to achieve that ?
 * Thanks for your help !
 * [http://wordpress.org/extend/plugins/mini-loops/](http://wordpress.org/extend/plugins/mini-loops/)

Viewing 11 replies - 1 through 11 (of 11 total)

 *  Thread Starter [sugardaddy](https://wordpress.org/support/users/sugardaddy/)
 * (@sugardaddy)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/plugin-mini-loops-how-about-inserting-php-code-into-item-format/#post-3039755)
 * Well… never any answer for this plugin.
    You should open it on a repository to
   have it upgraded by other people if you don’t have time…
 *  Thread Starter [sugardaddy](https://wordpress.org/support/users/sugardaddy/)
 * (@sugardaddy)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/plugin-mini-loops-how-about-inserting-php-code-into-item-format/#post-3039756)
 * Ok I did otherwise, but it’s no more with GUI… the main interest of mini loops.
   
   To achieve a translation of a mini loop and the strings inside items format, 
   I used [WPML](http://wmpl.org), [Executable PHP widget](http://wordpress.org/extend/plugins/php-code-widget/)
   and the shortcode of mini loop.
 * First of all, you should try your loop with mini loop. In this way, you will 
   be aware of what option to add to the shortcode and be sure the loop works.
 * Use the executable PHP widget to create a widget in which you can write some 
   PHP. You need it to invoke the WPML conditional tags.
 * And there’s the result :
 *     ```
       <?php
       if (ICL_LANGUAGE_CODE == 'fr') {
           echo '<div>'; // this is what I usually put in the "before items" section of mini loop
           echo do_shortcode('[miniloop categories=46 number_posts=1 shuffle_order=1 order_by="random"]{image from=attached width=70 height=auto cache=clear}<h4><a href="{url}" title="En savoir plus sur le projet de {title}">{title}</a></h4><p>{excerpt custom=1}</p>[/miniloop]');
           echo '</div><div class="more"><a href="/clients" title="Tous nos clients"><span>Tous nos clients</span></a></div>'; // this is what I usually put in the "after items" section of mini loop
       }
       elseif (ICL_LANGUAGE_CODE=='en') {
          echo '<div class="widget-content client">';
           echo do_shortcode('[miniloop categories=46 number_posts=1 shuffle_order=1 order_by="random"]{image from=attached width=70 height=auto cache=clear}<h4><a href="{url}" title="Read more about the project of {title}">{title}</a></h4><p>{excerpt custom=1}</p>[/miniloop]');
           echo '</div><div class="more"><a href="/clients-2" title="More clients"><span>More clients</span></a></div>';
       }
       else {}
       ?>
       ```
   
 * And there’s a list of the arguments supported by the shortcode :
 *     ```
       $args = array(
               'title' => __( 'Recent Posts', 'mini-loops' ),
               'hide_title' => 0,
               'title_url' => '',
               'number_posts' => 3,
               'post_offset' => 0,
               'post_type' => 'post',
               'post_status' => 'publish',
               'order_by' => 'date',
               'order' => 'DESC',
               'reverse_order' => 0,
               'shuffle_order' => 0,
               'ignore_sticky' => 1,
               'only_sticky' => 0,
               'exclude_current' => 1,
               'categories' => '',
               'tags' => '',
               'tax' => '',
               'custom_fields' => '',
               'exclude' => '',
               'before_items' => '<ul>',
               'item_format' => '<li><a href="[url]">[title]</a><br />[excerpt]</li>',
               'after_items' => '</ul>',
               );
       ```
   
 * Of course, I could have put the code before and after inside the shortcode… but
   It’s outside for readability and to bulletproof the shortcode with less arguments.
 * Glad if it could help. But the ability to have gettext expressions inside the
   items format (before and after too) would be a great feature…
 *  Plugin Author [Kailey (trepmal)](https://wordpress.org/support/users/trepmal/)
 * (@trepmal)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/plugin-mini-loops-how-about-inserting-php-code-into-item-format/#post-3039761)
 * You might be able to use the `miniloops_item_format` filter. For example, in 
   the item format put a placeholder string, then use that filter to replace the
   string with whatever you need:
 *     ```
       add_filter( 'miniloops_item_format', function( $format ) {
       	$string1 = __( 'Some text', 'text-domain');
       	$format = str_replace( '###', $string1, $format );
       	return $format;
       });
       ```
   
 *  Thread Starter [sugardaddy](https://wordpress.org/support/users/sugardaddy/)
 * (@sugardaddy)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/plugin-mini-loops-how-about-inserting-php-code-into-item-format/#post-3039763)
 * That’s a bit easier and clean… thanks a lot !!
 *  Thread Starter [sugardaddy](https://wordpress.org/support/users/sugardaddy/)
 * (@sugardaddy)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/plugin-mini-loops-how-about-inserting-php-code-into-item-format/#post-3039767)
 * And… just one more question (as I’m not a developer) : how to do that for many
   strings ? Should I make a function for each string ?
 *  Thread Starter [sugardaddy](https://wordpress.org/support/users/sugardaddy/)
 * (@sugardaddy)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/plugin-mini-loops-how-about-inserting-php-code-into-item-format/#post-3039768)
 * Sorry for that PHP question… I found by myself.
    But as I want to include placeholders
   for translations into before and after item, I have to create filters for that
   placements.
 *  Plugin Author [Kailey (trepmal)](https://wordpress.org/support/users/trepmal/)
 * (@trepmal)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/plugin-mini-loops-how-about-inserting-php-code-into-item-format/#post-3039769)
 * There are similar hooks for both the before and after fields. For those, use 
   either `miniloops_before_items_format` or `miniloops_after_items_format` in place
   of `miniloops_item_format`
 *  Thread Starter [sugardaddy](https://wordpress.org/support/users/sugardaddy/)
 * (@sugardaddy)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/plugin-mini-loops-how-about-inserting-php-code-into-item-format/#post-3039770)
 * Yes I found it before your answer, and it works like a charm !!
 *  Thread Starter [sugardaddy](https://wordpress.org/support/users/sugardaddy/)
 * (@sugardaddy)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/plugin-mini-loops-how-about-inserting-php-code-into-item-format/#post-3039771)
 * One more thing to close this topic : actually, I’m working with WPML and, as 
   an advice, you should add an apply_filters to your widgets’titles.
    That’s what
   I did, but I have to do it on each update…
 *  Plugin Author [Kailey (trepmal)](https://wordpress.org/support/users/trepmal/)
 * (@trepmal)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/plugin-mini-loops-how-about-inserting-php-code-into-item-format/#post-3039772)
 * Adding the`widget_title` filter in my list for the next update.
 *  Thread Starter [sugardaddy](https://wordpress.org/support/users/sugardaddy/)
 * (@sugardaddy)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/plugin-mini-loops-how-about-inserting-php-code-into-item-format/#post-3039773)
 * Thanks a lot !!

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘[Plugin: Mini Loops] How about inserting PHP code into Item format ?’
is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/mini-loops_f7f7f7.svg)
 * [Mini Loops](https://wordpress.org/plugins/mini-loops/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/mini-loops/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/mini-loops/)
 * [Active Topics](https://wordpress.org/support/plugin/mini-loops/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/mini-loops/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/mini-loops/reviews/)

## Tags

 * [Localization](https://wordpress.org/support/topic-tag/localization/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 11 replies
 * 2 participants
 * Last reply from: [sugardaddy](https://wordpress.org/support/users/sugardaddy/)
 * Last activity: [13 years, 2 months ago](https://wordpress.org/support/topic/plugin-mini-loops-how-about-inserting-php-code-into-item-format/#post-3039773)
 * Status: resolved