Hello Wordpress connoisseurs. I'm just starting to learn the basics of PHP and Wordpress, and now I am faced with such a thing. I bring social. Icons via the shortcode [alx-social id = "Vk, Twitter"] in id write down the names of the social network. If in the database it is, then we output it. I can not make them appear in the order in which they are written, they are displayed according to their own order.
Here is the shortcode function
// ΠΡΠ²ΠΎΠ΄ ΡΠΎΡΠΈΠ°Π»ΡΠ½ΡΡ
ΠΈΠΊΠΎΠ½ΠΎΠΊ Π¨ΠΠ Π’ΠΠΠ function alx_social($attr,$text=''){ //ΠΠ»ΠΎΠ±Π°Π»ΡΠ½ΡΠΉ ΠΌΠ°ΡΡΠΈΠ² ΠΎΠΏΡΠΈΠΉ global $options; // ΠΠΎΠ»ΡΡΠ°Π΅ΠΌ ΠΌΠ°ΡΡΠΈΠ² Π΄Π°Π½Π½ΡΡ
ΠΈΠ· Π°ΡΡΠΈΠ±ΡΡΠΎΠ² ΡΠΎΡΡΠΊΠΎΠ΄Π° ΠΈ ΠΏΡΠ΅Π²ΡΠ°ΡΠ°Π΅ΠΌ ΠΈΡ
Π² ΠΌΠ°ΡΡΠΈΠ² $razbienie = explode(',', $attr['id']); // ΠΡΠ΅ΠΎΠ±ΡΠ°Π·ΡΠ΅ΠΌ Π²ΡΠ΅ ΡΠ»Π΅ΠΌΠ΅Π½ΡΡ ΠΌΠ°ΡΡΠΈΠ²Π° Π² Π½ΠΈΠΆΠ½ΠΈΠΉ ΡΠ΅Π³ΠΈΡΡΡ $razbienie = array_map('strtolower', $razbienie); ?> <!--ΠΠΎΠΌΠ΅ΡΠ°Π΅ΠΌ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π² ΠΎΡΠ΄Π΅Π»ΡΠ½ΡΠΉ Π±Π»ΠΎΠΊ--> <div class="alx-socials"> <?php // ΠΠ΅ΡΠ΅Π±Π΅ΡΠ°Π΅ΠΌ ΠΠ°ΡΡΠΈΠ² ΠΎΠΏΡΠΈΠΉ ΠΈ ΠΌΠ°ΡΡΠΈΠ² ΠΈΠ· ΡΠΎΡΡΠΊΠΎΠ΄Π° Π΅ΡΠ»ΠΈ Π΅ΡΡΡ ΡΠΎΠ²ΠΏΠ°Π΄Π΅Π½ΠΈΡ Π²ΡΠ²ΠΎΠ΄ΠΈΠΌ ΠΈΡ
Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ foreach($options as $key => $value1){ foreach($razbienie as $value2){ if ($key == $value2){ switch($key){ case 'twitter': echo '<a href="'. $options["twitter"] .'"> <i class="fa fa-twitter" aria-hidden="true"></i> </a>'; break; case 'facebook': echo '<a href="'. $options["facebook"] .'"> <i class="fa fa-facebook" aria-hidden="true"></i> </a>'; break; case 'instagram': echo '<a href="'. $options["instagram"] .'"> <i class="fa fa-instagram" aria-hidden="true"></i> </a>'; break; case 'vk': echo '<a href="'. $options["vk"] .'"> <i class="fa fa-vk" aria-hidden="true"></i> </a>'; break; case 'youtube': echo '<a href="'. $options["youtube"] .'"> <i class="fa fa-youtube" aria-hidden="true"></i> </a>'; break; case 'google': echo '<a href="'. $options["google"] .'"> <i class="fa fa-google-plus" aria-hidden="true"></i> </a>'; break; case 'pinterest': echo '<a href="'. $options["pinterest"] .'"> <i class="fa fa-pinterest-p" aria-hidden="true"></i> </a>'; break; case 'flickr': echo '<a href="'. $options["flickr"] .'"> <i class="fa fa-flickr" aria-hidden="true"></i> </a>'; break; case 'linkedin': echo '<a href="'. $options["linkedin"] .'"> <i class="fa fa-linkedin" aria-hidden="true"></i> </a>'; break; } // end switch }// end if }// end forech 2 }// end foreach 1 ?> </div> <!--end .alx-socials--> <?php } add_shortcode('alx-social', 'alx_social'); Thank you in advance.