Tag Info

New answers tagged

3

The post parent can be accessed by $post->post_parent. The ID of the post parent is retrieved, so can try something like this $parent_ID = $post->post_parent; if( is_sticky( $parent_ID ) ) { // DO SOMETHING IF POST PARENT IS STICKY }


1

This should work to get the parent's tags. <?php global $wp_query; $attachment_id = $wp_query->post->ID; $parent_id = get_post_field('post_parent', $attachment_id); $parent_tags = wp_get_post_tags($parent_id); $tag_count = count($parent_tags); // Counting the tags to find know the last one so there is no pipe $i = 1; // Setting up the count if ...


1

If this is related to your other question then the custom field is attached to the post and not the attachment. You need to get the post ID of the post first then you can get the custom field. This should work. global $wp_query; $attachment_id = $wp_query->post->ID; $parent_id = get_post_field('post_parent', $attachment_id); echo ...


0

Attachments are a separate post type in WordPress, so on theory if you want to specify tags for each uploaded file, you'll have to use this in your active theme's functions.php: register_taxonomy( 'post_tag', 'attachment', $args ); For $args have a look here: http://codex.wordpress.org/Function_Reference/register_taxonomy


0

If your uploading the photos via ftp, WordPress won't know about them in the media library. If that's Ok with you then you take the image URLs from the XML being loaded, create a serialized array using maybe_serialize() and then save it as a custom field to the post.


0

These options are hardcoded into the tmpl-attachment-display-settings Underscore media template in the /wp-includes/media-template file: <script type="text/html" id="tmpl-attachment-display-settings"> <h3><?php _e('Attachment Display Settings'); ?></h3> ...cut... <select class="link-to" ...


0

I am not sure what you mean by "redirect" there. attachment.php is meant to be used as theme template file. Loading it directly it won't be able to access WordPress core properly. In usual WordPress mechanics you can use get_attachment_link() to form URL itself or wp_get_attachment_link() for whole link HTML.


0

The problem was that the files wasn't attached to the post. To make it work I re-attached the files (Media Library > Attach). I also removed the & in $attachments =& get_children( array (.


1

Here's how to check if the post has an attachment other than image (or other mime types): <?php $attachments = get_posts( array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_parent' => $post->ID, 'exclude' => 'image' )); if ( $attachments ) { ?> ...


3

You can use the following within a loop: $files = get_attached_media( $type, $post_id ); Just define the attachment MIME type on $type. Second parameter is optional. Example from the Codex page: $media = get_attached_media( 'audio', 102 ); With the retrieved array, you can do something like: if( $media ) { //Show the post attachments that are not ...


0

Assuming that bungeshea is right and you want to retrieve the IDs of images attached to a gallery using PHP, you can filter 'shortcode_atts_gallery', like this: add_filter ('shortcode_atts_gallery', 'wsec_filter_gallery_atts', 10, 3); function wpsec_filter_gallery_atts ($out, $pairs, $atts) { $ids = $out['include']; // Do what you want with the ids ...



Top 50 recent answers are included