Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-02-15 16:04:00

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Article category list with images

How do I…

Sorry can’t get my head around that one.

I want to build a list of article categories with images.
The images are the one last added in an article in each category.

So in a form, from an article custom call I have this already working:

<txp:category1><txp:if_different><txp:category1 title="1" /></txp:if_different></txp:category1>
<txp:category1><txp:upm_article_image limit="1" form="my_form" /></txp:category1>

Except it’ll show me a list of categories with, for each listed category, a list of all images assigned to articles in that category.

How do I… Have this list of categories with only one image, the last image that was added to an article in that category.

This is not a list for image categories, but for articles categories showing only the latest image assigned to an article.

If I set limit=“1” in the preceding article_custom call, it’ll output only one category… ;(

Any wings ?

Cheers…


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#2 2010-02-15 16:19:22

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: Article category list with images

Is that not essentially showing the last article from the respective category and using a form that shows only the article_image, e.g. something along the lines of:

<txp:category1><txp:if_different><txp:category1 title="1" /><txp:article_custom category='<txp:category1 />' limit="1" sort="Posted desc" ><txp:article_image /></txp:article_custom></txp:if_different></txp:category1>

Maybe that will bork the if_different, though? Is there a reason you’re not using txp:category_list instead of article_custom to construct your list? You could then do without the if_different construction.

Another idea might be to assign the images you use for the article_image to an image category of the same name and grab the latest image in that category… (for example when some articles do not contain an article_image).


TXP Builders – finely-crafted code, design and txp

Offline

#3 2010-02-15 20:45:06

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Article category list with images

jakob wrote:

Is there a reason you’re not using txp:category_list instead of article_custom to construct your list?

You might need both. Would something like this work? Beware, not tested at all! ;)

<txp:category_list wraptag="ul" break="li">
	<txp:article_custom category='<txp:category />'>
		<txp:variable name="art_img" value='<txp:article_image />' />
		<txp:if_variable name="art_img" value="">
		<txp:else />
			<txp:if_first_article>
				<txp:category>
					<txp:upm_article_image form="my-form" />
				</txp:category>
			</txp:if_first_article>
		</txp:if_variable>
	</txp:article_custom>
</txp:category_list>

Offline

#4 2010-02-16 11:01:08

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: Article category list with images

That’s is perfectly working Els, thank you very much.

Jakob thank you for your help as well.

Added this tip to the Txp tips knowledge base

Last edited by hablablow (2010-02-17 19:51:03)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#5 2010-02-17 11:23:49

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: Article category list with images

Last request – question:

I do I output the number of articles in each category ?

Is this possible now in TXP 4.2 with native txp tags ?

Need to try that snippet I found:

<txp:php>echo safe_count(“textpattern”, “Category1 = ‘foobar’ or Category2 = ‘foobar’”);</txp:php>

Any better approach ?

Last edited by hablablow (2010-02-17 11:33:37)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#6 2010-02-17 11:48:12

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: Article category list with images

The above snippet works, doesn’t throw any errors, but counts 0 articles !?

<txp:php>echo safe_count(“textpattern”, “Category1 = ‘<txp:category1 />’”);</txp:php>

Actually it’s working when you manually enter the name of the category… But needs to work for each available category…

Achhnmmmff…

Last edited by hablablow (2010-02-17 15:06:08)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#7 2010-02-17 19:00:09

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Article category list with images

<txp:category1 /> only works inside an article form or article or article_custom container tags. Are you using it in another context? (Anyway, I can’t even tell if that code is correct…)
You can also use rah_function.

Last edited by els (2010-02-17 19:00:56)

Offline

#8 2010-02-17 19:25:28

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: Article category list with images

Els,

I’m using it inside the previous snippet you came with to show the category list. So it’s actually in an article_custom call.

Here it is in context:

<txp:category_list wraptag="ul" break="li">
	<txp:article_custom category='<txp:category />'>
		<txp:variable name="art_img" value='<txp:article_image />' />
		       <txp:if_variable name="art_img" value="">
		       <txp:else />
			<txp:if_first_article>
                                <txp:category title="1" link="1" />
				<txp:category>
					<txp:upm_article_image limit="1" form="article_img" />
				</txp:category>
					<txp:php>echo safe_count("textpattern", "Category1 = '<txp:category1 />'");</txp:php>
			</txp:if_first_article>
		</txp:if_variable>
	</txp:article_custom>
</txp:category_list>

Thanks again for your support !

Last edited by hablablow (2010-02-17 19:27:30)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#9 2010-02-17 19:40:10

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Article category list with images

I think it doesn’t parse the txp tag, but I’m not good at php so I can’t tell you how to change it… I have used rah_function to do the same, like this:

<txp:rah_function call="safe_count" table="textpattern" where='Category1="<txp:category1 />"' />

Offline

#10 2010-02-17 19:49:14

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: Article category list with images

<txp:how_cool />
<txp:solved />

Seriously I wish I could have your skills Els… That’s what the forum is there for: share knowledge…

Multi-thanks again !! I’ll add that, if you don’t mind, to the txp tips knowledge base…


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#11 2010-02-17 19:59:21

PascalL
Member
From: Switzerland
Registered: 2009-03-09
Posts: 132
Website

Re: Article category list with images

I think it doesn’t parse the txp tag, but I’m not good at php so I can’t tell you how to change it

I just discovered that every txp tag has it’s equivalent php fonction

Not that I’m a coder either, but I’ve found good use of it lately.

Last edited by PascalL (2010-02-17 19:59:50)

Offline

#12 2010-02-17 19:59:29

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Article category list with images

hablablow wrote:

I’ll add that, if you don’t mind, to the txp tips knowledge base…

I don’t mind, but it’s Jukka’s plugin! I’m only using it… ;)

Offline

Board footer

Powered by FluxBB