我正在使用Wordpress的advanced custom field插件来显示复选框的结果。我有我想要的工作,我只想整理代码并添加以下内容:
这是我的test page,它们是学科部分下面的蓝色“标签”。
这是我的代码:
<?php
$catNames = array( 'branding','creative','development','exhibition','packaging','print','seo','social_media','usability','web','advertising','campaign','content','feasibility','publishing','research','strategy');
foreach($catNames as $name){
if(in_array($name, get_field('categories') )){
echo '<a href="/tags/design/'.$name.'" title="'.$name.'">'.strtoupper($name).'</a>';
}
}
?>
答案 0 :(得分:1)
这是非常基本的,你只需要做一个循环。我可以用更多信息写出更好的东西......无论如何,这应该完全符合你的代码所做的但是循环。
<?php
$catNames = array( 'branding','creative','development','exhibition','packaging','print','seo','social_media','usability','web','advertising','campaign','content','feasibility','publishing','research','strategy');
foreach($catNames as $name){
if(in_array($name, get_field('categories') )){ //I don't know what this is suppose to do
echo '<a href="/tags/design/'.$name.'" title="'.$name.'">'.strtoupper($name).'</a>';
}
}
?>
答案 1 :(得分:0)
试试这个:
<?php foreach( get_field('categories') as $category ): ?>
<a href="/tags/design/<?php echo $category ?>" title="<?php echo ucwords($category) ?>"><?php echo ucwords($category) ?></a>
<?php endforeach; ?>
答案 2 :(得分:0)
好的,这应该更好
<?php
$catNames = array( 'branding','creative','development','exhibition','packaging','print','seo','social_media','usability','web','advertising','campaign','content','feasibility','publishing','research','strategy');
foreach($catNames as $name){
$theID = get_cat_ID($name); // get the ID of each category
echo '<a href="'.get_category_link($theID).'" title="'.$theID->name.'">'.$theID->name.'</a>';
}
?>