Php 显示来自Wordpress post自定义字段的图像
我正在使用下面的代码将随机帖子数据拉到我博客的边栏上。我如何添加从该帖子的自定义字段“athletethumbnail”中提取的图像? :Php 显示来自Wordpress post自定义字段的图像,php,wordpress,random,Php,Wordpress,Random,我正在使用下面的代码将随机帖子数据拉到我博客的边栏上。我如何添加从该帖子的自定义字段“athletethumbnail”中提取的图像? : 来自,在Posteta功能下 These functions are intended for use inside The Loop, and all return arrays. get_post_custom() Get all key/value data for the current post. ................ 解决方案:
来自,在Posteta功能下
These functions are intended for use inside The Loop, and all return arrays.
get_post_custom()
Get all key/value data for the current post.
................
解决方案:你应该使用
试试这个:
$custom = get_post_custom(the_ID());
echo $athletethumbnail = $custom["athletethumbnail"][0];
注意:您还应该能够在不传递POST ID的情况下离开,因为get\u POST\u自定义调用get\u没有传递POST ID
更改后:
<?php
global $wp_query;
$current_id = $wp_query->get_queried_object_id();
$my_query = new WP_Query( array(
'post_type'=>'athletes',
'posts_per_page'=>'1',
'category' => '36' ,
'orderby' =>'rand'
));
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php
$custom = get_post_custom(the_ID());
echo $athletethumbnail = $custom["athletethumbnail"][0];
the_title(); ?>
<?php
endwhile;
// Reset Post Data
wp_reset_postdata();
?>
你能帮我发布完整的代码吗?我似乎无法让它工作
<?php
global $wp_query;
$current_id = $wp_query->get_queried_object_id();
$my_query = new WP_Query( array(
'post_type'=>'athletes',
'posts_per_page'=>'1',
'category' => '36' ,
'orderby' =>'rand'
));
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php
$custom = get_post_custom(the_ID());
echo $athletethumbnail = $custom["athletethumbnail"][0];
the_title(); ?>
<?php
endwhile;
// Reset Post Data
wp_reset_postdata();
?>