Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#256 2008-10-31 15:04:35

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,493
Website GitHub

Re: smd_gallery: super-flexible gallery generator

spgriffee wrote:

This sounds very interesting. Let me see if I have it right: <snip>

Yes, you have it right :-)

The crucial parts are:

  1. the mod_rewrite adds the ?pic variable internally (behind the scenes) leaving the browser URL bar untouched, showing a nice, shiny permlink-looking URL to visitors. All javascript-free
  2. Your story-name article (or attached form thereof) does all the hard work decoding the hidden ?pic=whatever bit, fetching the image and displaying it
  3. The next/prev, as you say, might be tricky. I’ve not thought it through because I don’t think there are tags that allow you to natively grab the next/prev image. However, through judicial use of the paging and limit="1" attributes, you might be able to coax smd_gallery into working out which image is next in line.

If the next/prev doesn’t work you might have to resort to some trickery. Off the top of my head we might be able to fashion some SQL query to get what you want (either directly in PHP or via smd_query?) or use some more plugins (e.g. wet_for_each_image or smd_each) to iterate over a dynamically-generated list of all images in the category until it finds the current pic; at that point it renders a link to the image either side. There’s probably a far better way of doing it than using smd_each; that’s like using a blunderbuss to win a round of golf: it’ll work if you point it at the opposition and shoot, but won’t win you any style points or reduce your handicap.

Breaking other parts of the site with the .htaccess mod_rewrite rule

The rule itself can target a specific section (which is why I suggested putting all this gubbins in its own section), thus not impacting anything else much… it will take a fraction of a second longer to read and process the rule, and decide whether to take action or not, but apache can comfortably handle it.

Do you have any tips on how to write the rule itself?

Not without trying it, sorry. I’m no mod_rewrite guru but something along these lines might be a starting point:

RewriteRule /stories/(.*)/(.*) /stories/$1/?pic=$2

So in theory, any article in the stories section that has two parts after it separated by a slash is changed to point at the given story-name ($1: the first part) and has the 2nd part added as a URL variable. If you Google for mod_rewrite tutorials there’s usually an example that exactly matches the type of thing you’re trying to do which you can copy ‘n’ paste!

Performance hit.

The rewrite itself fires for every page request and thus takes a (tiny) fraction longer to determine whether to act on the page or not. But TXP is doing that anyway for every page so you’re unlikely to notice.

Every extra tag that does SQL stuff (and every client-side plugin) adds a performance hit so you will want to minimise the number of tags on your page, as normal when worrying about render speeds. Again, there are so many other tags that just one more won’t make much difference. You’ll only be calling one smd_gallery per page — one in the ‘true, I have found a ?pic variable’ case, or one in the ‘else’ part — and the good news about smd_if (despite its ugliness) is that all its processing is done after any SQL calls so it does not go back to the database for anything. For a simple one-var check you’d be hard pushed to be able to click the stopwatch accurately enough to detect the extra time it takes to check the existence of the variable. I think your site is safe ;-)

If you want any further clarification or ideas, feel free to post what you have working (or not…) and either me or someone with greater brain capacity will endeavour to help you out.


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

#257 2008-10-31 15:15:11

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,493
Website GitHub

Re: smd_gallery: super-flexible gallery generator

curiouz wrote:

but comma’s don’t work in combo’s.

Have you tried setting delim to something other than comma; like delim="::" or delim="_,_"? It’ll mean going back to your smd_gallery tag and changing any comma-delimited options to something else but it might allow that deliciously complicated combo to be parsed correctly ;-)

If that doesn’t work, shout back and I’ll look into it deeper to try and replicate what you’re doing on my test site.

Last edited by Bloke (2008-10-31 15:16:46)


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

#258 2008-10-31 15:59:01

mlarino
Member
Registered: 2007-06-29
Posts: 367

Re: smd_gallery: super-flexible gallery generator

Man! thanks!
Worked perfect!!
Great job with this plugin!

Offline

#259 2008-11-02 10:09:19

spgriffee
Member
Registered: 2004-12-21
Posts: 38
Website

Re: smd_gallery: super-flexible gallery generator

“There’s probably a far better way of doing it than using smd_each; that’s like using a blunderbuss to win a round of golf: it’ll work if you point it at the opposition and shoot, but won’t win you any style points or reduce your handicap.”

Laughing!

Thanks for your detailed and entertaining response, Stef!
I’m going to take a crack at this (doing my best to avoid blunderbusses) and will report here soonest.

Cheers!

Offline

#260 2008-11-05 22:21:43

progre55
Member
Registered: 2006-05-02
Posts: 668

Re: smd_gallery: super-flexible gallery generator

Bloke:

Hope all is well.

Not sure if it is out there (ok I am sure but have not found it) and I have tried several solutions with non really doing the trick in a clean manner. I want to take your plug in and integrate it into an automatic slideshow. Unlike slimbox (which I use on alot of my projects), I want the slideshow to run automatically.

Any and all insight you or the rest of the group may have would be appreciated.

progre55

Last edited by progre55 (2008-11-05 22:22:01)

Offline

#261 2008-11-05 22:30:08

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,493
Website GitHub

Re: smd_gallery: super-flexible gallery generator

progre55 wrote:

I want to take your plug in and integrate it into an automatic slideshow…. to run automatically.

Have you looked at using jQuery Cycle? I’ve used it successfully with smd_gallery on a few projects. If you just want the fadey effect, there’s cycle lite which is much easier to get going.


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

#262 2008-11-06 13:20:48

progre55
Member
Registered: 2006-05-02
Posts: 668

Re: smd_gallery: super-flexible gallery generator

Bloke:

Thanks for the quick reply. I guess I was hoping for something more along the lines of what HP has on their website where you have some controls, as well as the capability to jump around.

progre55

Offline

#263 2008-11-06 13:52:22

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,493
Website GitHub

Re: smd_gallery: super-flexible gallery generator

progre55 wrote:

I was hoping for something more along the lines of what HP has on their website where you have some controls, as well as the capability to jump around.

Well if you find out which tool they have used (assuming it’s a third party one and not custom built) you can download it and integrate it. Or steal that one off their site! It’s only divs, js, an image map and some css. smd_gallery will most likely work, with a bit of ingenuity!

First task is to pick the tool/effect you want to use, then asses how easy it is to make smd_gallery get the graphics into it.


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

#264 2008-11-06 14:02:52

progre55
Member
Registered: 2006-05-02
Posts: 668

Re: smd_gallery: super-flexible gallery generator

Bloke:

I will do some digging and maybe with the some of your expert assistance I can get it moving in the right direction. To be continued …..

progre55

Offline

#265 2008-11-11 06:11:34

mcx
Member
Registered: 2008-11-11
Posts: 12

Re: smd_gallery: super-flexible gallery generator

Great stuff Stef!

However my newbiness prevents me from using all but the most basic of features… I was hoping that someone would be able to point my in the right direction on loading the related images for an article dynamically.

I have the plug-in working up to the point where the correct images load if the <txp:smd_gallery… > tag is place in the article, but once I try to place the tag in either a page or a form (swapping out the static category attribute for a dynamic”?” attribute), it all heads south.

I have tried to emulate a set-up from another plug-in by categorizing the images by the article number to which are associated (e.g. “30”), then using the <txp:smd_gallery category=”?id” form=“gallery” debug=“1”> in either the default page or form.

I suspect that I missing something about the textpattern’s method of retrieving the article id or the correct use of the dynamic id retrieval system. I am pretty sure I will be kicking myself when the answer comes around, moreso if there is a simpler, more refined method achieving the same result.

Thanks for you patience and consideration!

Last edited by mcx (2008-11-11 12:28:26)

Offline

#266 2008-11-11 09:20:42

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,493
Website GitHub

Re: smd_gallery: super-flexible gallery generator

mcx wrote:

using the <txp:smd_gallery category=”?id” form=“gallery” debug=“1”> in either the default page or form.

Hi mcx. No, you’re not missing anything, that should work (assuming you have the trailing / in the tag on your site). It works on my test site.

What sort of thing do you see in the debug output? You should see a line that starts with 1=1. Under that you should see a REPLACEMENTS section with each of your matching images listed and a load of junk about each one. If all you’re seeing is array() then for some reason the plugin is not pulling out the correct info. Post what you see and I’ll try and figure it out.

If all that looks ok and the first part is pulling the correct stuff out of the database, the next thing to look at is the form. What is the content of your gallery form? And you’re using v0.45 of the plugin, yes? (I still haven’t fixed the id attribute bug that I *cough* fixed badly from 0.44, but it shouldn’t affect you here because you are using category).

You’re approach seems sound and logical. The default form is the right place for the tag, and keying the image category off the article ID is a great way to make “auto galleries” that expand if you add new images. There are other ways, but they all involve an extra step and/or nominating another field to hold the category name, so yours is by far the most efficient method.

So at the moment I’m a bit flummoxed, sorry.


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

#267 2008-11-11 10:52:47

kemie
Plugin Author
From: mexico<-->sweden
Registered: 2004-05-20
Posts: 495
Website

Re: smd_gallery: super-flexible gallery generator

progre55 wrote:

Bloke:

Thanks for the quick reply. I guess I was hoping for something more along the lines of what HP has on their website where you have some controls, as well as the capability to jump around.

progre55

Hey, progre555, the jquery cycle plugin can be made to have controls.
take a look at their advanced demos

i have implemented cycle with pagers/prev next several times, including in my portfolio (shameless plug)

I’d be happy to help out if you have any questions


~~~~~~~~~~~~~| monolinea.com | pixilate.com | istockphoto.com/kemie |~~~~~~~~~~~~~

Offline

#268 2008-11-11 12:06:54

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_gallery: super-flexible gallery generator

smd_gallery + smd_if = lot of fun = the infinite is the limit


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#269 2008-11-11 12:10:50

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,493
Website GitHub

Re: smd_gallery: super-flexible gallery generator

maniqui wrote:

smd_gallery + smd_if = lot of fun = the infinite is the limit

Another satisfied customer :-)


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

#270 2008-11-11 12:25:45

mcx
Member
Registered: 2008-11-11
Posts: 12

Re: smd_gallery: super-flexible gallery generator

Thanks for the speedy reply Stef – much appreciated!

So I’ve gone through it once more, but have not been able to spot any obvious discrepancies.

Please have a look at the following and let me know where I am getting blind-sided.

In the “default” form:
<txp:smd_gallery category=”?id” sublevel=“1” form=“gallery” debug=“1” />

The “gallery” form:
<a rel=“lightbox-{category}” href=”{url}” alt=”{alt}” title=“A picture of {title}” height=”{height}” width=”{width}”> <txp:thumbnail id=”{id}” />
</a>

With in the <head> tag of the “default” page:
<script type=“text/javascript” src=”/js/mootools.js”></script> <script type=“text/javascript” src=”/js/slimbox.js”></script> <link rel=“stylesheet” type=“text/css” href=”/css/slimbox.css” />

With this combination the debug prints:
“++ WHERE CLAUSE ++
txp_image.category = “smd_1053391178” ORDER BY txp_image.category asc
select txp_image.name,txp_image.id,txp_image.alt,txp_image.caption,txp_image.category,txp_image.author,txp_image.date,txp_image.ext,txp_image.w,txp_image.h,txp_image.thumbnail, txp_category.title AS category_title from txp_image, txp_category where txp_category.name = txp_image.category AND txp_category.type=“image” AND txp_image.category = “smd_1053391178” ORDER BY txp_image.category asc LIMIT 0,99999”
x5 – with different “smd_…” for each.

I have seen the “1=1” debug output during my various trials but forget by which combination it was produced.

Thanks again for your support!

Last edited by mcx (2008-11-11 12:26:42)

Offline

Board footer

Powered by FluxBB