0

我正在使用 Wordpress 的高级自定义字段插件来显示复选框的结果。我有我想要的工作,我只想整理代码并添加以下内容:

  1. 从社交媒体标签中删除下划线(某种剥离???)。
  2. 如果可能的话,我想在每个“标签”之后显示一个逗号,但如果它是最后一个,则不会。

这是我的测试页面,它们是学科部分下的蓝色“标签”。

这是我的代码:

    <?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>';       
    }
}
?>
4

3 回答 3

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>';       
    }
}
?>
于 2011-05-17T11:58:03.270 回答
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>';
    }
?>
于 2011-05-17T12:25:50.120 回答
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; ?> 
于 2011-05-17T11:58:28.660 回答