Add Random Gallery Photo Block

Filed in: Site News — February 1st, 2005

advertisement

Just installed the Gallery random photo block into the Wordpress sidebar. The so-call “installation” is easy, just use a PHP include function to include the random-block.php script into template. :)

However, I can’t find a way to modify the image tag so that it has a CSS border. The image tag is auto generated by $album->getThumbnailTag() function in the script. The function code will be deep inside Gallery core, I better don’t touch on it…

If you have a workaround, please let me know. Thanks!

Updated: I think I found it – The enhanced Random Photo for Gallery ! :) …few minutes later… No, not quite. It support CSS for the captions not for the thumbnail…

Bookmark and Share

Read also:

  • Actually I think you don't need to assign a class to the img tag. All you need to do is to add the following CSS:

    div#sidebar li img {
    padding: 3px;
    border: 1px solid #CCCCCC;
    }


    That should add a gray border around the photo. Just change the padding, border width and colour to suit. Just a small warning - results may be funny if your code is not valid XHTML
  • LcF
    Thank you, David. :)
    But now all images in sidebar have border..
  • Yup true, unless you can give an id or class to your li tag, e.g. <li id="rand-photo"></li>. Then for your CSS you do

    div#sidebar li#rand-photo img {
    padding: 3px;
    border: 1px solid #CCCCCC;
    }
  • Hi LcF, how did you get the block-random-enhanced to work?
    As soon as I put "include('gallery/block-random-enhanced.php');" into function.php, the block_image shows up on top of the page. I tried to locate to my sidebar. Nothing works.

    I added a div ID in block-random-enhanced.php, echo "<div div="block-random" align="center">". That did not help neither.

    It seems like the "include" can only be added to the beginning of function.php.

    Using:

    function get_header() {
    if ( file_exists( TEMPLATEPATH . '/block-random-enhanced.php') )
    load_template( TEMPLATEPATH . '/block-random-enhanced.php');
    else
    load_template( ABSPATH . 'gallery/block-random-enhanced.php');
    }

    does not work neither.

    Cheers.</div>
  • LcF
    @allan: I am not using block-random-enhanced. I use the block-random comes with Gallery.

    No, you do not add the include code into function.php, add the code into your wordpress template(sidebar) instead.

    Example:
    <?php include("/gallery/block-random-enhanced.php"); ?>
  • Anonymous
    Hey LcF, thanks for the quick response.

    I am running Gallery 1.4 and WP 1.5. The match seems problematic. Whenever I call a function in Gallery, system prints:

    PHP Warning: Cannot modify header information - headers already sent by (output started at D:\root\dynamic\wp-content\themes\default\index.php:5) in D:\root\dynamic\gallery\lib\lang.php on line 342 PHP Fatal error: Cannot redeclare _() (previously declared in D:\root\dynamic\wp-includes\functions.php:6) in D:\root\dynamic\gallery\lib\lang.php on line 465

    It seems some hacking of the original code is needed to get these two program to work together.

    Cheers.
  • LcF
    I don't understand why do you need to call a function in Gallery?!
    Login Wordpress admin, goto Presentation > Theme Editor. From there, select your template and click "Sidebar Template" and add the following code to include random gallery block:
    <?php include("http://www.YOURDOMAIN.com/gallery/block-random-enhanced.php"); ?>
  • Allan
    Hey man, guess I did my changes in different way since the very beginning. Whenever I need to refine something, I use Dreamweaver MX instead. But results are the same as template editor. System prints out the error message above. I have found no spaces, new lines, or other garbage before an opening <?php tag or after a closing ??> tag.

    It's interesting that the "block-random.php" worked on your system out of the box with any error.

    Best.
  • Allan
    I fixed
    "PHP Warning: Cannot modify header information - headers already sent"
    by turning on the "output buffering". It speeded up my page loading speed as well. That was a surprise.

    These error in original code remains:
    Fatal error: Cannot redeclare _() (previously declared in D:\root\dynamic\wp-includes\functions.php:6) in D:\root\dynamic\gallery\lib\lang.php on line 465
  • LcF
    I would advice you to make a new installation and do as I recommended.
  • Allan
    To all other friends who might be looking for the answer to this issue:

    The problem is that Gallery *requires* the random block to be included via HTTP. It can't be included as a direct file.

    include("http://your.site/path/to/gallery/block-random.php")

    That way gallery works as an external system to WP. No worries about definition overlapping at code level.
blog comments powered by Disqus