Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author shauno

    (@shauno)

    Hi Jack

    You can show the custom fields in the sidebar widget. The problem is the widget isn’t ‘templated’ like the gallery. The widget outputs the HTML directly in one of the core NGG files.
    You are still able to use the NGG Custom Fields API <?php echo nggcf_get_field($image->pid, "Your Field Name"); ?> in those core files.

    The obvious downside to that is you are editing NGG core files. Next time NGG updates, you are going to need to make the change again, as it will be overwritten in the update.

    Thread Starter Jack

    (@moxie)

    If I understand you correctly, I could use the PHP widget and add your code into this, surrounded by some html to style the output just like the other widgets?

    I would like to use those values next to the image inside the image browser.

    Plugin Author shauno

    (@shauno)

    Sorry Jack, I misunderstood what you were trying to achieve.
    But now I know, I can show you how.

    Firstly, you will need a PHP widget plugin, as WP doesn’t support PHP scripts inside widgets by default. I just used “PHP Code Widget” by Otto, as I trust his work (being a WP core coder and all). But any one you like should work fine.

    Ok, so now you need to make sure the image ID is available in the sidebar, so the widget we create can use it later. You said you are using the imagebrowser template, so I am going to explain assuming you are using the shortcode [imagebrowser id=x] in a page.

    Open /nextgen-gallery/view/imagebrowser.php in your text/code editor of choice, and add the following code at the very bottom of the file:

    <?php
    //persist the PID for a widget to use later
    global $_persist_pid;
    $_persist_pid = $image->pid;
    ?>

    Now, add a PHP widget to your sidebar, and paste the following code into it:

    <?php
    global $_persist_pid;
    echo nggcf_get_field($_persist_pid, 'Your Field Name Example');
    echo '<br />';
    echo nggcf_get_field($_persist_pid, 'Another Field Name Exmaple');
    ?>

    (obviously be sure to change the field names appropriate).

    And that’s it. You now have a widget showing your custom fields 🙂

    I hope that helps!

    Thread Starter Jack

    (@moxie)

    This works, half way :).

    Now when I’m on a gallery page with the thumbs I click on the first thumb and then I’m in the image browser. My custom fields display nicely for that first image, but when I click to the next image, the information in the custom fields stays the same, for all other images.

    Plugin Author shauno

    (@shauno)

    Works fine on my test installs 🙂

    But if you’re using the imagebroswer on as a click through from the gallery, you can change the code in the widget to:

    <?php
    global $_persist_pid;
    echo nggcf_get_field($_GET['pid'], 'Your Field Name Example');
    echo '<br />';
    echo nggcf_get_field($_GET['pid'], 'Another Field Name Exmaple');
    ?>
    Thread Starter Jack

    (@moxie)

    Do I have to change something to the code I entered in imagebrowser.php? Because the last change didn’t help, yet.

    Plugin Author shauno

    (@shauno)

    Have you got a URL I can see, because everything works fine for me

    Thread Starter Jack

    (@moxie)

    The site is not online at the moment. I can give you a link soon, I hope. I hope you’re not going on vacation 😉 For now just a screenshot: http://img827.imageshack.us/i/slwr.png/

    As you can see the info is on the top right, but clicking to another image doesn’t change the display.

    Plugin Author shauno

    (@shauno)

    I honestly don’t know what to tell you man, the logic is sound, and it works on my test installs. You must have a setting or something specific different on your site. I can debug it if I see it.

    If the site is online, but you just don’t want the URL public, feel free to email it to me at shaunalberts AT gmail DOT com.

    Thread Starter Jack

    (@moxie)

    Shauno helped me through mail to solve this matter. It appears that what I wanted to do didn’t work with Ajax pagination inside NextGen enabled. Turning it off did.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Display custom field values inside sidebar / widget’ is closed to new replies.