WordPress.org

Ready to get started?Download WordPress

Forums

Random Image from G2 in WP (3 posts)

  1. kodekitten
    Member
    Posted 7 years ago #

    Hello!

    I have installed wordpress on my server and everything seems to be just fine. I used to run Serendipity, and there was a sidebar plugin that pulled 4 random images from a Gallery 2 install and placed them in the sidebar, along with a little information (title, views..).

    I haven't been able to find a very simple plugin or widget for WordPress that does this effectively. I am very well aware of the WPG2 plugin/widget bundle, but the host I have my website with is incapable of running one of the modules required to get it to work. Long story short, I only want the simplest feature of the thing, but it won't run due to my webhost.

    The Serendipity plugin called a module on the Gallery end of things called Random Block, so I don't see why I couldn't do the same with a little PHP in my sidebar and a PHP text widget (which I've got.) My WordPress install and Gallery are on two different subdomains, and the situation was the same with Serendipity and Gallery before.

    I've seen plugin after plugin for WordPress which wraps Gallery in my WordPress template, but that's not what I'm looking for. Does anyone have another suggestion or a bit of PHP they think might work? I've looked for days non-stop at this point, so this post is a last resort. This may be the DEAL BREAKER for WordPress.

    Here's some code suggested by Gallery 2's website that may call on that random function. My problem with it is that the URL refrence /gallery/embed. php at the top of the code looks within the current subdomain and I can't make it look elsewhere (another subdomain). For example, WP is installed in journal.x.com, and gallery is installed in gallery.x.com. This bit of code as is won't look anywhere but its own subdomain, and I'm not sure how to modify it to do so.

    <?php
    /* You'll have to change the /gallery2/ thing in the following 2 lines probably */
    require_once(dirname(__FILE__) . '/gallery/embed.php');
    $ret = GalleryEmbed::init(array('fullInit' => true, 'baseUri' => '/', 'g2Uri' => '/gallery/'));
    if ($ret) {
    print 'GalleryEmbed::init failed, here is the error message: ' . $ret->getAsHtml();
    exit;
    }
    /*
    * See "Site admin" -> "image block" for all available options. the parameters are the same
    * as for the external imageblock
    */
    list ($ret, $bodyHtml, $headHtml) = GalleryEmbed::getImageBlock(array('blocks' => 'randomImage',
    'show' => 'title|date'));
    if ($ret) {
    print 'GalleryEmbed::getImageBlock failed, here is the error message: ' . $ret->getAsHtml();
    exit;
    }
    /* $bodyHtml contains the image block. print it somewhere on your website */
    print $bodyHtml;
    /*
    * $headHtml is not required. if you use imageframes for your imageblocks, you need to print
    * $headHtml in the <head> section of your web page
    */
    ?>

    Incidentally, how old is the widgets functionality? It feels like it is fairly new, considering how few widgets have been created.

  2. drmike
    Member
    Posted 7 years ago #

    Widgets have been around for about a year if that. They were created for use over at wordpress.com since endusers can't edit themes on the WPMu platform.

    I know in my G2 install, there's a function call you can use to display a random picture. Looks like this:

    <?php @readfile('http://kpscreencaps.tdjc.be/main.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_show=title'); ?>

    You an see how this is used on your G2 install at SiteAdmin -> Image Block. I'd just figure out the code that you want to use and just use that.

    Hope this helps,
    -drmike

  3. kodekitten
    Member
    Posted 7 years ago #

    That was it! That's the piece of code I needed. Thanks so much Dr. Mike.

Topic Closed

This topic has been closed to new replies.

About this Topic