Pixelpost

Authentic Photoblog Flavour


Go Back   Pixelpost Forum > DEVELOPMENT > Hacks and Modifications

Post Reply
 
Thread Tools
  #1  
Old 08-27-2007, 09:20 AM
iaredatsun Offline
forum loafer
 
Join Date: Aug 2007
Posts: 6
A simple random front page image hack

Problem: showing a random picture each time the home page is first loaded.
(Of course this should not effect the loading of images from the browse page.)

I know this has been discussed before but no one seemed to come up with a satisfactory answer to this functionality. Usually people suggested some modification of the site structure with index2.php and random folder image method.

My method is a simple one line modification to the index.php file

line 333 of orginal index.php -

change:

$row = sql_array("SELECT * FROM ".$pixelpost_db_prefix."pixelpost WHERE datetime<='$cdate' ORDER BY datetime DESC limit 0,1");

to:

$row = sql_array("SELECT * FROM ".$pixelpost_db_prefix."pixelpost WHERE datetime<='$cdate' ORDER BY rand() asc limit 0,1");

This will only effect the page when it loaded with no PHP arguments - i.e. only when someone first goes to the site and not when things are accessed from the thumbnails page.

Please note that I think this will only work if you are not logged in as admin. I think modifying that would be simple too.

I'm totally new to this but I have tested this a few times and it seems to work fine - at least for me. Any comments?

Mr.Datsun
Reply With Quote
  #2  
Old 08-28-2007, 05:14 PM
witty's Avatar
witty Offline
pp veteran
 
Join Date: Mar 2007
Posts: 72
Hi,

Works well for me too. Although, I have a link on my front page called "Latest Image", which for now is set with a 'href' point to index.php. If I could change that so that the 'href' really did point to the latest image, that would be ideal. Any ideas?

Right now, the URL to my most recent image is:

http://domain.com/index.php?showimage=91

So how can I change the 'href' to be a variable that would use the most recent image and use that for my "Latest Image" link? That way, on the initial page load, visitors would get a random image, but when they clicked on "Latest Image" visitors could start from the beginning of the blog. Thanks!


-Witty
__________________
Reply With Quote
  #3  
Old 08-28-2007, 08:33 PM
iaredatsun Offline
forum loafer
 
Join Date: Aug 2007
Posts: 6
Quote:
Originally Posted by witty View Post
So how can I change the 'href' to be a variable that would use the most recent image and use that for my "Latest Image" link? That way, on the initial page load, visitors would get a random image, but when they clicked on "Latest Image" visitors could start from the beginning of the blog. Thanks!
There's a line that gets the total image count and stores it in $pixelpost_photonumb. You should be able to use that to create a dynamic link.

My guess is that you put <SITE_PHOTONUMBER> in your template where the latest photo number should go in your url string. Try that.

<SITE_PHOTONUMBER> gets replaced by the number of photos in the database ($pixelpost_photonumb). But I don't know what happens if a photo has been deleted as I don't know if it uses a unique id or a number to retrieve images. That's the current limit of my knowledge.
Reply With Quote
  #4  
Old 08-29-2007, 04:56 PM
witty's Avatar
witty Offline
pp veteran
 
Join Date: Mar 2007
Posts: 72
Hi,

You're definitely on the right track. While <SITE_PHOTONUMBER> is in fact the total number of photos, it is not the unique ID number that is used to identify each photo. The tag we're looking for is <IMAGE_LAST_ID>. I tested it and it works. Thanks iaredatsun!


-Witty
__________________
Reply With Quote
  #5  
Old 08-30-2007, 12:08 PM
witty's Avatar
witty Offline
pp veteran
 
Join Date: Mar 2007
Posts: 72
Hi,

I'm not sure why yet, but this hack appears to "break" (including my modification to show <IMAGE_LAST_ID>) when you're logged in as Admin and viewing the blog.... works fine otherwise.


-Witty
__________________
Reply With Quote
  #6  
Old 08-31-2007, 03:57 PM
iaredatsun Offline
forum loafer
 
Join Date: Aug 2007
Posts: 6
Quote:
Originally Posted by witty View Post
Hi,

I'm not sure why yet, but this hack appears to "break" (including my modification to show <IMAGE_LAST_ID>) when you're logged in as Admin and viewing the blog.... works fine otherwise.


-Witty
I think I know why. But how does it break exactly?

I only hacked the section where the user is not logged in as admin. I figured that as admin it may be better to see the latest photo than to keep getting a random image when you are testing the site.
Reply With Quote
  #7  
Old 09-04-2007, 02:35 PM
witty's Avatar
witty Offline
pp veteran
 
Join Date: Mar 2007
Posts: 72
Hi,

It (talking about the <IMAGE_LAST_ID> tag) leaves off the image number in the following URL:

http://domain.com/index.php?showimage=91

So it looks like this when it breaks:

http://domain.com/index.php?showimage=

and says this:

Quote:
Not Found
Don't do that! go back to index.php!
And the "randomness" stops being random... only displaying the latest image over and over.

For me, now that I know WHY it breaks, it doesn't really matter. As long as it works for non-admin visitors, that's all I care about.


-Witty
__________________
Reply With Quote
  #8  
Old 01-17-2008, 06:30 AM
Marx Offline
forum loafer
 
Join Date: Aug 2006
Location: Belgium somewhere near Brugge
Posts: 7
Just wondering.. does this also work with V1.7.1?
(cant find the code used here)
Reply With Quote
  #9  
Old 01-21-2008, 01:02 PM
Marx Offline
forum loafer
 
Join Date: Aug 2006
Location: Belgium somewhere near Brugge
Posts: 7
In V1.7.1 at line 424 I see
$row = sql_array("SELECT * FROM ".$pixelpost_db_prefix."pixelpost WHERE datetime<='$cdate' ORDER BY ".$cfgrow['display_sort_by']." ".$display_order." limit 0,1");
Could some one tell me what I need to adjust to get it workin?
Thanks.
Reply With Quote
  #10  
Old 01-22-2008, 12:00 AM
jaywilliams's Avatar
jaywilliams+ Offline
Team Pixelpost
 
Join Date: Sep 2005
Posts: 1,003
Send a message via AIM to jaywilliams Send a message via MSN to jaywilliams Send a message via Yahoo to jaywilliams Send a message via Skype™ to jaywilliams
Quote:
Originally Posted by Marx View Post
In V1.7.1 at line 424 I see
$row = sql_array("SELECT * FROM ".$pixelpost_db_prefix."pixelpost WHERE datetime<='$cdate' ORDER BY ".$cfgrow['display_sort_by']." ".$display_order." limit 0,1");
Could some one tell me what I need to adjust to get it workin?
Thanks.
In v1.7.1 its on Line # 423
__________________
Jay Williams | A Different View
Reply With Quote
Post Reply


Thread Tools




All times are GMT. The time now is 03:47 PM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd. | Style Design: d3 designs