social-fontawesome
, (*1)
, (*2)
, (*3)
PHP Class to generate social links with FontAwesome icons., (*4)
Note
This module does not add FontAwesome to your project. This will have to be added by yourself., (*5)
Installation
Either download or use composer:, (*6)
"require": {
"linusrendahl/social-fontawesome": "1.*"
}
Basic usage
Usage:, (*7)
//create the object
$icons = new LinusRendahl\SocialFontAwesome;
//add some icons with the add method
$icons
->add('http://www.facebook.com')
->add('http://twitter.com')
->add('http://instagram.com');
//get the html
$html = $icons->getHtml();
Returns:, (*8)
<a href="http://www.facebook.com"title="Facebook">
<i class="fa fa-facebook"></i>
</a>
<a href="http://twitter.com"title="Twitter">
<i class="fa fa-twitter"></i>
</a>
<a href="http://instagram.com"title="Instagram">
<i class="fa fa-instagram"></i>
</a>
Icons & Social Networks supported by default
- Facebook
- Twitter
- Instagram
- GitHub
- LinkedIn
- Youtube
- Tumblr
- Vimeo
Methods
add
Add your URL to your social network with the add method. Use only if the social network is in the defaults listed above., (*9)
->add('http://facebook.com/user')
Returns:, (*10)
<a href="http://facebook.com/user" title="Facebook">
<i class="fa fa-facebook"></i>
</a>
addCustom
If your link is not in the supported defaults, use this method to create your own., (*11)
//addCustom($url, $class, $title=null)
->addCustom('http://some-other-network.com/user', 'fa fa-some-icon', 'My title!')
Returns:, (*12)
<a href="http://some-other-network.com/user" title="My title!">
<i class="fa fa-some-icon"></i>
</a>
title
Change the title for the default icons using this method., (*13)
->add('http://facebook.com/user')->title('Welcome to my Facebook page!')
Returns:, (*14)
<a href="http://facebook.com/user" title="Welcome to my Facebook page!">
<i class="fa fa-facebook"></i>
</a>
wrapper
Add a HTML element to wrap around your icons., (*15)
->add('http://facebook.com/user')->wrapper('<div class="wrapper">', '</div>')
Returns:, (*16)
<div class="wrapper">
<a href="http://facebook.com/user" title="Facebook">
<i class="fa fa-facebook"></i>
</a>
</div>
setClass
Add a custom class to the i element., (*17)
->add('http://facebook.com/user')->setClass('foobar')
Returns:, (*18)
<a href="http://facebook.com/user" title="Facebook">
<i class="fa fa-facebook foobar"></i>
</a>
setClass
Add a custom class to the i element., (*19)
->add('http://facebook.com/user')->setClass('foobar')
Returns:, (*20)
<a href="http://facebook.com/user" title="Facebook">
<i class="fa fa-facebook foobar"></i>
</a>
getHtml
Method to return the formatted HTML., (*21)
->getHtml()
getArray
Method to return the raw array of icons to easily format with your own markup, (*22)
->getArray()
Complete Example
Usage:, (*23)
//create the object
$icons = new LinusRendahl\SocialFontAwesome;
//add some icons with the add method
$icons
->add('http://www.facebook.com')
->add('http://twitter.com')->title('My Twitter Page!')
->add('http://instagram.com')->title('Cool pictures!')->setClass('foobar')
->wrapper('
', '
');
//get the html
$html = $icons->getHtml();
echo $html;
Returns:, (*24)
<div class="wrapper">
<a href="http://www.facebook.com" title="Facebook">
<i class="fa fa-facebook"></i>
</a>
<a href="http://twitter.com" title="My Twitter Page!">
<i class="fa fa-twitter"></i>
</a>
<a href="http://instagram.com" title="Cool pictures!">
<i class="fa fa-facebook foobar"></i>
</a>
</div>
History
v1.0.2
- Added as a composer package at Packagist.
v1.0