How to get all attachment image from post ?? WordPress

<?php /* * Template Name: Gallery Page */ $query_images_args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘post_status’ => ‘inherit’, ‘posts_per_page’ => – 1, ); $query_images = new WP_Query( $query_images_args ); ?> <?php get_header();?> <div class=”main”> <div class=”row”> <?php foreach ( $query_images->posts as $image ) {?> <div class=”col-md-3″> <img src=”<?php echo wp_get_attachment_url($image->ID); ?>” > <a … Read more

Is it possible to list post attachments in a sub URL endpoint with a dedicated template?

I think I found it myself. Now I’ve successfully managed to add a /photos endpoint to a permalink URL, such as: http://mywordpressite.com/projects/a-project/photos And then a custom template, photos.php will load and show – with access to the global $post variable. Helpful links: http://codex.wordpress.org/Rewrite_API/add_rewrite_endpoint http://codex.wordpress.org/Template_Hierarchy In my functions.php I added functions for the single_template and query_vars … Read more

Get the size (size in Kb or MB) of an featured image?

You can use get_attached_file() to: Retrieve attached file path based on attachment ID. And get_post_thumbnail_id() to determine the post thumbnail of the current post, or any post if you set the $post_id parameter. Exemplary usage: $bytes = filesize( get_attached_file( get_post_thumbnail_id() ) ); Use size_format() to Convert a given number of bytes into a human readable … Read more

Add suffix to filename of uploaded images

I did it in a different way. I just had to update the code from Gerasimos Tsiamalos Retina Plugin to WordPress 3.5., using image editor instead of image resize. This is how it looks like: function nothing_image_make_retina_size($file, $width, $height, $crop=false) { if ( $width || $height ) { $resized_file = wp_get_image_editor($file); if ( ! is_wp_error( … Read more

How to add a rel attribute to images that contains their categories?

This should work for the rel attribute: /** * Create a rel attribute from the image categories * * @see http://wordpress.stackexchange.com/a/158024/26350 */ add_filter( ‘get_image_tag’, function( $html, $id ) { $rel = array(); foreach( (array) get_the_category( $id ) as $cat ) { $rel[] = $cat->slug; } return str_ireplace( ‘<img ‘, sprintf( ‘<img rel=”%s” ‘, join( ‘ … Read more