Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-10-19 14:52:06

Mr. Smith
Member
From: Denmark
Registered: 2006-11-10
Posts: 56

Use category from URL instead of manually write category="something"

I’m using smd_slimbox and I use category=“something” to output the right images in the right page. But instead of having to manually write category=“something” in every page where it is used, I would like to get the category from the URL, and then use a form to output smd_slimbox.

I’ve tried <txp:smd_slimbox category="<txp:category1 />" /> , but it doensn’t work as intended. <txp:smd_slimbox category="some-category" /> works just fine.

Any idea?


Textpattern n00b

Offline

#2 2007-10-19 15:11:04

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Use category from URL instead of manually write category="something"

You could use plain PHP or a plugin, asy_wondertag to use the category. Like this:

<txp:asy_wondertag><txp:smd_slimbox category="<txp:category1 />" /></txp:asy_wondertag>

Cheers!

Last edited by Gocom (2007-10-19 15:11:31)

Offline

#3 2007-10-19 15:24:00

Mr. Smith
Member
From: Denmark
Registered: 2006-11-10
Posts: 56

Re: Use category from URL instead of manually write category="something"

Thanks, I’ll take a look at asy_wondertag!


Textpattern n00b

Offline

#4 2007-10-19 21:02:07

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

Re: Use category from URL instead of manually write category="something"

Mr. Smith wrote:

I’ve tried <txp:smd_slimbox category="<txp:category1 />" /> , but it doensn’t work as intended.

Unfortunately, as you found, it won’t work that way. Tags in tags tend to smash things up. A way round it is to use the awesome asy_wondertag as Gocom suggested but…

instead of having to manually write category=“something” in every page where it is used, I would like to get the category from the URL, and then use a form to output smd_slimbox.

Have you tried <txp:smd_slimbox category="?c" />

That will read the current (article) category and pass it to slimbox, which will then look for an image category of the same name. There’s plenty of other things you can use (?s for section, ?t for title, ?id for article id etc). And, keep it under your hat for now, but I’ve found a way of making it even more useful for the next release.

Does that help?

Last edited by Bloke (2007-10-19 21:03:50)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2007-10-20 12:19:19

Mr. Smith
Member
From: Denmark
Registered: 2006-11-10
Posts: 56

Re: Use category from URL instead of manually write category="something"

Have you tried <txp:smd_slimbox category="?c" />

I just tried that, but now I get an error message when I load the page, saying tag_error <txp:smd_slimbox category="?c" /> -> Textpattern Warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY category asc LIMIT 0,99999' at line 1 select id,name,caption,alt,category,date,author,ext,w,h from txp_image where ORDER BY category asc LIMIT 0,99999 on line 84, and the design is broken. I’ve tried changing it back to <txp:smd_slimbox category="some-category" />, but even though the article is succesfully saved it still outputs the above error message (on that page only).

Really weird… :-)


Textpattern n00b

Offline

#6 2007-10-20 13:02:32

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

Re: Use category from URL instead of manually write category="something"

Mr. Smith wrote:

I get an error message when I load the page

Bugger, you’re right. If the category doesn’t exist it should return nothing, not an error. Must have some faulty logic in the code and I think I know where to look to fix it. Thanks for finding that. Leave it with me, and I’ll try and fix it this afternoon. Sorry for the bug (btw it disappears if you put the site in Live mode :-)

Question: if you do have the global category set, does it work? i.e. if you went to a URL such as http://site.com/section?c=myCatName, does it pull images from ‘myCatName’? It should.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#7 2007-10-20 13:21:13

Mr. Smith
Member
From: Denmark
Registered: 2006-11-10
Posts: 56

Re: Use category from URL instead of manually write category="something"

I’m not quite sure what you mean by “if I have the global category set”, but URLs ending in “section?c=myCatName” does now work for me, as I’ve set Textpattern to use “/titel” in “permanent link mode”. I know that I may be answering something totally different from what you’re asking me … :^)


Textpattern n00b

Offline

#8 2007-10-20 14:11:39

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

Re: Use category from URL instead of manually write category="something"

Mr. Smith wrote:

I’m not quite sure what you mean by “if I have the global category set”

Ah right, ok. Probably just my terminology. I mean when you want to show a list of articles in a category, Textpattern adds ?c= and the category name to the URL line. [ I believe it does that even in “non-messy” permlink mode, although that may be outdated information now in 4.0.5. Been a while since I used category lists ]

With that in the URL, textpattern knows it’s in a specific category and sets the relevant bits and bobs so that programmers can detect what a user is doing, and act accordingly. That’s why when you are “in” a specific category the error goes away. When you are not in a category but just looking at a general article, article list or section, the category is blank and that’s causing my plugin to cry.

I’ve checked and it’s definitely my hack I introduced in v0.24 to get round the bug that if the category was empty the plugin displayed images from the whole site; obviously not desirable. Unfortunately my hack introduced the error you just found. Yet again, because I didn’t test that particular setup in Debugging mode I never spotted it (and nor has anyone else for that matter!)

Working on a fix for the fix… :-)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#9 2007-10-20 14:44:13

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

Re: Use category from URL instead of manually write category="something"

Try that and let me know how you get on.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#10 2007-10-21 17:46:18

Mr. Smith
Member
From: Denmark
Registered: 2006-11-10
Posts: 56

Re: Use category from URL instead of manually write category="something"

Bloke,

I’m sorry, but I’ve been mixing things up here. When I was reinstalling the plugin, the one you link to in your previous post, and trying to get it to work, I realized that I was trying to get smd_slimbox to identify the right image category through what is actually a section. I wanted your plugin to understand that when the URL says “somesite.com/cars”, it should display the images in the “cars” image category.

I then tried <txp:smd_slimbox category="?s" />, and it works perfectly. I may still be mixing things up, but now it works and I’m
sorry if I made a lot of fuss over nothing.


Textpattern n00b

Offline

#11 2007-10-21 21:09:33

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

Re: Use category from URL instead of manually write category="something"

Mr. Smith wrote:

I was trying to get smd_slimbox to identify the right image category through what is actually a section… tried <txp:smd_slimbox category="?s" />, and it works perfectly… I’m sorry if I made a lot of fuss over nothing.

Cool, glad it works for you now. No apology necessary: you found a naughty bug that shouldn’t have been there so you’ve helped the rest of the community benefit from a better plugin. Many thanks.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB