我在wordpress主题中创建了“投资组合”自定义帖子类型。
<?php
add_action( 'init', 'portfolio' );
function portfolio() {
$labels = array(
'name' => _x('portfolio', 'post type general name'),
'singular_name' => _x('portfolio', 'post type singular name'),
'add_new' => _x('Add New', 'Slide'),
'add_new_item' => __('Add New slide'),
'edit_item' => __('Edit project'),
'new_item' => __('New project'),
'view_item' => __('View project'),
'search_items' => __('Search project'),
'not_found' => __('No project Found'),
'not_found_in_trash' => __('No project found in Trash'),
'parent_item_colon' => ''
);
$supports = array( 'title','editor','thumbnail');
register_post_type( 'portfolio',
array(
'labels' => $labels,
'public' => false,
'publicly_queryable' =>false,
'show_ui' =>true,
'show_in_menu' =>true,
'query_var' =>true,
'rewrite' =>false,
'capability_type' =>'post',
'has_archive' =>false,
'hierarchical' =>false,
'menu_position' =>15,
'supports' => $supports
)
);
}
?>
在其内部成功添加了带文本输入的元数据箱,以获取投资组合图像的URL。通过这种方式添加了5个帖子,其中metabox中有portfolio-image url。此值的输出为<?php echo get_post_meta($post->ID,'portfolio-url',true); ?>
我创建了5个投资组合,每个投资组合都有投资组合网址。如何获取数组中所有url的值,以便我可以将jquery中的那些值用作变量?
var _portfolioImage = [url1,url2,url3,url4,url5];
答案 0 :(得分:1)
将此内容写入
循环中<script>
var arr = new Array();
/*loop starts here*/
for(i=0;i<5;i++){
arr.push('<?php echo get_post_meta($post->ID,'portfolio-url',true); ?>');
/*loop ends here*/
}
</script>