dongshan3806 2015-09-04 02: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 02: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部