Great plugin! Suggestion for improvement.
-
This is the only plugin I have found that will let me add non-standard links and completely customize the icon set.
I have modified the cn-social-icons shortcode to add many parameters so that the output can be customized differently for each instance, if needed. Perhaps this could be included in a future release.
Here is the code:
/* Modified version of [cn-social-icons] from Easy Social Icons plugin. * * Added all the parameters to the shortcode. All parameters are optional. * * Description: Returns an unordered list of icons and optional labels as * defined in 'Easy Social Icon'->'Add Icons'. * * Usage: [cg_social_icons * width=nn * height=nn * margin=nn * rows=nn * vertical=[yes|no] * text_align=[left|center|right] * labels=[yes|no] * icons=[all|(csv list of icon titles)] * class=[class_name] * ] * * Parameters: * width - * The width in pixels for the icons. Example: width=16 * Default is the value set in 'Easy Social Icon'->Options. * * height - * The height in pixels for the icons. Example: height=16 * Default is the value set in 'Easy Social Icon'->Options. * * margin - * The margin in pixels around the icons. Left and right * margins will be set to 1/2 this value. * Default is the value set in 'Easy Social Icon'->Options. * * rows - * The number of rows of icons (unused). * Default is the value set in 'Easy Social Icon'->Options. * * vertical - * The vertical or horizontal display of the icons. * If set to 'yes', the icons will be displayed vertically. * If set to 'no', the icons will be displayed horizontally. * Default is the value set in 'Easy Social Icon'->Options. * * text_align - * Alignment of the icons. * If set to 'left', the icons will be aligned left. * If set to 'center', the icons will be aligned center. * If set to 'right', the icons will be aligned right. * Default is the value set in 'Easy Social Icon'->Options. * * labels - * Option to print the Icon Title as a label for the icons. * If set to 'yes', the labels will be printed. * Default is 'no'. * * icons - * An optional comma separated list of Icon Titles to print. * If specified, icons will be printed in the order listed. * If omitted, or set to 'all', all icons will be printed in * the order set in 'Easy Social Icon'->'Sort Icons'. * * class - * An optional class name to be added to the '<ul>' tag in * addition to the class 'cnss-social-icon' which is always * added. * Default is none. * */ function cg_social_icons_fn( $atts ) { global $wpdb,$baseURL; $attrs = shortcode_atts( array( 'width' => get_option('cnss-width'), 'height' => get_option('cnss-height'), 'margin' => get_option('cnss-margin'), 'rows' => get_option('cnss-row-count'), 'vertical' => 'default', 'text_align' => get_option('cnss-text-align'), 'labels' => 'no', 'icons' => 'all', 'class' => '', ), $atts ); extract( $attrs ); if ( $vertical == 'default' ) { $vorh = get_option('cnss-vertical-horizontal'); } else { $vorh = ($vertical == 'yes') ? 'vertical' : 'horizontal'; } // Convert icons list to csv for use in sql IN clause, if necessary if ( $icons == 'all' ) { $post_title_sql = ' 1 = 1 '; } else { $icon_names = explode( ',', strtolower($icons) ); $icon_names = array_map( 'trim', $icon_names ); $icon_list = '"' . implode( '","', $icon_names) . '"'; $post_title_sql = ' LOWER(title) IN (' . $icon_list . ') '; } $table_name = $wpdb->prefix . "cn_social_icon"; $image_file_path = $baseURL; $sql = "SELECT * FROM ".$table_name." WHERE $post_title_sql AND image_url<>'' AND url<>'' ORDER BY sortorder"; $video_info = $wpdb->get_results($sql); $icon_count = count($video_info); // Sort in order of icons parameter, if needed $out = ''; if ( $video_info ) { if ( $icons != 'all' ) { usort($video_info, function($a, $b) use ($icon_names) { return array_search(strtolower($a->title), $icon_names) - array_search(strtolower($b->title), $icon_names); } ); } $_collectionSize = count($video_info); $_rowCount = $rows ? $rows : 1; $_columnCount = ceil($_collectionSize/$_rowCount); $li_margin = round($margin/2); ob_start(); echo '<ul class="cnss-social-icon ' . $class . '" style="text-align:'.$text_align.';">'; $i=0; foreach($video_info as $icon) { if(strpos($icon->image_url,'/')===false) { $image_url = $image_file_path.'/'.$icon->image_url; } else { $image_url = $icon->image_url; } ?><li class="<?php echo format_title($icon->title); ?>" style=" <?php echo $vorh=='horizontal'?'display:inline-block;':''; ?>"> <a <?php echo ($icon->target==1)?'target="_blank"':'' ?> title="<?php echo $icon->title ?>" href="<?php echo $icon->url ?>"><img src="<?php echo $image_url?>" border="0" width="<?php echo $width ?>" height="<?php echo $height ?>" alt="<?php echo $icon->title ?>" style=" <?php echo 'margin:'.$li_margin.'px;'; ?>" /> <?php echo ($labels == 'yes') ? $icon->title : '';?> </a> </li><?php $i++; } echo '</ul>'; $out = ob_get_contents(); ob_end_clean(); } return $out; } add_shortcode( 'cg-social-icons', 'cg_social_icons_fn' );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Great plugin! Suggestion for improvement.’ is closed to new replies.