• HI I AM UNABLE TO FIND ANY KIND OF COMPLETE EXAMPLES OR DOCUMENTATION ON THE NEED I AM HAVING, I REALLY HOME YOU CAN HELP ME… I HAVE JUST BECOME A PAYING CUSTOMER AND I LOVE YOUR WORK BUT THERES IS ONE THING I NEED (I AM NOT AN EXPERIENCED USER):

    I NEED TO SHOW A CUSTOM POST TYPE LIST ORDERED BY THE BETTER RANKED (BY WP ULIKE), AND OTHER FOR THE WORST… I AM THINKING THE FIEST 5 AND THE LAST 5… SO I HAVE READ READ AND READ BUT DON NOT UNDERSTAND (I AM SORRY FOR MY LIMITED EXPERIENCE) SO I WAS THINKING TO PUT A CODE IN THEME FUNCTIONS SO I CAN CREATE A SHORTCODE THAT GIVES ME SOMETHING LIKE THIS….. [wpulike_posts type=”positive” posts_per_page=”5″ post_type=”prop” show_votes=”yes” order=”DESC”]

    THE PART OF THE CODE IN THE FUNCTIONS THEME IS THE TRICKY ONE:

    if  ( ! function_exists( 'wp_ulike_posts' ) ):
    	function wp_ulike_posts( $atts ) {
    
    		$return = '';
    
    		// Parameters accepted
    
    		extract( shortcode_atts( array(
    			'include_posts' => '',
    			'exclude_posts' => '',
    			'type' => 'positive',
    			'posts_per_page' => 5,
    			'category' => '',
    			'show_votes' => 'yes',
    			'post_type' => 'any',
    			'show_both' => 'no',
    			'order' => 'DESC',
    			'orderby' => 'meta_value_num'
    		), $atts ) );
    
    		// Check wich meta_key the user wants
    
    		if( $type == 'positive' ){
    
    				$meta_key = 'ulike_meta';
    				$sign = "+";
    				$other_sign = "-";
    		}
    		else{
    				$meta_key = 'udislike_meta';
    				$sign = "-";
    				$other_sign = "+";
    		}
    
    		// Build up the args array
    
    	  $args = array (
    	    'post_type'				=> $post_type,
    			'post_status'			=> 'publish',
    			'cat'					=> $category,
    			'pagination'			=> false,
    			'posts_per_page'		=> $posts_per_page,
    			'cache_results'			=> true,
    			'meta_key'				=> $meta_key,
    			'order'					=> $order,
    			'orderby'				=> $orderby,
    			'ignore_sticky_posts'	=> true
    		);
    
    		// Has to be done this way, or the query will return 0 results
    
    		if ($exclude_posts) {
    			$args['post__not_in'] = explode(",", $exclude_posts);
    		}
    
    		if ($include_posts) {
    			$args['post__in'] = explode(",", $include_posts);
    		}
    
    		// Get the posts
    
    		$wp_ulike_posts_query = new WP_Query($args);
    
    		// Build the post list
    
    		if($wp_ulike_posts_query->have_posts()) :
    
    			$return .= '<ol>';
    
    			while($wp_ulike_posts_query->have_posts()){
    
    				$wp_ulike_posts_query->the_post();
    
    				$return .= '<li>';
    
    				$return .= '<a href="' . get_permalink() . '">' . get_the_title() . '</a>';
    
    				if( $show_votes == "yes" ){
    
    					// Get the votes
    
    					$meta_values = get_post_meta(get_the_ID(), $meta_key);
    
    					// Add the votes to the HTML
    
    						$return .= ' (' . $sign;
    
    						if( sizeof($meta_values) > 0){
    
    							$return .= $meta_values[0];
    
    						}else{
    
    							$return .= "0";
    						}
    
    						// Show the other votes if needed
    
    						if( $show_both == 'yes' ){
    
    							$other_meta_values = get_post_meta(get_the_ID(), $other_meta_key);
    
    							$return .= " " . $other_sign;
    
    							if( sizeof($other_meta_values) > 0){
    
    								$return .= $other_meta_values[0];
    
    							}else{
    
    								$return .= "0";
    							}
    						}
    
    						$return .= ')';
    
    					}
    				}
    
    				$return .= '</li>';
    
    			$return .= '</ol>';
    
    			// Reset the post data or the sky will fall
    
    			wp_reset_postdata();
    
    		endif;
    
    		return $return;
    	}
    
    	add_shortcode( 'wp_ulike_posts_top', 'wp_ulike_posts' );
    endif;

    COUD YOU PLEASE HELP ME?

  • The topic ‘HI, NEED HELP WITH TOP POSTS SHORTCODE’ is closed to new replies.