Pixelpost Forum

Pixelpost Forum (http://www.pixelpost.org/forum/index.php)
-   Hacks and Modifications (http://www.pixelpost.org/forum/forumdisplay.php?f=16)
-   -   A simple random front page image hack (http://www.pixelpost.org/forum/showthread.php?t=7094)

iaredatsun 08-27-2007 09:20 AM

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

witty 08-28-2007 05:14 PM

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

iaredatsun 08-28-2007 08:33 PM

Quote:

Originally Posted by witty (Post 49437)
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.

witty 08-29-2007 04:56 PM

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

witty 08-30-2007 12:08 PM

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

iaredatsun 08-31-2007 03:57 PM

Quote:

Originally Posted by witty (Post 49482)
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.

witty 09-04-2007 02:35 PM

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

Marx 01-17-2008 06:30 AM

Just wondering.. does this also work with V1.7.1?
(cant find the code used here)

Marx 01-21-2008 01:02 PM

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.

jaywilliams 01-22-2008 12:00 AM

Quote:

Originally Posted by Marx (Post 53759)
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


All times are GMT. The time now is 05:18 PM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.