Wordpress

Display total number of attachments to a Post

<?php
global $post;
$attachments = get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) );

$count = count( $attachments );
$specific = array();
$i = 1;

foreach ( $attachments as $attachment ) {
    $specific[$attachment->ID] = $i;
    ++$i;
}

echo "Image {$specific[$post->ID]} of {$count}";

?>
Advertisements
PHP

Replace a flickr image url from big to small size with substr_replace

I have been trying out the change the flickr image url from the big size to small and medium size without using the image url’s again.I have landed up with the solution.

<?php
$url="http://farm5.static.flickr.com/4074/4940684667_9c99ff0288_b.jpg";
echo substr_replace($url,"m",-5,1);
echo "<br />";
echo $url;
?>