开发者

easy php array of images, from a WordPress custom field

I'm trying to use 1 custom field for a bunch of images - to do the same thing to all the images. I can store them in the custom field however is advisable, but I thought this format would be best, since I think that's what a PHP array goes into:

'http://images.domain.com/image1-Th.jpg',
'http://images.domain.com/image1-Th.jpg',
'http://images.domain.com/image3-Th.jpg'

So, once I have my custom field values entered for a post, here's my non-working PHP code:

<?php //og images
    $ogimagepre = '<meta property="og:image" content="';
    $ogimagepost = '"/>';
    global $wp_query; $postID = $wp_query->post->ID;
    $photosfull = array(get_post_meta($postID, 'custom_field_name', true));
    echo $ogimagepre.$photosfull.$ogimagepost
?>

You can see I'm trying to get this result:

<meta property="og:image" content="http://images.domain.com/image1-Th.jpg"/>
<meta property="og:image" content="http://images.domain.com/image2-Th.jpg"/>
<meta property="og:image" content="http://images.domain.com/image3-Th.jpg"/>

That's Step1. Ideally, I'd be able to do other things u开发者_如何学Gosing the same array. Such as replace "-Th.jpg" with "-X3.jpg", since that's a larger size of the same image. And other stuff; need to get past Step1 first.

Thanks!


I had a similar problem where I wanted images under a single meta key to be returned as unique elements. Try this:

$ogimagepre = '<meta property="og:image" content="';
$ogimagepost = '"/>';
global $wp_query; $postID = $wp_query->post->ID;
$photos =get_post_meta($postID, 'custom_field_name', true);

foreach ($photos as $photo){

    echo $ogimagepre.$photo.$ogimagepost
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜