webForumDet fria alternativet

Lägga till Share-buttons-rad i varje widget

PHP

0 svar · 441 visningar · startad av LimeS

Medlem sedan maj 201036 inlägg
Frågan#1

Hej!

På den här sidan: http://xnn etwork.c om/par ado x/ (ta bort mellanslagen för att besöka)
Skulle jag vilja ha en rad med share-knappar i slutet av varje widget! (framsiden är halvt uppbyggd av widgets)

Coden för home-widget är:

<?php

	//Adds our custom wdiget hook
	add_action( 'widgets_init', 'paradoxHomeWidget' );
	
	function paradoxHomeWidget() {
		
		register_widget( 'Paradox_Home_Widget' );
		
	}
	
	////////////////////////////
	//OUR WIDGET
		////////////////////////////
	class Paradox_Home_Widget extends WP_Widget {
		
		
		
		function Paradox_Home_Widget() {
			
			$widget_ops = array( 'classname' => 'home-post', 'description' => __('Insert blocks of content into your homepage using this widget', 'home-post') );

			/* Widget control settings. */
			$control_ops = array( 'width' => 350, 'height' => 450, 'id_base' => 'home-post-widget' );

			/* Create the widget. */
			$this->WP_Widget( 'home-post-widget', __('PARADOX - Home Content Widget', 'home-post'), $widget_ops, $control_ops );
			
		}
		
		
		
		
		//////////////////////////////
		//Our widget form
		//////////////////////////////
		function form( $instance ) {
	
			//Our default settings
			$defaults = array( 'title' => __('Example', 'home-post'), 'read_more' => __('read more', 'home-post') );
			$instance = wp_parse_args( (array) $instance, $defaults ); ?>
	
			<!-- Widget Title: Text Input -->
			<p>
			
				<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'hybrid'); ?></label>
                <input type="text" value="<?php echo $instance['title']; ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" id="<?php echo $this->get_field_id( 'title' ); ?>" class="widefat">
				
			</p>
	
			<!-- Widget Icon: Text Input -->
			<p>
			
				<label for="<?php echo $this->get_field_id( 'icon' ); ?>"><?php _e('Icon URL:', 'hybrid'); ?></label>
                <input type="text" value="<?php echo $instance['icon']; ?>" name="<?php echo $this->get_field_name( 'icon' ); ?>" id="<?php echo $this->get_field_id( 'icon' ); ?>" class="widefat">
				
			</p>
	
			<!-- Widget Text: Textarea -->
			<p>
			
				<label for="<?php echo $this->get_field_id( 'text' ); ?>"><?php _e('Text (HTML Accepted):', 'hybrid'); ?></label>
                <textarea name="<?php echo $this->get_field_name( 'text' ); ?>" id="<?php echo $this->get_field_id( 'text' ); ?>" cols="20" rows="10" class="widefat"><?php echo $instance['text']; ?></textarea>
				
			</p>
	
			<!-- Widget Button URL: Text Input -->
			<p>
			
				<label for="<?php echo $this->get_field_id( 'url' ); ?>"><?php _e('Button URL:', 'hybrid'); ?></label>
                <input type="text" value="<?php echo $instance['url']; ?>" name="<?php echo $this->get_field_name( 'url' ); ?>" id="<?php echo $this->get_field_id( 'url' ); ?>" class="widefat">
				
			</p>
	
			<!-- Widget Button Text: Text Input -->
			<p>
			
				<label for="<?php echo $this->get_field_id( 'read_more' ); ?>"><?php _e('Button Text:', 'hybrid'); ?></label>
                <input type="text" value="<?php echo $instance['read_more']; ?>" name="<?php echo $this->get_field_name( 'read_more' ); ?>" id="<?php echo $this->get_field_id( 'read_more' ); ?>" class="widefat">
				
			</p>
	
		<?php 
			
		}
		
		
		
		////////////////////////////////
		// OUR UPDATE
		////////////////////////////////
		
		function update( $new_instance, $old_instance ) {
			
			$instance = $old_instance;
	
			//REMOVE HTML FROM THESE
			$instance['title'] = strip_tags( $new_instance['title'] );
			$instance['icon'] = strip_tags( $new_instance['icon'] );
			$instance['url'] = strip_tags( $new_instance['url'] );
			$instance['read_more'] = strip_tags( $new_instance['read_more'] );
	
			//DO NOT REMOVE HTML TAGS FROM THESE
			$instance['text'] = $new_instance['text'];
	
			return $instance;
			
		}
		
		
		
		///////////////////////////////////
		// DISPLAYS OUR WIDGET
		///////////////////////////////////
		
		function widget( $args, $instance ) {
			
			extract( $args );
	
			// OUR WIDGET VARIABLES
			$title = apply_filters('widget_title', $instance['title'] );
			$iconUrl = $instance['icon'];
			$url = $instance['url'];
			$button = $instance['read_more'];
			$text = $instance['text'];
	
			//BEFORE WIDGET DEFINED BY THE THEME
			echo $before_widget;
			
				//OUR TITLE & ICON
				echo '<h3 class="title icon"><span><img src="'.$iconUrl.'" alt="icon" /></span>'.$title.'</h3>';
				
				// OUR TEXT
				echo '<p>'.$text.'</p>';
				
				if(($url != NULL) && ($button != NULL)) {
				
					//OUR READ MORE BUTTON
					echo '<p><a href="'.$url.'" class="button-color"><span></span>'.$button.'</a></p>';
				
				}
	
			//AFTER WIDGET, DEFINED BY THE THEME
			echo $after_widget;
			
		}
	
	} 

?>

Och jag vill lägga in denna sträng så att share-ikonerna syns strax under länk-knappen i widgeten:

<?php if( function_exists('ADDTOANY_SHARE_SAVE_KIT') ) { ADDTOANY_SHARE_SAVE_KIT(); } ?>

Har provat nu några gånger och får det inte att fungera.. Blir superglad av hjälp (y)

260 ms totalt · 4 externa anrop · v20260731065814-full.1dc6f849
125 ms — deklarationer (db)
0 ms — hämta statistik (cache)
131 ms — hämta tråd, inlägg och bilagor (db)
126 ms — ändringar (db)