Not signed in (Sign In)

Vanilla 1.1.10 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorJrnymnJay
    • CommentTimeNov 23rd 2005 edited
     
    I've made Plogger random thumbnails display on the front page using the code below. Clicking on the images takes you right to it's location in the album flawlessly. Credit to theg3nius for posting the code over here --> http://theg3nius.com/wordpress/2005/10/10/plogger-add-in-script/
    for me to tinker with.

    <?php
    $host="hostname";
    $username="username"; //Database username here
    $password="dbpassword"; //Database password here
    $database="dbname"; //Database name here
    $amount="6"; //How many images do you want shown?
    $siteurl="http://yoursite.com/ploggerdirectory"; //The URL of your Plogger directory E.G. http://yoursite.com/ploggerdirectory ***IMPORTANT*** DO NOT INCLUDE A TRAILING SLASH LIKE THIS http://yoursite.com/ploggerdirectory/

    //Database Connection
    $connection = mysql_connect($host, $username, $password);
    $db = mysql_select_db($database);

    $q = "SELECT * from plogger_pictures order by RAND() LIMIT $amount";
    $result= mysql_query($q) or die
    ("Could not execute query : $q." . mysql_error());

    while ($row=mysql_fetch_array($result))
    {
    $id=$row["id"];
    $path=$row["path"];

    $number=strrpos($path, '/');
    $number=$number+1;
    $url=substr($path, $number);

    ?>
    <a href="<? echo "$siteurl"; ?>/index.php?level=picture&id=<? echo "$id"; ?>"><img src="http://yoursite.com/ploggerdirectory/thumbs/<? echo "$id"; ?>-<? echo "$url"; ?>" border="1" style="border-color:black"></a>
    <?php } ?>
    •  
      CommentAuthorCroila
    • CommentTimeNov 23rd 2005
     
    Many thanks for this - I've just implemented it, and am very pleased with it! :-)

    Kind regards,
    Croila
    • CommentAuthorsonria
    • CommentTimeJan 5th 2006
     
    I just implemented it over on my front page. Very easy, works like a charm. Thank you!
    • CommentAuthorBouley86
    • CommentTimeJan 19th 2006
     
    wouldn't it also make sense (and be slightly easier) to change this:

    <img src="http://yoursite.com/ploggerdirectory/thumbs/<? echo "$id"; ?>-<? echo "$url"; ?>" border="1" style="border-color:black">

    to this:

    <img src="<? echo "$siteurl"; ?>/thumbs/<? echo "$id"; ?>-<? echo "$url"; ?>" border="1" style="border-color:black">

    just to keep everything consistent? just a thought :)
    • CommentAuthorshutterbug
    • CommentTimeJan 20th 2006
     
    Where does this code need to be entered? On home page?
    • CommentAuthorddejong
    • CommentTimeJan 20th 2006 edited
     
    First, I would suggest getting rid of your shorttags, and also enveloping the whole snippet into one echo statement.

    <?php echo '<img src="$siteurl/thumbs/$id-$url" border="1" style="border-color:black">n'; ?>

    It greatly improves legibility and keeps it less prone to server config frustrations.

    Secondly, if you are going to use shorttags, I would suggest using ASP-style with the "=" sign.

    Keeping in mind this is almost all stylistic, and doesn't affect page rendering that much (although echo() does take execution time, and multiple calls take more, afaik).

    Regards,
    Derek
    • CommentAuthorskeeboo
    • CommentTimeJan 22nd 2006
     
    What a great little script. Thanks for sharing it. Is it possible to have it display random images within a specific album?

    For example, if my Plogger had two albums; Vacations and Cats, and I had two sections on my site dedicated to Vacations and Cats, I'd like to pull random cat images in the cats section and random vacation images from the vacation section.

    An easy workaround would be to just set up two Ploggers, for each album and use two copies of this script to pull from each database. That's doable, but it would be nice to see if this can pull random images from one database based on category/album title.
  1.  
    Can i modify it so it show the latest added images?
    •  
      CommentAuthormike
    • CommentTimeJan 25th 2006 edited
     
    Broderbluff,

    Just change the query in the script

    $q = "SELECT * from plogger_pictures order by RAND() LIMIT $amount";

    to

    $q = "SELECT * from plogger_pictures order by `id` DESC LIMIT $amount";

    That will show $amount of the latest pictures.
  2.  
    thanks a lot =)
    • CommentAuthornissai
    • CommentTimeMar 11th 2006
     
    ddejong
    sorry but im learning php
    where i can do your change
    "First, I would suggest getting rid of your shorttags, and also enveloping the whole snippet into one echo statement.

    n'; ?>"
    • CommentAuthorsire
    • CommentTimeMar 13th 2006
     
    Much of this can be eliminated. Here's how I would do it. Create a new file in the same directory as your index.php and gallery.php called random.php, with this code.

    http://rafb.net/paste/results/4I8Mny67.html

    Then, just add the following where you want them to be displayed in your index.php page.
    <? include('random.php'); ?>
    • CommentAuthornissai
    • CommentTimeMar 13th 2006
     
    thnks for your help
  3.  
    Would you be so kind to put the random.php file in a zip and put it up for download somewhere? I could not find on the location you gave us.
    • CommentAuthorsire
    • CommentTimeMar 24th 2006
     
    Try this
    http://pastebin.com/620934
    • CommentAuthorsonria
    • CommentTimeMar 25th 2006
     
    I love this script and am using it at http://cathcoll.net. Question - for a new site I'm developing, is there a way to pull a random image rather than a random thumbnail? I tried a couple of things but being a PHP cluebie, none of them worked.

    Thanks!
    • CommentAuthorsire
    • CommentTimeMar 26th 2006
     
    I see my code is already gone. Sorry.
    • CommentAuthorTerje
    • CommentTimeMar 26th 2006 edited
     
    Nice script, love it :) I use it on mi site Asphaug.info

    Just a little tip!
    If you want to change the thunbsize just change

    border="1" style="border-color:black"

    to

    border="1" style="border-color:black;height:90px;width:90px"
    • CommentAuthorthyde
    • CommentTimeMar 28th 2006 edited
     
    Great script, I've put it to use on livingos.com by wrapping it in my first wordpress plugin.

    This is very rough still and very much work-in progress as I'm new to WP and Plogger.

    I did find a WP plugin for plogger here somewhere, but it wasn't complete and didn't seem to do anything. Anybody know if this has been completed anywhere?
    • CommentAuthorthyde
    • CommentTimeMar 28th 2006
     
    Scrub my last comment. I've polished up my Plogger plugin for WordPress inspired by this thread.

    It no longer requries the connection to db (uses $wpdb class) and now includes ability to insert tags in posts.

    It is still fragile at Alpha release - but it works for me!

    Find it here