简体   繁体   中英

WordPress: 3.5+ Attach Gallery To Post and Use Template Tag

Just wonder if WordPress 3.5+ still attach gallery even if it is not added to the post content area.

Earlier WordPress was adding gallery as an attachment and allowing to populate via template tag even if it is not added to the content area. Now with version 3.5.1 I am trying to create a gallery and it is displaying if I add to the post content but as soon as I remove from the post content than gallery just disappear from the media library as well and there is no attachment found for the post.

Just wonder and trying to understand how they have changed the media library and gallery. I understand the basic that before they were creating a gallery id but now they are adding only image id so there is no more gallery id. Is that correct?

So question how can I add gallery using template tag something like <?php echo do_shortocode('[gallery link="file"]'); ?> <?php echo do_shortocode('[gallery link="file"]'); ?> or similar?

You have almost answered this question yourself!

Check the codex for the specifics.

I needed to do this with with a custom meta box and the details can be found here. Pre-Select Images when opening WordPress 3.5 media manager .

EDIT:

For the benefit of other readers and for clarification, something like this is required

echo do_shortcode( '[gallery ids="139,138,137,136"]' );

Where the ids is a comma seperated list of attachment id's you want included. This is it in the simplest form - check the codex for more options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM