Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to attach an image gallery to a post. Here how i am trying to do it:

  • from the posts administration page i click on: add new media -> create gallery
  • Select the images and click to: create new gallery

After that i dont have a button: "Save gallery", i have just "insert gallery", but this add the shortcode to the content of my post.

I would like to include the gallery like an "object" in my template using wordpress API.

If i remove the shortcode from the post content i loose completely my gallery...

Is there a way so?

share|improve this question
    
I'm unclear on what you're trying to do. The gallery will show as a big yellow 'object' in the editor if you switch to 'Visual' - it shows as a shortcode in 'Text' mode. If you're trying to insert the gallery in a Page Template, that's totally different....? –  Michelle Oct 21 '13 at 15:54
    
@Michelle i dont want to use shortcode mode to include the gallery...i would like to use(if possible) the gallery as a post attached object and call it in the temlate file in the way i could get the urls of single images and style the template as i want...hope it's clear now –  Salvatore Dibenedetto Oct 21 '13 at 15:58
    
Gotcha - see @s_ha_dum's answer below, it's the way to go. –  Michelle Oct 21 '13 at 16:21
add comment

1 Answer

up vote 2 down vote accepted

The gallery is the shortcode. It is not, so far as I know, saved in any other place or in any other way than in that shortcode.

You can print/process shortcodes anywhere you want with tricks like this:

echo do_shortcode('[gallery option1="value1"]');

Or this:

$gallery_shortcode = '[gallery id="' . intval( $post->post_parent ) . '"]';
print apply_filters( 'the_content', $gallery_shortcode );

Both from the Codex.

You can see in the source how that gallery is constructed. It is actually parsed from the values passed in the shortcode.

If you need to save that shortcode and retrieve it some other way you will need to construct your own mechanism for doing so.

share|improve this answer
    
thank you! i think it's the best way to do it! –  Salvatore Dibenedetto Oct 22 '13 at 7:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.