最近发布的Wordpress Q和A主题的图片

时间:2012-11-21 11:45:46

标签: php wordpress

我正在使用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
}

1 个答案:

答案 0 :(得分:0)

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

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

三江源