WordPress.org

Ready to get started?Download WordPress

Forums

File Gallery
[resolved] Custom Media fields in Template? (5 posts)

  1. Laurent J.V. Dubois
    Member
    Posted 2 years ago #

    Is it possible to display custom media fields in a file gallery's template?
    Media allows to add custom fields, I don't know how to integrate these fields in a template.

    That will help me to have a gallery views with not only artwork and description, but also creator, year ...

    thanks for your feedbacks

    http://wordpress.org/extend/plugins/file-gallery/

  2. Aesqe
    Member
    Plugin Author

    Posted 2 years ago #

    hi ljvd :)

    you can use the standard WP get_post_custom() function to retrieve an attachment's custom fields.

    try something like this inside your template:

    $custom_fields = get_post_custom($attachment->ID);
    
    foreach($custom_fields as $key => $values)
    {
    	// skip fields with underscore as their first letter
    	if( '_' != substr($key, 0, 1) )
    	{
    		foreach($values as $value)
    		{
    			echo '<p>[' . $key . '] => ' . $value . '</p>';
    		}
    	}
    }
  3. Laurent J.V. Dubois
    Member
    Posted 2 years ago #

    Thanks Aesqe ;-)

    my issue was most about adding extra information with each image of the gallery.
    Fortunately, your code is pretty clean ;-)
    It's a real pleasure to learn from your code!
    I'm definitely one of your big fans ;-p

    I've find the $attachment_id and currently work around it with media tags and my dedicated fields

    Thanks again for this amazing plugin.
    It definitely deserve its 5 stars 42 endorsements ;-)

  4. jynk
    Member
    Posted 2 years ago #

    is there a way to stop the file gallery updates overwriting the templates? It's never seem my custom templates so i edit the supplied which get over overwritten on every update.

    Dc

  5. Aesqe
    Member
    Plugin Author

    Posted 2 years ago #

    @jynk: when a plugin is updated, its whole folder gets deleted and all files are replaced with new ones, there's no way around it.

    where do you place your custom templates? File Gallery looks at the following two locations by default:

    1) your-theme-directory/file-gallery-templates
    2) wp-content/file-gallery-templates

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic