您可以通过自定义元来实现这一点,您所要做的就是创建自定义元盒及其复选框,创建自定义元盒的最简单方法是
1) 。从下载WP Alchemy Metabox类here
2) 。在主题文件夹中放置“wpalchemy”文件夹
在您的功能中。php文件
include_once WP_CONTENT_DIR . \'/themes/yourtheme/wpalchemy/MetaBox.php\';
3)。然后,按照名称“my special feature meta”创建两个php文件。php“,”my-special-feature-spec.php“(您可以随意命名php文件)。
在“my-special-feature-spec.php”文件中
<?php
global my_special_features;
$my_special_features = new WPAlchemy_MetaBox(array
(
\'id\' => \'_my_special_features\',
\'title\' => \'Special Features\',
\'template\' => get_stylesheet_directory() . \'my-special-feature-meta.php\',
\'types\' => array(\'page\',\'post\',\'your_custom_post\')
));
/* eof */
还有你的“我的特色元”。php文件
分组复选框测试#1
<?php
global $my_special_features;
$items = array(\'internet\', \'laundry\', \'garage\', \'tv\');
?>
<?php while ($my_special_features->have_fields(\'cb_ex\', count($items))): ?>
<?php $item = $items[$mb->get_the_index()]; ?>
<input type="checkbox" name="<?php $my_special_features ->the_name(); ?>" value="<?php echo $item; ?>"<?php $my_special_features ->the_checkbox_state($item); ?>/> <?php echo $item; ?><br/>
<?php endwhile; ?>
好的,您已经在自定义帖子类型中创建了复选框列表,现在您必须在前端显示元结果,要做到这一点,请在函数中创建php函数。php文件
function display_special_fetures(){
global $my_special_features;
$myresults = $my_special_features->the_meta();
if(!empty($myresults)){
foreach($myresults){
echo \'<img src="\'get_stylesheet_directory().\'/\'.$myresults[\'cb_ex\'].\'">\';
}
}
}
最后,将此函数放入循环或单循环中。