php 社交媒体链接小工具与图标

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 社交媒体链接小工具与图标相关的知识,希望对你有一定的参考价值。

<?php

/**
 * Social Widget
 * Based on Bill Erickson's example from his Core Functionality plugin example.
 * An older version of Bill's code had a similar style widget example.
 *
 * @package      Core Functionality
 * @since        1.0.0
 * @link         https://github.com/billerickson/Core-Functionality
 * @author       Bill Erickson <bill@billerickson.net>
 * @author	 Patrick Boehner <patrick@patrickboehner.com>
 * @copyright    Copyright (c) 2011, Bill Erickson
 * @license      http://opensource.org/licenses/gpl-2.0.php GNU Public License
 */


//* Block Acess
//**********************************************

if( !defined( 'ABSPATH' ) ) exit;


// Setup Simple Social Widget
//**********************************************

class PB_Social_Widget extends WP_Widget {

	/**
	* Constructor
	* @return void
	**/
	function __construct() {
        $widget_ops = array(
            'classname' => 'widget_social_links',
            'description' => 'A simple social media icon widget'
         );
        	parent::__construct( 'social-widget', 'Social Media Links Widget', $widget_ops );
    	}

	/**
	 * Social Options
	 *
	 */
	function social_options() {
		return array(
			'facebook'  => 'Facebook',
			'youtube'	=> 'Youtube',
			'vimeo'		=> 'Vimeo',
			'linkedin'  => 'LinkedIn',
         'instagram' => 'Instagram',
         'twitter'   => 'Twitter',
         'pinterest' => 'Pinterest',
			'yelp'      => 'Yelp',
		);
	}

	/**
	* Outputs the HTML for this widget.
	* Includes schema for soical media porfiles as outlined by google
	*
	* @param array  An array of standard parameters for widgets in this theme
	* @param array  An array of settings for this widget instance
	* @return void Echoes it's output
	**/
	function widget( $args, $instance ) {
		extract( $args, EXTR_SKIP );
		echo $before_widget;

		if( $instance['title'] )
			echo $before_title . esc_html( $instance['title'] ) . $after_title;

		echo '<div class="social-links" itemscope itemtype="http://schema.org/Organization">';
		echo '<span class="screen-reader-text">Social media links</span>';
		echo '<link itemprop="url" href="' .get_bloginfo( 'url' ). '">';
		echo '<ul class=social-links-list>';

		$socials = $this->social_options();

		foreach( $socials as $key => $label ) {
			if( !empty( $instance[$key] ) )

         echo '<li class="social-item"><a class="social-icon icon-' . $key . '" itemprop="sameAs" href="' . esc_url( $instance[$key] ) . '" target="_blank" rel="noopener noreferrer" aria-label="' .$key. ' - Opens in new window"></a></li>';
		}
		echo '</ul></div>';

		echo $after_widget;
	}

	/**
	* Deals with the settings when they are saved by the admin. Here is
	* where any validation should be dealt with.
	*
	* @param array  An array of new settings as submitted by the admin
	* @param array  An array of the previous settings
	* @return array The validated and (if necessary) amended settings
	**/
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;

		$instance['title'] = esc_attr( $new_instance['title'] );
		$socials = $this->social_options();
		foreach( $socials as $key => $label )
			$instance[$key] = esc_url( $new_instance[$key] );

		return $instance;
	}

	/**
	* Displays the form for this widget on the Widgets page of the WP Admin area.
	*
	* @param array  An array of the current settings for this widget
	* @return void Echoes it's output
	**/
	function form( $instance ) {

		$socials = $this->social_options();
		$defaults = array( 'title' => '' );
		foreach( $socials as $key => $label )
			$defaults[$key] = '';
		$instance = wp_parse_args( (array) $instance, $defaults );

		echo '<p><label for="' . $this->get_field_id( 'title' ) . '">Title: <input class="widefat" id="' . $this->get_field_id( 'title' ) .'" name="' . $this->get_field_name( 'title' ) . '" value="' . esc_attr( $instance['title'] ) . '" /></label></p>';

		foreach( $socials as $key => $label )
			echo '<p><label for="' . $this->get_field_id( $key ) . '">' . $label . ' URL: <input class="widefat" id="' . $this->get_field_id( $key ) .'" name="' . $this->get_field_name( $key ) . '" value="' . esc_url( $instance[$key] ) . '" /></label></p>';

	}
}

//* Register the widget
add_action( 'widgets_init', 'pb_register_social_widget' );
function pb_register_social_widget() {
	
	register_widget('PB_Social_Widget');
	
}

以上是关于php 社交媒体链接小工具与图标的主要内容,如果未能解决你的问题,请参考以下文章

php 自动社交媒体链接

PHP WordPress中的自动社交媒体链接

尝试将社交媒体链接添加到 Drupal 网站

社交图标在移动设备和某些平板电脑中不起作用(链接不起作用,它们不会在悬停时更改图像)

社交媒体图标未出现

有没有办法使用 Flexbox 在媒体查询中将我的社交媒体图标居中?