Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: smd_random_banner: Random banner image for advertising
ahhh. could be the corp firewall i’m behind here. can be a tricky fella…
that URL worked fine though – off to test now!
L.
“Absorb what is useful, Discard what is not, Add what is uniquely your own” – Bruce Lee
Offline
Re: smd_random_banner: Random banner image for advertising
hmm. no dice!
i get an error msg:
<code>tag_error <txp:notice message=“malformed random_banner tag” /> -> Textpattern Warning: unknown_tag</code>
i’m using:
<code><txp:smd_random_banner use_alt=“1” match_text=”?” look_in=“title,category” /></code>
which, by all accounts, should display any image from the library that match words in the alt text with words in the title or category?
however, if i take ‘match_text’ out and replace with ‘avoid_text’ images start to appear – which i assume are now avoiding words in the title or category that also appear in the alt text…
or did i miss something? :-)
L.
“Absorb what is useful, Discard what is not, Add what is uniquely your own” – Bruce Lee
Offline
Re: smd_random_banner: Random banner image for advertising
One quick question: does ‘avoid’ or ‘match’ text look at whole words only, and is it case sensitive?
“Absorb what is useful, Discard what is not, Add what is uniquely your own” – Bruce Lee
Offline
Re: smd_random_banner: Random banner image for advertising
lukepermsn wrote:
hmm. no dice! i get an error msg:
Bugger. That was me being stupid and not testing what happens if no images match. It shouldn’t return an error it should just return, well, nothing. So now it does just that.
<code><txp:smd_random_banner use_alt=“1” match_text=”?” look_in=“title,category” /></code>
which, by all accounts, should display any image from the library that match words in the alt text with words in the title or category?
Not quite. It will display any image from the library that match words in the alt text with the whole of the title or the whole of the category (or section). At the moment it doesn’t split the title, category or section into its discrete words. This is for two reasons right now:
1) What would I split the words at? Maybe 80% of the TXP world might use hyphen-as-the-separator but not all will.
2) Once I’ve split the words I need to tell the database to match against each word and I haven’t figured out how to do that efficiently yet. It’d turn into spaghetti-code, which annoys me when I come back to it three months later.
Having said that I just found another bugette which, for some reason, didn’t show itself when I tested it earlier because I was only testing it at the section/category level. When I view an actual article within a category it tries to match “title?c=category_name” as the title instead of giving each part to me separately. Didn’t realise that was the way TXP hands the “title” to me, so I have to process it one more step.
Just done that. Let’s pretend the old version of 0.14 never existed eh? ;-)
Try the link again. If the fact it doesn’t split the URL title into its component parts is a show-stopper for you I can try and figure out how to split them up without making the database cry. It’s probably not tricky for someone who speaks fluent SQL. I’m not that someone :-(
Sorry about the false start…
Last edited by Bloke (2006-09-19 15:20:29)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: smd_random_banner: Random banner image for advertising
lukepermsn wrote:
One quick question: does ‘avoid’ or ‘match’ text look at whole words only, and is it case sensitive?
part 1: See above post.
part 2: yes, because TXP is
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: smd_random_banner: Random banner image for advertising
Bloke wrote:
Sorry about the false start…
haha, no problem. i apreciate this is all work in progress ;-)
i guessed that might have been the problem you described above.
actually, matching whole, case-sensitive words is perfect – i just realised that some images are labeled ‘Antarctica’ – whereas the article in question says ‘Antarctic’ – so I potentially have a problem there – but that can be easily solved by adding ‘Antarctic’ to the alt text.
it could however be a problem if the article title is ‘Antarctic-Peninsula’ – does this mean that I need to have ‘Antarctic-Peninsula’ in the alt text? (hyphen included…)
this is all fine. just a bit of grunt work adding the keywords!
i’m back to my day job now (bore) so i’ll try testing the plug-in a bit more this evening!
cheers :-)
Luke
Last edited by lukepermsn (2006-09-19 15:32:43)
“Absorb what is useful, Discard what is not, Add what is uniquely your own” – Bruce Lee
Offline
Re: smd_random_banner: Random banner image for advertising
lukepermsn wrote:
it could however be a problem if the article title is ‘Antarctic-Peninsula’ – does this mean that I need to have ‘Antarctic-Peninsula’ in the alt text? (hyphen included…)
At the moment, unfortunately yes. You’re right though, the more I think about it, the more it makes sense to split the category/section/title up and look for individual words. I really only based it on section when I designed it and just threw ‘title’ and ‘category’ in because they were easy two-liners. Some adage involving the words ‘piss-poor’ and ‘planning’ is coming to mind :-D
Right, this is what I’ll try and do:
1) Find out if TXP can give me the title-format information in a form I can use. I don’t anticipate it will, but there may be a cool function hidden in the API somewhere that might return me a ‘-’ if that’s the character used, or something else if someone’s elected to use a different character. For people using CamelCase I’m pretty much stuffed.
2) Based on that I can split the category/section/title into its constituent words. Failing that I’ll assume a hyphen and fix it later if that’s not to taste.
3) Next, I can find some efficient way of querying the database looking for images that have any of those words in them. Easier said than done with my (lack of) SQL skills, but there must be a way using IN( list, of, words ) or something.
4) I’ll make this the default behaviour and add an option to override it, e.g. whole_urls=“1” (or something better if you have any ideas – I’m rubbish at naming options)
Sound like a plan?
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: smd_random_banner: Random banner image for advertising
Sounds great – it’s nice to be part of the process of building creating this plug-in!
I reckon that if anyone is using CamelCase, they wouldn’t find this plug-in very useful, as the word searching would be completely negated by that form of title / section / category…
I wish I knew more about SQL to help with your querying – I’m looking forward to doing some thorough testing tonight and will certainly report back all my findings!
Cheers. L.
Last edited by lukepermsn (2006-09-19 18:31:53)
“Absorb what is useful, Discard what is not, Add what is uniquely your own” – Bruce Lee
Offline
Re: smd_random_banner: Random banner image for advertising
Hi mate,
Have been playing with this a bit now, and it appears to work completely as expected! Very cool indeed.
What’s really nice is that it seems that it doesn’t matter how words are formatted in the ‘alt text’ – as the plug-in picks out individual words whether they are separated by hyphens or spaces? It might be worth clarifying that one.
Now I’m playing with this, the tag I think I will most likely use is:
<code><txp:smd_random_banner use_alt=“1” match_text=”?” avoid_text=“Schools,School,Project,landscape” look_in=“title,category” /></code>
Which essentially (if I understand correctly) displays any image from the library that contains words in the alt text that match the title or category text, but avoid displaying any images with the words ‘Schools’, ‘School’, ‘Project’ or ‘landscape’ in the alt text.
However, what happens if a word in ‘match_text’ is also found in ‘avoid_text’?
i.e. some images have alt text: “Kenya School Project” – which I still don’t want to appear on the Kenya page, so essentially it would seem that ‘avoid_text’ should be used as a conditional negator for ‘match_text’ – does that make sense?? ;-) i.e. anything in ‘avoid_text’ should overrule words found in ‘match_text’ if the ? operator is used.
For some ultimate grooviness, the ability to negate categories / subcats would be genius – as I could then use:
<code><txp:smd_random_banner category=”!header, !detail” use_alt=“1” match_text=”?” avoid_text=“Schools,School,Project,landscape” look_in=“title,category” /></code>
Which essentially would prevent any images showing from the ‘header’ or ‘detail’ categories in the library!
Brain bending indeed – but becoming a quite powerful random / related / contextual image plug-in!
L.
Last edited by lukepermsn (2006-09-19 19:35:30)
“Absorb what is useful, Discard what is not, Add what is uniquely your own” – Bruce Lee
Offline
Re: smd_random_banner: Random banner image for advertising
Pants. Small snagette. Added the ability to split the text up (easier than I thought) but there’s an implementation problem.
The ‘alt’ column in the database is, for all intents and purposes, a full string of words. In order to check word-for-word there are two options:
1) Use a fulltext search which makes this sooo simple it hurts. Except TXP doesn’t have a fulltext index on that table/column, so this doesn’t work.
2) Use wildcards
Option 2 is what I’m doing now: make up a list of words and stick wildcards round each one, testing them in turn against the alt text/image filename. The problem here is that the computer has no concept of what a “word” is. If your title was “US fly drive deals”, you will get images that had alt text with the following words in them:
russia, belarus, flying, driven, house
and so on….
I tried the SQL “In” clause too but that doesn’t work the way I’d hoped. My guess is, unless somebody points me towards a clever way of doing it, I’ll have to stick with keeping the title/section/category text together for now.
it doesn’t matter how words are formatted in the ‘alt text’ – as the plug-in picks out individual words whether they are separated by hyphens or spaces
Yep, it will appear that way because I stick wildcards around each word in your list (and wildcards around the whole of the title/section/category). You may come unstuck occasionally as mentioned above if you use a short word that is contained inside another word because both will come out BUT, as you found out…
what happens if a word in ‘match_text’ is also found in ‘avoid_text’?
… the saviour is that if it does happen you can “negate” the longer/other word using avoid_text.
When you brought up the idea of match_text, I played with it both ways round and decided it made more sense (and was more flexible) to process match_text first so you can override it with avoid_text if you wish. Looks like I chose correctly. That’s a relief :-)
For some ultimate grooviness, the ability to negate categories / subcats would be genius
That would indeed be rather neat. Wonder if my coding is up to it… time will tell.
Thanks for stress-testing this and throwing ideas about. The plugin’s getting more useful by the minute.
Last edited by Bloke (2006-09-19 20:10:56)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: smd_random_banner: Random banner image for advertising
Well, it seems to be working rather well right now. ‘avoid_text’ is certainly negating anything ‘match_text’ throws up, so all good there. and the whole wildcard issue isn’t really an issue as far as I’m concerned. It appears to be rather a nice bonus that I can have the word ‘Antarctica’ in the alt text – but ‘Antarctic’ will also match there. So good job!
For the sake of completeness, if you really wanted to go the route of fulltext, wouldn’t that simply be a database update on that particular table? i.e.
ALTER TABLE ‘txp_image’ ADD FULLTEXT (‘alt’);
Or am I oversimplifying?
The wildcard route certainly works for reasons described above, certainly for now as I only have a couple of words in each alt tag. I guess one could always use an Anagram Generator to test for unusual cross-references!
So does this mean you’ve solved the hyphen separated word issue in the URL? awesome. I’m just realising the complexity of what is happening each time a page loads up – that the plug-in takes the words from the URL string and cross checks with the entire database of alt text for matching images… pretty wild when you consider i have about 500 images currently loaded.
Thanks for stress-testing this and throwing ideas about. The plugin’s getting more useful by the minute.
You’re absolutely welcome! I’m quite enjoying this process. Thank you for being so ‘into it’…
One more thought for the pot: currently no images display if ‘match_text’ doesn’t throw up anything meaningful. It would be neat is if there was some option for the plug-in to generate a random image anyway. That way random images will always display, switching to more ‘contextual’ random images if something in the URL matches the alt text. Maybe an option called <code>‘spawn’</code>? i.e. <code>spawn=“y”</code> to make the plug-in choose a random image from the assigned category(s) instead of showing nothing?
And finally, finally: I’m currently using two tags on the page to generate two random / contextual images. One side effect of this is that sometimes the plug-in generates the same image twice. Maybe the tag could have a ‘limit’ feature to output more than one image? it would be easy to then use CSS to arrange them as desired…
But all these things in time! good night.
Luke
Last edited by lukepermsn (2006-09-19 21:05:32)
“Absorb what is useful, Discard what is not, Add what is uniquely your own” – Bruce Lee
Offline
Re: smd_random_banner: Random banner image for advertising
lukepermsn wrote:
For the sake of completeness, if you really wanted to go the route of fulltext, wouldn’t that simply be a database update on that particular table? i.e. ALTER TABLE ‘txp_image’ ADD FULLTEXT (‘alt’);
Yup, but the other (currently 8, but maybe more in future) people who use the plugin would find it doesn’t work without making the mod also :-p And my coding is nowhere near good enough to figure out how to do that at install time.
So does this mean you’ve solved the hyphen separated word issue in the URL?
Sort of, by virtue of not doing anything at all ;-) I tried, I failed, but as it happens it’s working as you expect anyway so I’ll start work on the next bit.
I’m just realising the complexity of what is happening each time a page loads up…
Yeah, and even though it’s not really very optimized ‘coz I’m a lazy coder, I think it’s working quick enough so far. One of the benefits of this awesomely lightweight TXP engine, methinx.
One more thought for the pot: currently no images display if ‘match_text’ doesn’t throw up anything meaningful. It would be neat is if there was some option for the plug-in to generate a random image anyway… Maybe an option called <code>‘spawn’</code>?
That could certainly be done. I thought about that issue as I was writing the help file but talked myself out of coding anything by palming the “no image” issue off to the excellent chh_if_data plugin. If my plugin returns nothing at all, chh_if_data can detect it and provide an alternative path for you to do anything else you desire.
But adding the catch-all to this plugin might work. It would mean a 2nd call to the database because, after the first has returned no rows, I’d need to strip out everything except the category attribute (if supplied) and try again. Shouldn’t slow it down too much – after all, it’s an “exceptional” circumstance.
And finally, finally: … Maybe the tag could have a ‘limit’ feature to output more than one image?
Not a problem in principle. May have to delve into providing wraptag and class attributes though, which is a bit of a bind. I suppose with good use of CSS selectors it’s possible to style img and img > img (or something) to get hold of each image separately, but that may leave IE users out in the cold.
Certainly getting more than one image out of the database is a breeze. I’ll experiment with outputting two or more and see how easy it is to manipulate them on the page.
Last edited by Bloke (2006-09-19 21:44:51)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: smd_random_banner: Random banner image for advertising
Cool as.
Unfortunately I’m already using chh_if_data to make the random images appear if another tag doesn’t generate any output! No matter. I can probably get around that. :-) Maybe I can embed chh_if_data inside each other?? I love this conditional statement way of programming :-p
The hyphen separated title issue hasn’t gone away – the plug-in works great on pages that have a single word title or category, like ‘Tibet’ or ‘Africa’ – but pages that have something like ‘Antarctic-Peninsula’ display no images right now, as I guess the plug-in is looking for that string in the alt text. Once again, no matter as I can simply add that string to alt text for now, but it would certainly be nice and slick if the plug-in recognised ‘Antarctic’ and ‘Peninsula’ as two separate words ;-) (no pressure!)
btw – If you want, I’ll email the URL of the site I’m working on, so that you can see the thing in action!
Yeah, CSS selectors would be the way to go for styling image positions. I wouldn’t get too hung up on <code>break</code> and <code>wraptag</code> attributes, as it would be a breeze to simply enclose the tag inside a DIV with a css ID and then call the images like:
<code>#images img { … do something … }</code>
Cheers :D
Last edited by lukepermsn (2006-09-20 10:04:47)
“Absorb what is useful, Discard what is not, Add what is uniquely your own” – Bruce Lee
Offline
Re: smd_random_banner: Random banner image for advertising
Hi mate, some more feedback for you:
Been using this quite extensively today, and I must say I’m impressed. It’s been a bit of grunt work on my part now to tag around 500 images, but now that (most of them) are correctly tagged, the plug-in works like a dream.
I’ve gotten around the parent / subat issues by simply employing more descriptive tagging, and using ‘<code>avoid_text</code>’ to prevent certain images appearing in certain locations. Similarly I’ve circumvented the whole separating the hyphenated title / category strings into individual words issue by simply putting the whole title or category into some of the alt texts of images I want to appear on those pages. Just looks a bit clunky though! But on the pages themselves, images are randomly rotating on each display as expected.
The only issues I still have with the plug-in as it stands are not being able to generate more than one image and the inability to have it output an image anyway, if <code>match_text</code> doesn’t throw up anything. As I’m using two separate tags, the same image appears sometimes on a page twice! and as described, using <code>chh_if_data</code> isn’t really an option for me for the no image issue.
But, you know what: Now that I’ve added all the relevant titles etc. into the image alt tags, I’ve realized that there is one feature that would make this plug-in killer: and that’s if you could match <code>look_in</code> words with the image categories themselves – as frankly, the majority of the text I have ended up putting in the alt text is a replication of the image’s category and that categories parent, as I have them all arranged by world regions, and then each region is divided into countries.
I realize that this is a good workaround for me right now, to get over the list by category issue above – but the ability to <code>use_category</code> also as a reference for keywords would be killer. Or at least something to ponder over ;-)
Bye for now. L.
Last edited by lukepermsn (2006-09-20 22:00:10)
“Absorb what is useful, Discard what is not, Add what is uniquely your own” – Bruce Lee
Offline
Re: smd_random_banner: Random banner image for advertising
lukepermsn wrote:
The only issues I still have with the plug-in as it stands are not being able to generate more than one image and the inability to have it output an image anyway.
Issues now dealt with in v0.15
Two new parameters: limit="2" (3,4,5… defaults to 1) to generate that many images in one go, and always_display="1" to cause the plugin to try again in the event it finds nowt that matches your criteria. In that situation it ignores any match_text or avoid_text you have supplied and looks in just the given category (if supplied) or the whole image pool if not.
I’ve realized that there is one feature that would make this plug-in killer: and that’s if you could match <code>look_in</code> words with the image categories
{headsmack} why didn’t I think of that. Right, I’m going to climb back in my box and think. Initial thought is that the nomenclature is going to get confusing from hereon in. Multiple uses of the word “category” now to match different things. Urk. Watch this space…
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline