Support » Plugins » [Plugin: NextGEN Custom Fields] Custom field in widget

  • Hello!

    I’m glad I found this excellent plugin, it suits my needs perfectly for my portfolio! I have just one question though: I have placed the Display Recent Images widget in my footer and I want to display the content of one of my custom fields (in this case the date) below the images. How do I achieve this? Placing

    '. $image->ngg_custom_fields['Date'] .'

    in the output of widgets.php doesn’t work, unfortunately, nothing shows up.

    Thanks in advance 🙂

Viewing 10 replies - 1 through 10 (of 10 total)
  • Hi

    The widgets don’t call call a hook for the custom fields to get loaded into memory like the normal galleries. This isn’t a problem though, as there is a nice way to still get the field.

    You can call the function nggcf_get_field($image->pid, "Field Name Here"); where you want to display the custom field. This call obviously needs to be made inside the foreach loop starting on line 403, and ending on line 426 of widgets.php

    I’m not sure what level your PHP is, but you will need to output the results of that function call into the $out variable.

    So, for instance, if you want the text inside the a tag, you you could add
    $out .= nggcf_get_field($image->pid, "test field");
    to line 418 of widgets.php (I am assuming NGG 1.3.6 for line numbers).

    Let me know if you need any more help.

    Yes, I figured 🙂 My PHP knowledge is pretty basic as of yet but I think I can get it to work now thanks to you 🙂 And if not I’ll just let you know. Thanks!

    It worked! Thanks 😀



    Hi Shauno,

    Is there a similar way to display the custom field in the album template?

    Yes, you can call that function anywhere!
    If you are trying to show a gallery field then here is the code:

    <?php echo nggcf_get_gallery_field(1, "Field Name"); /* where 1 is the gallery id */ ?>
    If you are inside the foreach in the album template, you can do this:
    <?php echo nggcf_get_gallery_field($gallery->gid, "Field Name"); /* This will show the "Field Name" custom field for all galleries in the template */ ?>

    If you are trying to show an image custom field, then you would use <?php echo nggcf_get_field(123, "Field Name"); /* where 123 is the ID of the image you want the custom field to show for */ ?>

    An explanation for people comfortable with a bit of PHP:
    The function nggcf_get_field() takes 2 arguments. The first (int) is the image id from NextGEN, the second (string) is the custom field name. It will return the value for that custom field for the specified image.

    The function nggcf_get_gallery_field() is the same, except its first argument is the gallery id.

    You should be able to call these functions pretty much anywhere in the wordpress templates

    PS code examples untested 🙂



    Hi Shauno,

    Thank you for the answer. The code that you wrote for displaying the gallery fields in the album template works perfectly! Thank you!

    So if the code for the gallery custom field is:
    <?php echo nggcf_get_gallery_field($gallery->gid, “Field Name”); ?>
    I’m guessing that, for the image custom field, it would be:
    <?php nggcf_get_field($image->pid, “test field”); ?>

    I wanted to display the titles of the preview images of the galleries within a template album, I’ve tried the code above but it didn’t work.

    Could you help again, please?

    Thanks so much.

    Looks like you are missing an echo in front of the function call?
    <?php echo nggcf_get_field($image->pid, "test field"); ?>




    Hi Shauno,

    No, I didn’t forgot the echo in my code (I just made the mistake in my reply).

    However I’ve figured out how to display the custom fields of my gallery’s preview image. Just replace $image->pid with $gallery->previewpic so the code shoulde be:
    <?php echo nggcf_get_field($gallery->previewpic, “Field Name”); ?>

    For the album’s preview image, it should be:
    <?php echo nggcf_get_field($album->previewpic, “Field Name”); ?>

    Thanks so much again, Shauno, for your kind help.



    And many thanks for the good plugin, too!


    I would like to have my custom fields show up where the gallery description shows up, what file do I edit, and where would I put it?
    Thank you for your help.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Plugin: NextGEN Custom Fields] Custom field in widget’ is closed to new replies.