PHP通过短代码始终在页面顶部

I got a plugin for wordpress to show the most popular posts...

But when I add it via shortcode it always gets to the top of the page and not where I placed it... I changed every echo in the plugin PHPs to return but it didn't helped... Here is my shortcode in functions.php:

function top_news(){
     $args = array(
    'limit' => 15,
    'range' => 'daily',
'freshness' => 1,
 'order_by' => 'views',
'post_type' => 'post',
'stats_views' => 1,
'stats_author' => 1,
 'stats_date' => 1,
'wpp_start' => '<table class="topnachrichten"><tr><th>Datum</th><th>Top Nachrichten von Heute</th><th>Leser</th></tr>',
    'wpp_end' => '</table>',
'stats_date_format' => 'd',
'excerpt_by_words' => 1,
    'excerpt_length' => 35,
'title_length' => 66,
 'post_html' => '<tr><td class="datum">{date}. Aug</td><td class="stext"><details>
  <summary><a href="{url}">{title}</a><span class="plus">+</span></summary>{summary}<br><a href="{url}">Weiterlesen</a></details></td><td class="views">{views}</td></tr>'


);
    wpp_get_mostpopular( $args );
    return $args;
}
add_shortcode( 'topnews', 'top_news' );

Do you know what I can do?

Thanks, Till

</div>

Reading documentation of wpp_get_mostpopular, it states that the function actually prints the popular posts. Which means your popular posts are printed out before it returns anything and since all shortcodes are processed before the posts content is being printed that's why your popular posts always prints before (at top) of the post content.

So, what you can do is catch all the popular posts in a buffer.

function top_news(){
     $args = array (
        'limit' => 15,
        'range' => 'daily',
        'freshness' => 1,
        'order_by' => 'views',
        'post_type' => 'post',
        'stats_views' => 1,
        'stats_author' => 1,
        'stats_date' => 1,
        'wpp_start' => '<table class="topnachrichten"><tr><th>Datum</th><th>Top Nachrichten von Heute</th><th>Leser</th></tr>',
        'wpp_end' => '</table>',
        'stats_date_format' => 'd',
        'excerpt_by_words' => 1,
        'excerpt_length' => 35,
        'title_length' => 66,
        'post_html' => '<tr><td class="datum">{date}. Aug</td><td class="stext"><details>
        <summary><a href="{url}">{title}</a><span class="plus">+</span></summary>{summary}<br><a href="{url}">Weiterlesen</a></details></td><td class="views">{views}</td></tr>'
    );

    ob_start();
    wpp_get_mostpopular( $args );
    $output = ob_get_contents();
    ob_end_clean();

    return $output;
}
add_shortcode( 'topnews', 'top_news' );