Wordpress - 将逗号添加到除最后一项之外的所有项目,删除下划线

时间:2011-05-17 10:50:12

标签: wordpress custom-fields

我正在使用Wordpress的advanced custom field插件来显示复选框的结果。我有我想要的工作,我只想整理代码并添加以下内容:

  1. 从社交媒体标记中删除下划线(某种剥离方式???)。
  2. 如果可能的话,我想在每个“标签”后面显示逗号,但如果是最后一个标签则不显示。
  3. 这是我的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>';       
        }
    }
    ?>
    

3 个答案:

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