0

我正在使用 Instant-QA 主题,需要使用widget提出问题的用户的图像来更新最近的帖子。我在网站functions.php的子域中使用以下代码wordpress。目前它显示的是简单的帖子——下面的代码有什么猜测吗?

function print_requested_template_part() {
    // Respond only to requests from the same address... 
    if ( $_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['including_template_part']) && isset($_GET['load_part']) && $_GET['load_part'] != '' ) {
        $part = $_GET['load_part'];
        $func = 'render_' . str_replace('-', '_', $part); // if you have declared a function called "render_footer_include", then "?load_part=footer_include"
        if ( function_exists($func) ) {
            // Allow for passing parameters to the function
            if ( isset($_GET['params']) ) {
                $params = $_GET['params'];
                $params = ( strpos($params, ',') !== false )? explode(',', $params) : array($params);
                call_user_func_array($func, $params);
            } else {
                call_user_func($func);
            }
        }
        exit; // if we don't exit here, a whole page will be printed => bad! it's better to have empty footer than a footer with the whole main site...
    }
}
add_action('init', 'print_requested_template_part', 1);

function render_my_recent_posts( $numberposts = 5 ) { ?>

    <ul>
    <?php
        $args = array( 'numberposts' => '5' );
        $recent_posts = wp_get_recent_posts( $args );
        foreach( $recent_posts as $recent ) {
            echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' .   $recent["post_title"].'</a> </li> ';
        }
    ?>
    </ul><?php
}
4

1 回答 1

0

不要浪费时间沉迷于上面的代码。在插件下方使用并获得即时输出。

http://wordpress.org/extend/plugins/recent-comments-with-avatars/使用这个插件

谢谢

于 2012-11-21T12:21:37.993 回答