【问题标题】:Joomla Headings - Make the first word in different colorJoomla 标题 - 用不同的颜色制作第一个单词
【发布时间】:2013-06-26 13:38:35
【问题描述】:

我目前正在尝试使我的任何/所有 Joomla 文章/类别/博客标题的第一个单词都具有一种颜色,然后句子的其余部分成为网站默认值。我发现下面的代码确实改变了颜色,但它仅在标题包含 2 个单词并且如果有更多单词时才有效,则它会删除所有格式。

<?php if ($this->params->get('show_page_heading')) : ?>
    <?php 
    $title = $this->escape($this->params->get('page_heading'));
            $title = str_replace(' ', '<span>', $title);
            echo "<h1>" . $title . "</h1>";
    ?>
<?php endif; ?>

谢谢!

【问题讨论】:

    标签: php joomla2.5 article html-heading


    【解决方案1】:

    在这种情况下,您必须考虑标题是 1 个单词或多个单词。

    试试这个..

    // check to see if there are multiple words by the count of the space character 
    if(substr_count($title,' ') > 0) {
        // multiple words
        // replace the FIRST space with closing span tag
        $title = '<span>'.preg_replace('/\ /', '</span> ', $title, 1);
    }
    else {
        // one word, just close the span
        $title = '<span>'.$title.'</span>';
    }
    echo "<h1>" . $title . "</h1>";
    

    请注意,如果标题中的第一个字符是空格,那么您将得到一个空跨度而不是预期的效果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-16
      • 2020-12-05
      • 1970-01-01
      • 2018-02-14
      • 2017-07-27
      • 2015-08-11
      • 1970-01-01
      • 2015-06-03
      相关资源
      最近更新 更多