Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改php中逗号的颜色_Php_Wordpress_Tags_Comma - Fatal编程技术网

更改php中逗号的颜色

更改php中逗号的颜色,php,wordpress,tags,comma,Php,Wordpress,Tags,Comma,这是我的密码: <?php $posttags = get_the_tags(); if ($posttags) { $tagstrings = array(); foreach($posttags as $tag) { $tagstrings[] = '<a href="' . get_tag_link($tag->term_id) . '" class="tag-link-' . $tag->term_id . '">' . $tag-&

这是我的密码:

<?php
$posttags = get_the_tags();
if ($posttags) {
   $tagstrings = array();
   foreach($posttags as $tag) {
      $tagstrings[] = '<a href="' . get_tag_link($tag->term_id) . '" class="tag-link-' . $tag->term_id . '">' . $tag->name . '</a>';
   }
   echo implode(', ', $tagstrings);
}

// For an extra touch, use this function instead of `implode` to a better formatted string
// It will return "A, B and C" instead of "A, B, C"
function array_to_string($array, $glue = ', ', $final_glue = ' and ') {
    if (1 == count($array)) {
        return $array[0];
    }
    $last_item = array_pop($array);
    return implode($glue, $array) . $final_glue . $last_item;
}
?>


代码在WP中的标记后加上逗号(最后一个标记除外)。我想更改逗号的颜色。我该怎么做呢?

您可以使用以下方法:

$glue = '<span class="tagglue">,</span> ';
实施:

<?php
$posttags = get_the_tags();
if ($posttags) {
   $tagstrings = array();
   foreach($posttags as $tag) {
      $tagstrings[] = '<a href="' . get_tag_link($tag->term_id) . '" class="tag-link-' . $tag->term_id . '">' . $tag->name . '</a>';
   }
   echo array_to_string($tagstrings);
}

// For an extra touch, use this function instead of `implode` to a better formatted string
// It will return "A, B and C" instead of "A, B, C"
function array_to_string($array, $glue = '<span class="tagglue">, </span>', $final_glue = ' and ') {
    if (1 == count($array)) {
        return $array[0];
    }
    $last_item = array_pop($array);
    return implode($glue, $array) . $final_glue . $last_item;
}
?>

正如您所写,我更改了我的代码,但是没有发生任何事情
函数数组到字符串($array,$glue=',',$final_glue='和')
请检查源代码以查看
标记是否按预期生成。您是否将
.tagglue{color:blue;}
声明添加到样式表中?源代码中的样式声明是吗?很奇怪。我更改了代码,但在源代码中看不到更改。span class=“tagglue”绝对找不到。清除缓存怎么样?硬刷新页面重新加载?您能检查您正在编辑的文件上上次修改的日期时间吗?这些小问题发生了,继续调查,如果有任何线索,请告诉我。函数是否实际被调用?或者你的文件仅仅是重复你发布的片段的第一部分?是否需要:
echo数组到字符串($tagstrings)在foreach()循环之后?我删除了缓存(ctrl+shift+r)。我的代码就是上面的代码。
<?php
$posttags = get_the_tags();
if ($posttags) {
   $tagstrings = array();
   foreach($posttags as $tag) {
      $tagstrings[] = '<a href="' . get_tag_link($tag->term_id) . '" class="tag-link-' . $tag->term_id . '">' . $tag->name . '</a>';
   }
   echo array_to_string($tagstrings);
}

// For an extra touch, use this function instead of `implode` to a better formatted string
// It will return "A, B and C" instead of "A, B, C"
function array_to_string($array, $glue = '<span class="tagglue">, </span>', $final_glue = ' and ') {
    if (1 == count($array)) {
        return $array[0];
    }
    $last_item = array_pop($array);
    return implode($glue, $array) . $final_glue . $last_item;
}
?>