$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>post thumbnails - Display featured image metadata?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

post thumbnails - Display featured image metadata?

matteradmin8PV0评论

Display featured image file size, extension, filename, type, orientation? How to display some information of featured image in post.

I need to display like this in post:

Detail Of Easter Desktop Wallpaper Widescreen Posted : February 13, 2017 At 9:46 Am

Author : Admin

Category : Easter

Tags : Beautiful, Cool, Desktop

Viewed : 1334 Visitor

File Size : 324 KB

File Type : Image/Jpeg

Resolution : 2560x1920 Pixel

Download : Smartphone ° Tablet ° Desktop (Original)

Download Many Resolution: Click Here (To Attachment Page)

pls, i am newbie, make it easy for me to understand. thnks

Display featured image file size, extension, filename, type, orientation? How to display some information of featured image in post.

I need to display like this in post:

Detail Of Easter Desktop Wallpaper Widescreen Posted : February 13, 2017 At 9:46 Am

Author : Admin

Category : Easter

Tags : Beautiful, Cool, Desktop

Viewed : 1334 Visitor

File Size : 324 KB

File Type : Image/Jpeg

Resolution : 2560x1920 Pixel

Download : Smartphone ° Tablet ° Desktop (Original)

Download Many Resolution: Click Here (To Attachment Page)

pls, i am newbie, make it easy for me to understand. thnks

Share Improve this question asked Feb 18, 2019 at 3:22 AOSAAOSA 11 silver badge1 bronze badge 2
  • This is quite open ended, you will need to break this apart into smaller multiple questions, else it's quite broad. E.g. 10 questions each for the 10 steps in baking a cake, vs what we have here "how to cake?" – Tom J Nowell Commented Feb 18, 2019 at 4:19
  • I can understand your problem except this "Download : Smartphone ° Tablet ° Desktop (Original)" . can you please explain me what is this . so can give you full code in answer. – Tanmay Patel Commented Feb 18, 2019 at 4:22
Add a comment  | 

2 Answers 2

Reset to default 1

The featured image is just an attachment, and you can retrieve its post ID via get_post_thumbnail_id, e.g.

$featured_image_id = get_post_thumbnail_id( $post );

At which point you're dealing with a standard post of type attachment. Other than checking that there is a featured image, no special handling is needed and it can be treated as any other attachment post.

In fact, internally setting the featured image is just putting a post ID in a particular post meta field.

function get_post_thumbnail_id( $post = null ) {
    $post = get_post( $post );
    if ( ! $post ) {
        return '';
    }
    return get_post_meta( $post->ID, '_thumbnail_id', true );
}

Though I would recommend using the function instead of going straight for the post meta.

As for how to get the size, type, format of an attachment post, that's another question that you should open a new question for ( or refer to the main good answers that already exist )

Here is the code as you wanted except this "Download : Smartphone ° Tablet ° Desktop (Original)". you can see in this screenshot http://prntscr/mmidnl

1. you can below code in functions.php file for visitors count. Reference: https://www.themexpert/blog/track-display-post-views-in-wordpress

function to display number of posts.

function getPostViews($postID){
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "0 Visitor";
    }
    return $count.' Visitors';
}

function to count views.

function setPostViews($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}

Remove issues with prefetching adding extra views

remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); 

2. Put this below code in single.php file.

This part of the tracking views code will set the post views. Just place this code below within the single.php file inside the WordPress Loop.

<div class="data">
<div>Detail Of <?php the_title(); ?> Posted : <?php the_time('F j, Y'); ?> At <?php the_time('g:i a'); ?></div>
<div>Author : <?php the_author(); ?></div>
<div>Category : <?php the_category( ', ' ); ?></div>
<div><?php the_tags( 'Tags: '); ?> </div>
<div><?php setPostViews(get_the_ID()); ?>Viewed : <?php echo getPostViews(get_the_ID()); ?></div>
<div><?php $image_data = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "full" ); $img_s = get_headers($image_data[0], 1); $img_size_wd =  $img_s["Content-Length"]/1024; $img_size_kb = number_format((float)$img_size_wd, 2, '.', ''); ?>File Size : <?php echo $img_size_kb; ?> KB</div>
<div><?php $img_id = get_post_thumbnail_id($post->ID); $type =  get_post_mime_type( $img_id ); ?>File Type : <?php echo $type; ?></div>
<div><?php $image_data = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "full" ); ?> Resolution : <?php echo $image_data[1]; ?> x <?php echo $image_data[2]; ?> Pixel</div>
<div><?php $img_id = get_post_thumbnail_id($post->ID); ?>Download Many Resolution: <?php echo '<a href="'. get_attachment_link($img_id) . '">Click Here</a>'; ?></div>
</div>
Post a comment

comment list (0)

  1. No comments so far