Mini Loops

Widget for mini post loops.

Show most recent posts, posts from categories, and more. Can be displayed via widgets, shortcodes, and template tags.

This is a new release, please report bugs to trepmal (at) gmail (dot) com before leaving a poor review. Thanks

Download

Latest version: Download Mini Loops v1.0.1

Installation

  1. Download the zip file and extract the contents.
  2. Upload the ‘mini-loops’ folder to your plugin directory (default: wp-content/plugins/).
  3. Activate the plugin through the ‘plugins’ page in WP.
  4. See ‘Appearance’->’Widgets’ to place it on your sidebar. Set the settings.

FAQ

Q. How can I exclude categories?
A. List its ID as a negative number.

Q. My site broke after customizing the excerpt. What happened?
A. Did you set the strip_tags attribute to false? ([excerpt strip_tags=0]). If tags haven’t been stripped, it may have cut off the text before an HTML tag was properly closed, thus breaking the page. Setting strip_tags to false should only be used if you’re carefully managing the excerpt’s output.

Q. Why can’t I add an ID to the element in ‘Before Items’?
A. There are limitations on the tag or tag/attribute combiniations allowed by WordPress. However, these can be overcome with a few lines of code.

To allow an additional tag, use this:

add_filter( "admin_init", "allowed_tags" );
function allowed_tags() {
    global $allowedposttags;
    $allowedposttags["video"] = array();
}

To allow additional attributes for any tag, use the following code:

add_filter( "admin_init", "allowed_tags" );
function allowed_tags() {
    global $allowedposttags;
    $allowedposttags["video"]["src"] = array();
    $allowedposttags["video"]["type"] = array();
    $allowedposttags["video"]["poster"] = array();
}

If you’re using a custom theme, you can add this code the its functions.php file. Otherwise, you may want to create your own plugin to hold these modifications.

See this post for instructions on creating your own plugin.

Changelog

Version 1.0.1

  • Fix: Multiple tag bug. Only first was being recognized, now correctly accepts all. Thanks Ozias.

Version 1.0

  • New: Exclude sticky posts option
  • New: Get posts from first current category (if single)

Version 0.9

  • Fix: Prevents error from being displayed if image can’t be resized
  • New: Improved support for multisite use
  • New: Improved [miniloop] shortcode. Editor tries to hard to “fix” the user-provided item format. Now you can save the format in a custom field. See Other Notes

Version 0.8 (2011.10.31)

  • Added French Translation files. (Thanks @maoneetag)

Version 0.8

  • New: [ml_field] shortcode, [ml_category] shortcode, [ml_tag] shortcode, [ml_taxonomy] shortcode
  • Fix: strip slashes from widget title

Version 0.7

  • New: more excerpt options (use automated/custom excerpts rather than trim by length, option to bypass tag/shortcode stripping). Please report issues.
  • Fix: stipping slashes for before/after item during output

Version 0.6

  • New (sorta): shortcode option [miniloop] (see Other Notes for usage). Why “sorta”? shortcode has existed the whole time, I only just now added some docs
  • New: get posts from current category (if archive)
  • New: custom taxonomies, if only 1 ID given, and it’s negative, treat it like “NOT IN”
  • Fix: added missing echo in instructions
  • General code optimization

Version 0.5

  • New: get only sticky posts
  • New: shuffle order
  • New: [ml_author_link] shortcode
  • New: [ml_comment_count] shortcode
  • New: thumbnail cropping for local images
  • New: Ready for localization

Version 0.4

  • New image option: get first attached image (great for galleries!)
  • Bug fix: broken image if no fallback is set

Version 0.3

  • Bug fix: post status works now

Version 0.2

  • Improvements: hide title, link title, exclude current single post options

Version 0.1

  • Initial release version.

29 thoughts on “Mini Loops

  1. Hi,
    This is a very useful plugin. I hope you will develop it further. I also have some feature requests.

    Using category slugs, I use friendly links and there is no way in getting the category ID in a easy way in WP so using sulgs or names would speed up things drastically. There are a lot of wp functions that ca do this very easily.

    Some code examples for of short code expalaining how things work in when used in page or post. The “List category posts” has some good examples that are very clear when you start with the plugin.

    Thanks for the good work. This makes working with automatic menu’s in post and pages a lot easier.

  2. I am a novice when it comes to programming details but am hopeful you can provide me with direction for the following. I want to use your plugin to show posts on a page rather than as a widget within a sidebar. How do I go about doing that? Appreciate your kindness and patience. -James.

      • I have the same question. I wasn't completely clear from viewing your documentation how to do this. Can I use miniloops to display posts on a page just as they would be displayed by default on WordPress? I'm trying to create a static homepage, but insert posts from the loop onto that page. If I wanted to display the three most recent posts with a specific category, what shortcode would I use? Something like?:

        [miniloops number_posts=10 categories=12]

        I say something like that, because I tried that and it didn't look anything like a normal post and the content spilled out of the content area into the sidebar. What am I doing wrong?

        • To get the three most recent posts, you're on the right track, just make sure to specify 3, not 10.
          <code>[miniloops number_posts=3 categories=12]</code>

          However, Mini Loops will by default display everything in as an unordered list. This is probably not how your themes posts.

          I don't know exactly how your theme displays posts, but your adjustments might be something like this:

          Shortcode:
          <pre>[miniloop before_items='' after_items='' number_posts=3 categories=12][ml_format][/miniloop]</pre>

          On the same page, create a custom field called 'ml_format' with this value:
          <pre><div class="entry [class]"><a href="[url]">[image from=customfield
          cfname=image width=50 height=50 class=alignright
          fallback='http://dummyimage.com/50'title
          [excerpt wlength=30 space_between=1 after="..." after_link=1]
          By [author] on [date format="n/j/y"]</div></pre>

  3. Hi Kailey. I am using the mini loops plugin and its associated shortcode. Here is what I have:

    [miniloop categories=42 exclude=1696 number_posts=20 before_items= after_items=]{title}[/miniloop]

    This works! However, I have two questions:

    (1) Rather than using the exclude argument, I want to use tags in a conditional type scenario. Ideally, what I would like is:

    [miniloop categories=42 tags=active number_posts=20 before_items= after_items=]{title}[/miniloop]

    Where only posts that are from category 42 and have been assigned the tag active will show. Is this possible?

    (2) I am having difficulties making my list bulleted. My understanding is that the tag defines an unordered list (a bulleted list) however I am having difficulties getting the before_items and after_items arguments to work, assuming that is where my problem lies. Where should I be placing these arguments and how should they be formatted?

    Thank you so much for your assistance.
    James

  4. Hi, Loops Mini is an application that is still very useful to me,
    Thank you.
    Although I have a problem:
    When “w3c validation” errors with the alt property of the images.
    I can fix it how?.

    thanks

    Sorry for my English.

  5. Love this plugin!
    I have deals I like to post on my blog but don’t want them to clutter my front page.
    I set up the plugin to show only the “deals” category and it works great! BUT when I use the WP Hide Post plugin to keep a post from showing on the front page, it also keeps it from showing in my mini loops side bar.

    Is there a way to force all posts in my specified category to show in the widget regardless of it showing on the front page?

    thanks so much for any help!

    • Took a little investigating, but I think I’ve found a solution.

      You’ll need to edit the Mini Loops plugin, so using your favorite FTP client and text editor, find and open the helpers.php file in Mini Loops plugin folder (probably something like /wp-content/plugins/mini-loops/helpers.php).

      Find the line that reads $miniloop = new WP_Query( $query ); (line 114 in v0.8) and just above that add:

      remove_filter('posts_join_paged', 'wphp_query_posts_join');
      remove_filter('posts_where_paged', 'wphp_query_posts_where');

  6. This plugin are awesome! Thank you very much.
    However I have one problem: When I use shortcodes for image, WP returns this: “Catchable fatal error: Object of class WP_Error could not be converted to string in …pluginsmini-loopshelpers.php on line 550″.

    I tried “post”, “thumb”, “attached” and “first”, but the error persists.
    Thank you again.

  7. Hello Kailey,

    First of all, thank you for an awesome plugin! Once the site I am building is up and running, I am definitely buying you a “cup of coffee” :)

    I was getting the same error as Apu (“Catchable fatal error…”) but only when trying to show the image from the custom field, while the ‘first’ attribute gave no errors and displayed the image placed inside the content without problems.

    On the other hand I have the following issue: the site I am building is multilingual (Catalan and Spanish) and I am quite satisfied with the qTranslate plugin. At first I just used the default post type and Mini Loops had no problem displaying a date-type custom field in its correct language. However, since I wanted a bit more of functionality, I used the “Custom Content Type Manager” plugin to create the “Activitats” custom post type with its own date-type custom field. Then I configured the “Custom Post View Generator” plugin to display the post with its date-type custom field and, as you can see, the date is displayed correctly localized: http://asac.adamfarkas.com/?post_type=activitats&p=357

    However, when I use Mini Loops to make a list, the date custom field is being displayed in English: http://asac.adamfarkas.com/activitats-asac/

    I am using the following shortcode:

    [miniloop post_type=activitats number_posts=20]
    Data: {field name=data}
    {title}
    {image from=first width=150 height=150 class=alignleft}
    {excerpt wlength=55 space_between=0}
    Lloc: {field name=lloc}
    Adreça: {field name=adreca}
    Hora: {field name=hora}
    Preu: {field name=preu}
    [/miniloop]

    I tried {field name=data format=”D, j F, Y”} to no avail… :(
    I would really prefer to use Mini Loops for listings as I love the straightforwardness if its item formating… Have any suggestions how to solve this problem? Thanks in advance and sorry for the long post!

    • Thanks for the detailed report!

      I’m not terribly familiar with either qTranslate or “Custom Content Type Manager” so it might take me a bit to find a solution for you.

      Simply based on what you tried to do (“{field name=data format=”D, j F, Y”}”) you can try this:

      Find the miniloop_field() function in helpers.php (begins at line 305 in version 0.9) and replace it with this

      function miniloop_field( $atts ) {
      extract( shortcode_atts( array(
      'name' => '',
      'single' => 1,
      'separator' => ', ',
      'reverse' => 0,
      'format' => 0,
      ), $atts ) );
      if ( empty( $name ) ) return;

      if ( $single ) :
      $return = get_post_meta( get_the_ID(), $name, $single );
      else :
      $meta = get_post_meta( get_the_ID(), $name, $single );
      if ( $reverse ) $meta = array_reverse( $meta );
      $return = implode( $separator, $meta );
      endif;

      if ( $format )
      $return = date_i18n( $format, $return );

      return $return;
      }

  8. Hi and congratulations for this plugin.
    Sorry for this basic question but I would like to have the posts from the current category when I’m reading a single post. Is that possible ?
    In the widget I can see that : “Get posts from current category (if archive)?” Does it work only when you are reading a category but not a single post ?
    Thanks

  9. Is there a way to add the category name to the “Title” field of the widget? It would be the same as when using “Get posts from first category (if single)?” option.

    So instead of having a header like “Recent Posts” it would appear “Recent – Cat A”

    Tried to search this portion of the code, but not familiar with PHP and WP programming…even if you just point out where to change would be appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>