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.

    1 answer 1

    It seems to be the way it should work. Changed social media output cycle to div

     <?php //ΠŸΠ΅Ρ€Π΅Π±ΠΈΡ€Π°Π΅ΠΌ принятыС названия соцсСтСй foreach($razbienie as $social_name){ //Если соц.ΡΠ΅Ρ‚ΡŒ сущСствуСт Π² массивС $options Ρ‚ΠΎ Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌ Π΅Ρ‘. if (array_key_exists($social_name, $options)){ switch($social_name){ 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 foreach ?>