Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#61 2007-02-12 18:23:46

DigitalRealm
Member
From: Greenville, SC
Registered: 2006-07-22
Posts: 139
Website

Re: smd_random_banner: Random banner image for advertising

Bloke, your image class attribute works like a charm! Thanks for adding that in.

Offline

#62 2007-02-25 13:47:40

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

Re: smd_random_banner: Random banner image for advertising

smd_random_banner v0.2
After many false promises and a long wait, it’s finally here. smd_random_banner v0.2 is leaner, meaner and more powerful than ever, with sub-category support too.

For those of you familiar with the old v0.1 syntax, it’s a bit of a change:

  • Uses the smd_lib plugin: a library of functions that I use across my plugins. This library is available separately to download but is also included in the smd_random_banner distribution file for convenience
  • New option: subcats="1" (more info later)
  • New option: id_prefix (ditto)
  • match_text / avoid_text now more powerful. look_in no longer required, so has been removed
  • use_alt has been dropped in favour of the more powerful compare_to
  • linkcaption / linkalt have been replaced with link_in
  • linkprefix is now link_prefix
  • Options thumb, always_display and subcats only take one value: the number “1”. You can’t do ="0" to turn them off any more. Just omit the option if you don’t want the feature
  • Spaces ar now permitted in comma-separated lists (in fact you can even use space-separated lists if you prefer)

The options

  • category : comma-separated list of image categories to choose from
  • subcats=“1” : whether to look in sub-categories or not. Default: no subcats
  • match_text : comma-separated list of text strings to look for in the image
  • avoid_text : comma-separated list of text strings to avoid in the image
  • compare_to : comma-separated list of places to look for match/avoid text in the image. Can be either: name (the default), id, caption, alt or category
  • id_prefix : when searching for an ID match (see below), this string is added to the beginning of the ID number. Default: “article-”
  • always_display=“1” : if no matching images are found the plugin usually returns nothing. This forces it to try again without any match_text/avoid_text. Default: off
  • thumb=“1” : to display thumbnails instead of fullsize images. Default: off
  • limit : the number of images to display. Default: 1
  • imgclass : the CSS class to add to each image. Default: no class
  • link_in : makes the image clickable. This option specifies in which part of the image the URL is stored. Can be either “alt” or “caption”. Default: no link
  • link_prefix : string to prepend to every URL. Useful if you reorganise your site: use this instead of visiting each image and changing the caption/alt text
  • referer : (sic!) each image has ?bid=‘imageID’ added to it so clicks can be tracked in the logs to see which are the most effective ads. Change the ‘bid’ text here to something of your choosing, or use referer=”“ to disable tracking. Default: bid (when link_in is used)

The details
When using category, you now have a load more options: as well as a standard list of categories, you can use any or all of the following options to pull information from the article currently being viewed:

  • ?c : to use the global category
  • !c : to exclude the category
  • ?s : to use the section
  • !s : to exclude the section
  • ?t : to use the article’s URL title (e.g. my-page-title)
  • !t : to exclude the URL title
  • ?id : to use the article’s ID. This item is prepended with the contents of id_prefix
  • !id : to exclude the article’s ID. This item is also prepended with id_prefix
  • ?field : use the question mark and any article field such as article_image, excerpt, keywords, etc to read the value from that field as a category list. The value in the field can be a single word or a comma-separated list of words to use as categories
  • !field : Same as ?field except it will exclude any categories found in the given article field

On its own that’s quite powerful but you can now also use any of the ‘?’ options in match_text and avoid_text as well. The ‘!’ options aren’t used because avoid_text is automatically an ‘exclude’ list.

All these matches are, by default, performed between the chosen items and the filenames of the images in the chosen categories. If you want to widen the search you can specify one or more of the following in the compare_to option:

  • name (for filename: the default)
  • alt (for checking alt text)
  • caption (for checking the caption text)
  • id (for comparing with the image ID)
  • category (for checking the image category)

There are loads of examples in the help file, but here are one or two to give you a flavour of what’s possible:

Example 1

<txp_random_banner category="animals, !s" subcats="1" limit="2" link_in="alt" />

Selects two random images from the ‘animals’ image category (and all its sub-categories) but won’t show any pictures from a category named the same as the currently viewed section. Great if you want to offer “read about other groups of animals”. Note also that link_in now tells the plugin to read the URL from the alt property of each image and make the image clickable.

Example 2

<txp_random_banner category="animals" subcats="1" match_text="pouch, ?s" avoid_text="?id, ?keywords" compare_to="alt, name, category, id" limit="5" link_in="caption" />

If a visitor was viewing a page with an ID of 39, this would look at all animal images (in all sub-categories) and look in each image’s alt, filename, category and id for a match. If it finds any text in any of those places that matches the word “pouch”, or the name of the current section but not the text “article-39” and not any of the words in the keywords field, then those images are shortlisted. The plugin will pull out a maximum of 5 images from that shortlist and make each clickable to the URL given in the caption field.

In the above example, id_prefix is by default set to “article-” and was prepended to the article ID. This is so you can have image category names that are more descriptive than just numbers.

You can even use the plugin on an article-list page, but of course you are limited to what you can do with the special codes because there’s no article to read the values from. Only ?s or ?c have any real meaning. If you use any of the others, they will be ignored. Note also that if you use the ?field or !field options and give the name of a field that doesn’t exist, the word you used will have the ? or ! removed and is then treated as a regular word.

The other options haven’t changed much in terms of functionality. link_in and link_prefix work a little better together: if you specify a full URL in the caption/alt (i.e. one that begins with http://) the value will be used verbatim; specifying a URL that begins with a ‘/’ is treated as a site-level link; everything else is assumed ‘local’ and will be relative to the current section. If you put a ‘full’ link in the image caption or alt, it will ignore any value in link_prefix.

referer works as before. Use referer="" to remove the link tracking functionality; change it to any other string to alter it from the default ‘bid’ (banner id).

Think that’s it for now. Go play and let me know how you get on…

Last edited by Bloke (2007-07-27 16:07:47)


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

#63 2007-02-26 13:08:27

DigitalRealm
Member
From: Greenville, SC
Registered: 2006-07-22
Posts: 139
Website

Re: smd_random_banner: Random banner image for advertising

Bloke,

Wow! Your new version has added some great features and flexibility! I am going to install in today and give it a go. I will let you know if I find anything weird.

Offline

#64 2007-03-04 04:01:54

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

Re: smd_random_banner: Random banner image for advertising

New version 0.21 out. Minor update to include support for net-carver’s awesome MLP. So now, if you have that extension pack installed, the plugin will show the image alt/caption info in the local language.

The latest version requires v0.2 of smd_lib, which is included in the zip file for convenience.

Download v0.21 of the plugin and shout if you have any issues or requests.

Last edited by Bloke (2007-07-27 16:08:27)


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

#65 2007-03-06 20:19:28

ragger
Member
From: Netherlands
Registered: 2005-04-10
Posts: 82
Website

Re: smd_random_banner: Random banner image for advertising

I just want to output a few random images in one category, so this plugin might be overkill. I will just give it a try though.
Thanks for your work.

Offline

#66 2007-03-06 20:30:49

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

Re: smd_random_banner: Random banner image for advertising

ragger wrote:

I just want to output a few random images in one category

If that’s all you want, you’re best off with dru_random_image (though I’m not sure if it works in 4.0.4… try it)

Last edited by Bloke (2007-03-06 20:35:08)


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

#67 2007-03-06 21:06:04

ragger
Member
From: Netherlands
Registered: 2005-04-10
Posts: 82
Website

Re: smd_random_banner: Random banner image for advertising

Yeah, I know, I saw that one. But t’s rather old and not supported anymore.

Offline

#68 2007-03-18 18:39:08

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

Re: smd_random_banner: Random banner image for advertising

New version out: smd_random_banner v0.22.

Adds one new convenience option: raw_url="1". This stops the plugin outputting a full <img> tag definition and just spits out the raw http://path/to/my/img.jpg URL of the chosen image. Really only of use in one circumstance (and when limit is left at the default of 1):

<style type="text/css">
  #myDiv { background: url(<txp:smd_random_banner category="animals" subcats="1" raw_url="1" />) no-repeat top }
</style>

That would apply a random background animal picture to myDiv. Very nice for headers of pages or semi-transparent background pictures that have position:absolute (or position:fixed in proper browsers!)

Using raw_url means that the imgclass, link_in, link_prefix and referer options are ignored.

I also took the opportunity to bundle the plugin with the latest version of smd_lib. It adds no new functionality to this plugin (yet…) so you don’t need to install it, but it just keeps things easier to manage my end if I know all the plugins are distributed with a common library.

Have fun with raw_url and shout if you have any issues/requests.

Last edited by Bloke (2007-07-27 16:08:15)


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

#69 2007-03-19 08:40:10

NeilA
Member
From: Blue Mountains, Australia
Registered: 2004-08-15
Posts: 316
Website

Re: smd_random_banner: Random banner image for advertising

Stef,

Thanks very much for adding that feature – I had just given up on using the plugin for a random banner where the graphic was placed via CSS.

Works very nicely, thanks!


Neil – Blue Mountains, Australia

http://westserve.org
http://ministrygrounds.net.au

Offline

#70 2007-03-22 22:42:45

Anton
Plugin Author
From: Alingsås, Sweden
Registered: 2004-11-16
Posts: 138
Website

Re: smd_random_banner: Random banner image for advertising

Works like a charm.

On a side note (and I know this is beyound the scope of this plugin), do anyone have any ideas of how to allow SWF-banners? These must first be allowed to be uploaded in the image area, right? Or is there a similar plugin for files that already handles this (and that I haven’t found yet)?

TIA

Offline

#71 2007-03-23 13:59:21

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

Re: smd_random_banner: Random banner image for advertising

Anton wrote:

On a side note (and I know this is beyound the scope of this plugin), do anyone have any ideas of how to allow SWF-banners?

I’ve not used it myself but does kml_flashembed fit your needs?


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

#72 2007-07-20 10:15:36

cdtavijit
Member
From: Malaysia
Registered: 2007-07-20
Posts: 14
Website

Re: smd_random_banner: Random banner image for advertising

Is there any way I can have an option for whether I want to target it to _blank, _parent blabla? I tried modifying the code, but well, it was a failure :p

Offline

Board footer

Powered by FluxBB