Change post meta numbers with images

2019-08-14 16:04发布

I need get post meta value "phone" and his value is "555666777" in this post, in others, can be 456654768... or whatever

My code is this:

<?php global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta($postid, 'phone', true); ?>

Now, i wish this numbers don't show in html like numbers, i need this numbers are images.

I have created 0.jpg 1.jpg 2.jpg 3.jpg 4.jpg 5.jpg 6.jpg 7.jpg 8.jpg 9.jpg

It's possible change the numbers of phone value with this jpgs? I don't want that google robots or anothers can this telephone numbers.

2条回答
走好不送
2楼-- · 2019-08-14 16:32

I think you dont need wp_query to get current post_id

global $post;

$image_str = get_post_meta($post->ID, 'phone', true);

$image_array = str_split(image_str);

$image_array_with_jpg = array();

foreach($image_array as $k=>$v){

  $image_array_with_jpg[] = $v.'.jpg';
}
 print_r( $image_array_with_jpg); // array with all your post images with .jpg extension
查看更多
该账号已被封号
3楼-- · 2019-08-14 16:50

A good way would be to isolate each digit using modulo and integer division, and produce an img tag out of it:

global $wp_query; 
$postid = $wp_query->post->ID; 
$i=intval(get_post_meta($postid, 'phone', true));
$s='';
while($i>0)
    {
    $digit=$i % 10;
    $i=(int)($i/10);
    $s="<img src='$digit.jpg' title='$digit'>$s";
    }
echo $s;
查看更多
登录 后发表回答