Displaying a Thumbnail of an Entry Image with the Title of a Post

| 2 Comments | No TrackBacks |
Movable Type's WYSIWYG editor makes it super easy to upload one or more images in any post.  Resizing them and moving them around a bit is also a snap in most cases.  But what if you want to display the titles of your most recent entries somewhere else, preferably with a thumbnail pic of one of the images in the post?  Are you stuck with also displaying the entire body of the post to get at the image(s)?  Of course not!
Each time you upload an image into an entry in Movable Type, an 'association' between that image and the post is created.  So the image is not just some HTML code inserted in the post, no, there is an actual relationship stored in the database too.  This allows you to do fun stuff in your template code: listing all the images associated to a post?  No problem, just bring out the <mt:entryassets> tag and loop right over them.

The fun thing about this tag is that as it puts each successive asset in context inside the loop it encloses, you can use any asset-related tag in Movable Type's arsenal.  Want to display a list of thumnails linking to the full version of all images in an entry?  Use this:

<mt:entryassets type="image">
<href="<mt:asseturl>"><img src="<mt:assetthumbnailurl width="50" height="50">"></a>

I just ran this little snippet for all entries in this blog, and this was the result:


Jazzing this up just a little more to also display post titles (and to only display something if the entry actually has an image):

<mt:entryassets type="image" limit="1">
<mt:if tag="asseturl">
<href="<mt:asseturl>"><img src="<mt:assetthumbnailurl height="30">"></a>
<href="<mt:entrypermalink>" style="font-size:30px"><mt:entrytitle></a><br>

The result:

Not bad for something created in five minutes, no?

No TrackBacks

TrackBack URL: https://www.movabletips.com/cgi-bin/mt/mt-tb.cgi/25


Hey great post!

I was wondering if there is a way to display the html element of the height and width from <mt:assetthumbnailurl>

For example: <img src="<mt:assetthumbnailurl height="30">" height="30" width="xxx">
In this case I want to display the "xxx" width size.

There is the function tag <mt:assetproperty image_height> but this only applies to the original image size.

Do you have any idea how to display this info?


What a data of un-ambiguity and preserveness of valuable experience concerning unpredicted emotions.

Leave a comment