Textpattern tips, tutorials and code snippets

Force article_image field to accept multiple images without a plugin

Plugins come and go but also bugs are suppressed. The code is based on a bug/feature of Textpattern where the article_image field also behaves as a custom_field. There are a number of plugins which can achieve this but here is a native method.

Assign article_image to a custom field

<txp:article_custom id='<txp:article_id />'>
	<txp:variable name="aimg" value='<txp:custom_field name="article_image" />' />
		<txp:if_variable name="aimg" value="">
		<txp:hide>if there is no value in the article_image field show nothing</txp:hide>
		<txp:else />
		<txp:images id='<txp:variable name="aimg" />' limit="10">
			<txp:image />
		</txp:images>
	</txp:if_variable>
</txp:article_custom>

All one needs to do is add the a comma separated list of article ids in the article_image field and the images will show in the page.

For further reading on this method or to see an example of how to use it to create an image gallery, see Display the first image from a list in the article image field or Galleriffic image gallery without any plugins.

2 Comments Comment feed

Hi, is this code not similar to this:

<txp:if_article_image>
<txp:images id='<txp:custom_field name="article_image" />' limit="10"/>
<txp:image />
</txp:images>
</txp:if_article_image>

@Rabah – yes it is similar and the tip is not supposed to be unique (see the last paragraph of the article).

The idea is to present a defined solution for a particular task, in this case simply requiring that the article_image field display a list of images without the use of a plugin. The two articles referenced seek to create image galleries, whereas this article aims to fulfil one simple task.

Add a comment

Use Textile help to style your comments