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.

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

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条