PDA

View Full Version : p28 Latest Images


HeavyEddie
06-11-2006, 12:51 PM
The purpose of this hack is to allow you to display the latest images from an image gallery section with the same name as the category the plugin is placed in.

I wanted to display screen shots for each project that I work on, but really didn't feel like cloning the image gallery, hack this plugin a wee bit and place it on EVERY project page. This allows me to simply slip the plugin to any project page. If there is an image gallery section with the same name... it displays the latest images from there.

Not sure if others will find this useful... but hey, I did :)


Here is what you need to do.

Open p28_latest_images.php and find this near line 12
**global $DB;


Replace it with this code
//! Hack START
**global $DB, $categoryid;
**$thiscatid = $categoryid;
//! Hack END



OK, now finde this code
****$images = $DB->query("SELECT imageid, sectionid, filename, author, title FROM " . TABLE_PREFIX . "p17_images
**************************WHERE activated = '1'".$extraquery." ORDER BY imageid DESC
**************************LIMIT 0, " . ($settings['Number of Images to Display'] + 1) . "");


Replace it with this
//! Hack START
********$catresult = $DB->query("SELECT * FROM " . TABLE_PREFIX . "categories WHERE categoryid = '" . $thiscatid . "'");
********$catname = $DB->fetch_array($catresult);
****$images = $DB->query("SELECT * FROM " . TABLE_PREFIX . "p17_sections as s LEFT JOIN " . TABLE_PREFIX . "p17_images as i ON s.sectionid = i.sectionid WHERE s.name = '" . $catname['name'] . "' ORDER BY i.imageid DESC LIMIT " . ($settings['Number of Images to Display'] + 1));
//! Hack END


Oky doky... thats it.

Thanks to subduck for original... excellent plugin.

spib
06-11-2006, 12:59 PM
Good stuff. Just one point in case you didn't know it, this code

$catresult = $DB->query("SELECT * FROM " . TABLE_PREFIX . "categories WHERE categoryid = '" . $thiscatid . "'");
********$catname = $DB->fetch_array($catresult);
Can be replaced by
$catname = $DB->query_first("SELECT * FROM " . TABLE_PREFIX . "categories WHERE categoryid = '" . $thiscatid . "' LIMIT 1");
query_first just gets the first result back for you. It's just a little tidier :).

Also, since you used a join anyway, why not just do this

$images = $DB->query("SELECT name FROM " . TABLE_PREFIX . "p17_sections as s LEFT JOIN " . TABLE_PREFIX . "p17_images as i ON s.sectionid = i.sectionid LEFT JOIN " . TABLE_PREFIX . "categories as c
ON s.name = c.name WHERE c.categoryid = '" . $thiscatid . "' ORDER BY i.imageid DESC LIMIT " . ($settings['Number of Images to Display'] + 1));

Good stuff though :)

HeavyEddie
06-11-2006, 02:40 PM
Being a bit lazy on the first one :)

2nd one... well, I'm always learning with the left, right and outer joins.

I have to say... you are good. Thanks for the tweakin & learnin :)

spib
06-11-2006, 03:14 PM
No problem, hope you didn't think I was being picky :) I just like to help out where I can

HeavyEddie
06-11-2006, 04:13 PM
Not at all... I love it actually, it only helps a person get better faster.

"He who learns from others is the most wise"
-unknown

HeavyEddie
06-11-2006, 05:18 PM
Noticed a small error in your SQL as well. The select statement is only refering to a single field. Works perfectly when I replaced it with an *

<div class='quotetop'>QUOTE(spib &#064; Jun 11 2006, 07&#58;59 AM) 6702</div>
Also, since you used a join anyway, why not just do this

&#036;images = &#036;DB-&#62;query&#40;&#34;SELECT name FROM &#34; . TABLE_PREFIX . &#34;p17_sections as s LEFT JOIN &#34; . TABLE_PREFIX . &#34;p17_images as i ON s.sectionid = i.sectionid LEFT JOIN &#34; . TABLE_PREFIX . &#34;categories as c
ON s.name = c.name WHERE c.categoryid = &#39;&#34; . &#036;thiscatid . &#34;&#39; ORDER BY i.imageid DESC LIMIT &#34; . &#40;&#036;settings&#91;&#39;Number of Images to Display&#39;&#93; + 1&#41;&#41;;
[/b]


Itty bitty change...

&#036;images = &#036;DB-&#62;query&#40;&#34;SELECT * FROM &#34; . TABLE_PREFIX . &#34;p17_sections as s LEFT JOIN &#34; . TABLE_PREFIX . &#34;p17_images as i ON s.sectionid = i.sectionid LEFT JOIN &#34; . TABLE_PREFIX . &#34;categories as c
ON s.name = c.name WHERE c.categoryid = &#39;&#34; . &#036;thiscatid . &#34;&#39; ORDER BY i.imageid DESC LIMIT &#34; . &#40;&#036;settings&#91;&#39;Number of Images to Display&#39;&#93; + 1&#41;&#41;;

Thanks again... I&#39;ve put your changes into action.

spib
06-12-2006, 12:41 PM
Haha, yeah my mistake. Good work.

alanmi2
10-23-2006, 12:53 AM
i need a mod to convert latest to random images? can someone help??

HeavyEddie
10-23-2006, 03:00 AM
Just so I understand the request perfectly... You would like this to randamally display images from a image gallery category with the same name as the gallery the plugin is placed.

Yeah, we can do that. Give me a few days and remind me. That is if someone else here doesn't do it before hand.

alanmi2
10-23-2006, 07:59 PM
Just so I understand the request perfectly... You would like this to randamally display images from a image gallery category with the same name as the gallery the plugin is placed.

Yeah, we can do that. Give me a few days and remind me. That is if someone else here doesn't do it before hand.
i would like a mod to p28 latest images plugin that does exactly the same, just random images instead of latest images, tnx for the quick answer, sorry 4 my english jeje

HeavyEddie
10-23-2006, 11:26 PM
OK, I will take a gander later in the week. Just remind me if you would be so kind :)

alanmi2
10-24-2006, 07:06 AM
ok, tnx, i will remind you, everyday if a had to, jaja just kiding

kboy_16
11-03-2006, 03:25 AM
is it ready?..

alanmi2
11-03-2006, 10:30 PM
nop, forget to remind, HeavyEddie???

kboy_16
12-07-2006, 05:11 AM
heavyeddie? did u made it?