Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter sugardaddy

    (@sugardaddy)

    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

    (@sugardaddy)

    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, Executable PHP 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)

    (@trepmal)

    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

    (@sugardaddy)

    That’s a bit easier and clean… thanks a lot !!

    Thread Starter sugardaddy

    (@sugardaddy)

    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

    (@sugardaddy)

    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)

    (@trepmal)

    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

    (@sugardaddy)

    Yes I found it before your answer, and it works like a charm !!

    Thread Starter sugardaddy

    (@sugardaddy)

    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)

    (@trepmal)

    Adding thewidget_title filter in my list for the next update.

    Thread Starter sugardaddy

    (@sugardaddy)

    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.