• Resolved RobertMueller

    (@robertmueller)


    Hi Ajay,

    first of all: Thanks a lot for this awesome plugin! Helped me a lot.
    I’m trying to implement some custom post list on a page using get_tptn_pop_posts within a self-made shortcode.
    I would really appreciate your advice on a problem I’m encountering …

    Objective:
    – List posts links from a specific category on a page
    – Category slug: ablagesystem
    – category ID: 4
    – Posts ordered by access count top-down
    – Number of posts limit: none (display all posts)
    – Relevant count time range: 30 days
    – List style: unordered
    – Implement via shortcode (no template coding wanted)
    – Link: http://hochproduktiv.de/ablage-organisieren-dokumente-verwalten-buero-privat-zu-hause-dokumentenmanagement-ablagesystem/

    Code in functions.php:

    function tptn_shortcode_ablagesystem( $atts, $content = null ) {
    	if ( function_exists( 'get_tptn_pop_posts' ) ) {
    
    		$list ='';
    
    		$settings = array(
    			'daily' => TRUE,
    			'daily_range' => 30,
    			'strict_limit' => FALSE,
    		);
    
    		$topposts = get_tptn_pop_posts( $settings ); // Array of posts
    
    		$topposts = wp_list_pluck( $topposts, 'postnumber' );
    
    		$args = array(
    			'post__in' => $topposts,
    			'orderby' => 'post__in',
    			'post_type' => 'post',
    			'cat' => '4',
    		);
    
    		$my_query = new WP_Query( $args );
    		if ( $my_query->have_posts() ) {
    			$list = '<ul>';
    			while ( $my_query->have_posts() ) {
    				$my_query->the_post();
    				$list = $list . '<li><a href="' . get_permalink( get_the_ID() ) . '">' . get_the_title() . '</a></li>';
    				wp_reset_postdata();
    			}
    			$list = $list . '</ul>';
    
    		} else {
    		}
    		wp_reset_query();
    		return $list;
    	}
    }
    add_shortcode( 'tptn_list_ablagesystem', 'tptn_shortcode_ablagesystem' );

    Problem:
    – Seven posts in respective category online
    – Only five displayed (should be seven), seems to restrict to five regardless of arguments
    – Not sure, if $settings are considered
    – Not sure, if post ranks / post order are stored in ‘postnumber’

    Do you have any idea as to where I went wrong?
    Thanks for your help in advance!

    Robert

    https://wordpress.org/plugins/top-10/

Viewing 8 replies - 16 through 23 (of 23 total)
  • right now it can fetch featured image but for posts related to the category without a featured image its fetching the a featured image from the very first post which is in a different category..
    here the current code:

    function tptn_shortcode_songreviews( $atts, $content = null ) {
    	if ( function_exists( 'get_tptn_pop_posts' ) ) {
    
    		$list ='';
            $settings = array(
                    'daily' => TRUE,
                    'daily_range' => 7,
                    'limit' => 3,
                    'strict_limit' => FALSE,
            );
    
    		$topposts = get_tptn_pop_posts( $settings ); // Array of posts
    
    		$topposts = wp_list_pluck( $topposts, 'postnumber' );
    
    		$args = array(
    			'post__in' => $topposts,
    			'orderby' => 'post__in',
    			'post_type' => 'post',
    			'cat' => '5',
    			'posts_per_page' => '3',
    		);
    
    		$my_query = new WP_Query( $args );
    		if ( $my_query->have_posts() ) {
    			$list = '<ul class="top-pick">';
    			while ( $my_query->have_posts() ) {
    				$my_query->the_post();
    				$list = $list. '<li><a href="' . get_permalink( get_the_ID() ) . '" class="topp-img-container">';
                    $list = $list.
                        tptn_get_the_post_thumbnail( array(
    						'postid' => get_the_id,
    						//'thumb_height' => '45',
    						//'thumb_width' => '45',
    						'thumb_meta' => $thumb_meta,
    						'thumb_html' => $thumb_html,
    						'thumb_default' => $thumb_default,
    						'thumb_default_show' => $thumb_default_show,
    						'scan_images' => $scan_images,
    						'class' => "tptn_thumb topp-img img-responsive",
    					) ); //thumbnail
    
                    $list = $list.'</a>';
                    $list = $list. '<span class="topp-title"><a href="' . get_permalink( get_the_ID() ) . '">' . get_the_title() . '</a></span></li>';
    				wp_reset_postdata();
    			}
    			$list = $list . '</ul>';
    		} else {
                echo "no top picks yet";
    		}
    		wp_reset_query();
    		return $list;
    	}
    }
    add_shortcode( 'tptn_list_songreviews', 'tptn_shortcode_songreviews' );

    —————
    as for the numbering currently using css counters so that i can style it more

    Plugin Author Ajay

    (@ajay)

    Hi,

    So were you able to resolve this?

    hi,
    showing of featured images yes But those without featured images doesn’t use the default placeholder thumbnail instead it fetches my first upload in my media library..
    middle one in this pic is has a featured image set up while the rest isnt.
    http://i57.tinypic.com/snfd04.png

    Plugin Author Ajay

    (@ajay)

    Hi, The plugin function tptn_get_the_post_thumbnail tries to get the first image linked to the post as well using the get_children function.

    Since it’s only a screenshot, what is the actual HTML being generated?

    well its not getting the first image of the post because I haven’t set any instead its getting my first upload in my wordpress media library.
    http://i57.tinypic.com/kcdwnt.png

    code output of no featured post set

    <li>
    <a href="http://indiecore/2015/06/18/song-review-alpha-betas-newest-single-title/" class="topp-img-container">
    <img src="http://indiecore/wp-content/uploads/2015/06/cgdrawing-e1434519307675-320x175.png" alt="" title="" width="150" height="150" class="tptn_thumb topp-img img-responsive tptn_firstchild"></a>
    <span class="topp-title">
    <a href="http://indiecore/2015/06/18/song-review-alpha-betas-newest-single-title/">song review alpha beta’s: newest single title</a>
    </span>
    </li>

    I have set a different placeholder image in your top10 settings

    Plugin Author Ajay

    (@ajay)

    Hi,

    Looking at the output it is pulling out “tptn_firstchild” which is the first attachment (i.e. image) for the post.

    https://codex.wordpress.org/Function_Reference/get_children

    If you go to your media library and find the image above, what do you see under Uploaded to column?

    its attached to hello world posts which is the wordpress 1st posts. which is still under uncategorized. the category i set this code is 3 which is called ‘song reviews’

    Plugin Author Ajay

    (@ajay)

    Hi,

    Could you please see what you can do with this plugin?

    https://wordpress.org/plugins/unattach/

Viewing 8 replies - 16 through 23 (of 23 total)
  • The topic ‘List all posts from specific category ordered by access count via shortcode’ is closed to new replies.