dongshan3806 2015-09-04 10:54 采纳率: 0%
浏览 67
已采纳

如何在php标记中的'a'元素中添加一个类

I'm struggling with something pretty simple here and wondered if someone can help as I only have a basic knowledge of code.

I've purchased a wordpress theme and am making some changes. I'd like to set individual colours for the social media icons. In order to do this, this is the advice from the theme developer:

To change the color individually, you need to add a class to the "a" element in the markup. In 'widget-social.php' the section between the line 64 and the line 139. Add a class ("facebook", "twitter", etc) to each element and use something like:

html .lol-social-widget li a.facebook {
background-color: #fff;
color: #000;
}

Here's the code from the widget-social.php:

<div class="lol-social-widget">            
<ul>
<?php if ( $facebook != '' ) : ?>
<li><a href="<?php echo esc_url( $facebook ); ?>" <?php echo $target; ?>><i class="fa fa-facebook"></i></a></li>
<?php endif; ?>
<?php if ( $twitter != '' ) : ?>
<li><a href="<?php echo esc_url( $twitter ); ?>" <?php echo $target; ?>><i class="fa fa-twitter"></i></a></li>
<?php endif; ?>

I've included just the facebook and twitter elements here.

Is anyone able to offer advice as to how I modify the php file to include the 'a' element?

Thanks in advance for any help!

  • 写回答

1条回答 默认 最新

  • dongluolie3487 2015-09-04 10:59
    关注

    You have to add the class inside the anchor tag as below.

    <div class="lol-social-widget">            
    <ul>
    <?php if ( $facebook != '' ) : ?>
    <li><a class="facebook" href="<?php echo esc_url( $facebook ); ?>" <?php echo $target; ?>><i class="fa fa-facebook"></i></a></li>
    <?php endif; ?>
    <?php if ( $twitter != '' ) : ?>
    <li><a class="twitter" href="<?php echo esc_url( $twitter ); ?>" <?php echo $target; ?>><i class="fa fa-twitter"></i></a></li>
    <?php endif; ?>
    

    Then update the style.css with the following styles.

    html .lol-social-widget li a.twitter{
    background-color: #f00; //add the required color for twitter icon.
    color: #000;
    }
    html .lol-social-widget li a.facebook {
    background-color: #00f; //add the required color for facebook icon.
    color: #000;
    }
    

    Then you will have red background color for twitter icon and blue for facebook icon. You can change the color to whatever color you need.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效