Pixelpost: Constraining Archive Searches
By Al Andersen on Tuesday, 2010-01-12, 19:42 - Pixelpost - Permalink
A modification to Pixelpost that enables image filtering of not only categories on your main page, but also archives and tags.
Introduction
The Pixelpost FAQ states that in order to use selected categories for the images on my main page, I should install the GeoS Show Category addon. I tried it, and while it looks to be a rather nice addon I wasn't happy with the fact that it mucked with my database. So, I looked at how the archive/browse code worked and realized that if the proper parameters were passed via the URL, it would be a simple matter to view categories on the main page... and more! Yes, it will be a bit of work, but I think you'll find the time spent making this modification is well-worth the effort.
The aim of this modification is to enable filtering of not only categories on your main page, but also archives and tags. The way we do it is to modify the thumbnail and tag links on the archive/browse page to pass the appropriate parameter (archivedate, category, or tag). We retrieve this parameter on our main page and use it to filter our SQL queries, links, and thumbnails. There's no need for additional changes to the database. Everything is passed by URL and two simple function calls determine which URL parameter is passed and what where constraint to add to our SQL.
I don't see a way to make this modification into a plugin for the current version of Pixelpost (1.7.3). Therefore you will need to make direct changes to the code. 5 files are modified. The first four are simple modifications (you can make them in a couple of minutes). The last file (index.php) requires quite a few insertions of a variable into the SQL and links. Still, it's not all that difficult and should take you somewhere between 10 to 30 minutes to complete, depending on how familiar you are with PHP coding. Just back up your files and also backup each line you're changing (duplicate the line and then comment one of them out).
Programming Comment
I detest PHP's concatenation symbol (the period). My editor uses periods to denote tabs. Therefore, it is very difficult for me to distinguish between periods and tab symbols. Also, I strongly disagree with the standard practice of using single quotes (') to enclose strings. I prefer to use double quotes (").
I bring this up because I use the {} delimiters to enclose variables inside of strings. To use these delimiters, you need to use double quotes for strings. So, instead of doing something like $a = 'There are ' . $x . 'items in a dozen' I instead use $a = "There are {$x} items in a dozen". Your delimited variable ({$x}) must be a variable -- no function calls are allowed inside the delimiters.
Some of the code below uses these {} delimiters. Now you know what they do. I recommend you don't change anything until after you make the cited modifications and ensure everything works. Only then should you go ahead and change things to your own style of coding.
Modifications
This blog format isn't sufficient to display the necessary coding changes. I've place them into a text file attachment which I encourage you to download at this time.
Conclusion
That's it!
Now, when you use archive/browse your results are made part of the thumbnail and tag URLs. When you click on the thumbnail or tag, images on your main page will be constrained to the archivedate, category, or tag you chose.
The constraint remains in effect until:
A) You go back to archive/browse and choose a different constraint.
B) You click on your site title, which takes you back to the most current photo. The URL for this is http://yoursite/ and seeing as there are no parameters, all constraints are removed.
Enjoy!
Comments
thanks so much for this. works great.
I was wondering if you've thought about a way to show the Category/tag/archive filter when you are viewing it. For example show "you are viewing the category: landscapes" when you are viewing that category? That would be a great addition to this modification. I've been going through the code trying to figure out a way to do it, but I'm a novice, so I can't figure it out.
Surprisingly, most of the work is already done for you, it's just not implemented anywhere.
Look in index.php at lines 779, keyword <IMAGE_CATEGORY> and line 782 <IMAGE_CATEGORY_PAGED>. Put one of these into the template you want to use, for example, I use the simple template and have <IMAGE_CATEGORY_PAGED> in my image_template.html file (look at my photo info & comments section).
Please note that putting the tag on your page will show the category assigned to that photo, regardless whether you're constraining your photos to a tag or category search!
I have not tried this with multiple categories, so depending on what you want displayed, this may or may not work for you.