You are not logged in.
I’ve looked around, but can’t figure out how it might be possible (via plugin or otherwise) to form the url for multiple article_image pages with each image’s id
or name (instead of the page number)? It still would need to work with next/previous links.
Currently the url for each page/image looks like this:
However, I’m envisioning something along the lines of an article-specific image permalink, where each page/image url remains tied to the image, even if the order of the images is changed in the article_image field (or, by any sort order).
I’m using the following code in my page to call the images:
<txp:article> <txp:images autodetect="article" limit="1" pageby="limit"> <img src="<txp:image_url />" /> </txp:images> </txp:article>
Any thoughts? Thanks!
Last edited by photonomad (2012-01-16 17:20:43)
Ok, so it looks like a bunch of people have seen my question, but no remarks thus far. Am I way off-base? Am I missing something completely obvious? If this is the case, then I am really sorry!
If this isn’t the case, then maybe I should explain in more detail:
A) I am using an article as a portfolio/image gallery. I anticipate that more images will be be added to the article periodically in the future and some images may be deleted as well. The order of the image in the gallery will be affected when these changes take place. As the pages are indexed by search engines, it would be nice if the urls would stay constant even when the page order changes.
B) Same issue affects social media linking: If a Facebook Like Button is tied to the url of each image page in a gallery and then the image order changes the urls, the open graph stats and like counts for each image will be lost.
Would it be possible via .htaccess or maybe a future plugin or something, to run the page numbers for an article through some type of behind the scenes code in order to swap them with the image id#s so that the URLs for image pages in multi-page image lists (i.e. <txp:images limit=“1” pageby=“limit” />) will be more permanent, seo and social media friendly?
If this were to become possible, I suppose there would have to be a way to construct the links to next and previous images in the list… maybe via special nextimg previmg tags…
Last edited by photonomad (2012-01-16 17:23:57)
This is a bit of a guess based on what you wrote and the website in your profile where you also have
/?pg=5&image=storm-on-the-paja in your url.
You can use adi_gps to capture the
image url variable and then do something with it. The txp tags txp:images, txp:image and txp:image_info will also accept the image
name as an attribute instead of the
id and assuming that all your photos are .jpg images you could use your
image url variable to display the image, e.g. something like:
<txp:adi_gps name="image" quiet="1" /> <txp:if_variable name="image" value=""> <!-- no image specified: show landing page view --> <txp:else /> <txp:images name='<txp:variable name="image" />.jpg'> <img src="<txp:image_url />" /> </txp:images> </txp:if_variable>
You can then leave out the pg variable so you generate an url like
/gallery-name/?image=name-of-image. It’s a messy url but that’s okay for google, social media sites etc.
Theoretically you could use an
.htaccess RewriteRule to make this a clean url – or alternatively gbp_permanent_links – but you may need to adjust the url scheme you’re using at present.
There are two caveats here:
My article_image field contains this list: 245,239,246,238,237,251,243,241,244,236,242,250,247,240,248,249
What is the easiest way to figure out that 241 is previous and 236 is next for image id 244?
My brain fails me. I’ve way over thought it and right now (temporary link to test example) I am using all sorts of variables to create the next/previous links that ultimately fail when I get to the first and last image. FYI: The next/prev links appear when mouse hovers over the image.
Painfully, here’s a peak at all the variables I’m using to try and make it work:
Above the head:
<txp:adi_gps name="image" quiet="1" />
<txp:variable name="count" value="0" />
<txp:smd_if field="urlvar:image" operator="undefined"><txp:else />
<txp:images break="" sort='FIELD(ID,<txp:custom_field name="article_image" />)'>
<txp:adi_calc name="count" add="1" />
<txp:variable name='<txp:image_info type="id" />' value='<txp:variable name="count" />' />
<txp:variable name='<txp:variable name="count" />' value='<txp:image_info type="id" />' />
<txp:adi_calc name='<txp:variable name="image" />' subtract="1" result="prevseqn" />
<txp:adi_calc name='<txp:variable name="image" />' add="1" result="nextseqn" />
<txp:adi_calc name='<txp:variable name="prevseqn" />' result="previmg" />
<txp:adi_calc name='<txp:variable name="nextseqn" />' result="nextimg" />
In the page for the image in and next/prev links (left out superflous divs/styling):
<txp:images id='<txp:variable name="image" />'>
<img src="<txp:image_url />" />
Next image link:
<a class="next thumb-link" href="<txp:site_url /><txp:article_url_title />/?image=<txp:variable name="nextimg" />&name=<txp:mta_sanitize><txp:image_info id='<txp:variable name="nextimg" />' type="alt" /></txp:mta_sanitize>" title="view next image"></a>
Previous image link:
<a class="prev thumb-link" href="<txp:site_url /><txp:article_url_title /><txp:if_variable name="prevseqn" value="0"><txp:else />/?image=<txp:variable name="previmg" />&name=<txp:mta_sanitize><txp:image_info id='<txp:variable name="previmg" />' type="alt" /></txp:mta_sanitize></txp:if_variable>" title="view previous image"></a>
Last edited by photonomad (2012-01-17 15:58:43)
Yes, I was thinking about that too. Will the tactic of using the next number always work if the images are not consecutive?
Another idea albeit entirely untested: Did the previous way you created the image list with txp:images and
pg= variable always produce the right links to the next/prev image even if not consecutive? If so, maybe you can use that to create your thumbnails and next/prev image links and then simply rewrite the output it produces to replace the url variable with your own variable name, e.g.:
<a href="<txp:rah_replace from="pg=" to="image="><!-- your link tag here --></txp:rah_replace>">next</a>
(or something along those lines).
EDIT: ah, scratch that. I just realised that the pg= variable doesn’t correspond to the actual image id number.
Last edited by jakob (2012-01-17 17:40:20)
Thanks for taking a stab, Jakob! This is tough… The code I posted above does work (except for the previous/last images), but it seems so convoluted to use all of those variables within variables, etc.
Would there be a way to find the next/previous values with some raw php and regex?
Probably you can do it with some raw php by converting your comma-separated list in your article_image field into an array (a list of items) with php using explode(), then using array_search() to find the position you are in the array based on the value of the
image url variable (i.e. the current image). You can then use php’s next() and prev() to return the image id numbers of the previous and next images in the array. Written out in words that looks a lot but it should only require a few lines.
Note, you can store the results as txp variables in php as described in this thread. Further down in your code you can then use the txp:variables you created as normal to create your actual links.
I have to rush now, so I can’t look in any more detail but maybe you’ll find some more pointers here.
Last edited by jakob (2012-01-17 18:06:00)
I’m with jakob: ditch the plugins and use some PHP:
<txp:php> global $variable, $thisarticle; $imgs = do_list($thisarticle['article_image']); $currimg = (int) gps('image'); $found = ($currimg) ? array_search($currimg, $imgs) : 0; $variable['curr_image'] = $found; $variable['prev_image'] = ($found < 1) ? '' : $found-1; $variable['next_image'] = ($found >= count($imgs)-1) ? '' : $found+1; </txp:php>
PREV: <txp:variable name="prev_image" /> CURR: <txp:variable name="curr_image" /> NEXT: <txp:variable name="next_image" />
It’s a 5-minute dirty beast, but it works.
EDIT: Added (int) cast as per Gocom’s recommendation below.
Last edited by Bloke (2012-01-18 09:17:25)