Question

I am not sure this is even possible with just using Movable Type tags but, how do I display random number with in certain range?

For example I have 10 images named 1~10 and every time I rebuild I want to display a random image from that range.

I use MT5.

Thank you in advance!

Was it helpful?

Solution

You can try my version of the MTCollate plugin with random filter. Original documentation is here: http://www.nonplus.net/software/mt/MTCollate.htm - difference is that it adds a sort="~" or "random" filter, but you'll probably be fine using the MTShuffleList block.

OTHER TIPS

I think if you want to show one image and images count is ten, maybe you can show this cord.

<MTSetVarBlock name="imageID"><MTDate format="%S"></MTSetVarBlock>
<MTSetVarBlock name="imageID"><mt:GetVar name="imageID" op="div" value="6" sprintf="%d"></MTSetVarBlock>
<MTSetVar name="imageID" op="++">
src="/images/hoge<mt:GetVar name='imageID'>.jpg"

You can actually do this with PHP if you're so inclined. Movable Type supports the ability to publish to PHP and you can just put the content you want to be randomized inside of a PHP block. All you need to do is change the published archive file type to "php" in the blog settings. Here is the MTML sample:

<?php
    $images = array();
    <mt:Asset id="1">
    $images[] = '<mt:AssetURL/>';
    </mt:Asset>
    <mt:Asset id="2">
    $images[] = '<mt:AssetURL/>';
    </mt:Asset>
    <mt:Asset id="3">
    $images[] = '<mt:AssetURL/>';
    </mt:Asset>
    $selected_asset = array_rand($images);
?>

Just repeat the Asset tag for each of the specific assets you want. That will generate ten operations to push each image asset's URL into the array. Alternatively, if you want to expose the last ten, you'd just to <mt:Assets lastn="10">

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top