Wordpress - 从多位作者那里获取帖子?

时间:2014-02-27 07:36:34

标签: wordpress

使用允许用户互相关注的第三方插件,我们可以检索被关注的用户(评论): -

<?php if (have_posts()) : ?>
        <?php global $userpro_social;

        $following = $userpro_social->following( get_current_user_id() ); //get users the current user is following
        print_r($following) ?> // print the array so we can see who we're following


        <?php $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; ?>     
        <?php query_posts( array( 'author'=> ??? , 'paged' => $paged, ) ); ?>      

        <?php while ( have_posts() ) : the_post() ?>


            <?php if ( has_post_format( 'video' )) {
                    get_template_part( 'video-post' );
                }elseif ( has_post_format( 'image' )) {
                    get_template_part( 'image-post' );
                } else {
                   get_template_part( 'standard-post' );
                }

            ?>

        <?php endwhile;?>

        <?php endif; ?>

所以这会输出类似这样的东西

数组([24] =&gt; 1 [1] =&gt; 1)

即,我们关注ID为1和24的用户,这很简单吗?

我迷失的部分就是这个

<?php query_posts( array( 'author'=> ??? , 'paged' => $paged, ) ); ?>

我如何实际输出这些用户的帖子,它已经存储在数组中,所以我认为它应该很容易,但即使在阅读完该脚本后我也无法弄明白。

2 个答案:

答案 0 :(得分:2)

如果要从多位作者检索帖子,则需要使用author__in参数

query_posts( array( 'author__in'=> array_keys($following) , 'paged' => $paged, ) );

答案 1 :(得分:1)

在Rafh上扩展

public class MyActivity extends ActionBarActivity {
private ImageView ivBackground;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
    ivBackground = (ImageView) findViewById(R.id.iv_background);
    String imageUri = "https://upload.wikimedia.org/wikipedia/commons/c/c2/Macau-bus-1032.jpg";
    ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.init(ImageLoaderConfiguration.createDefault(this));
    DisplayImageOptions options = new DisplayImageOptions.Builder()
            .showImageForEmptyUri(Color.TRANSPARENT)
            .showImageOnFail(Color.TRANSPARENT)
            .resetViewBeforeLoading(true)
            .cacheOnDisk(true)
            .cacheInMemory(false)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .considerExifParams(true)
            .displayer(new FadeInBitmapDisplayer(300))
            .build();

    imageLoader.displayImage(imageUri, ivBackground, options, new SimpleImageLoadingListener() {


        @Override
        public void onLoadingComplete(final String imageUri, View view, final Bitmap loadedImage) {
Bitmap bmpTest = BitmapFactory.decodeResource(getResources(), R.drawable.test);
//final Bitmap cropedBitmap = Bitmap.createBitmap(bmpTest, 0, 0, bmpTest.getWidth() / 2, bmpTest.getHeight());
final Bitmap cropedBitmap = Bitmap.createBitmap(loadedImage, 0, 0, loadedImage.getWidth() / 2, loadedImage.getHeight());

            ivBackground.setImageBitmap(cropedBitmap);
            new AsyncTask<Void, Void, Bitmap>() {
                @Override
                protected Bitmap doInBackground(Void... params) {
Bitmap bitmap = ((BitmapDrawable) ivBackground.getDrawable()).getBitmap();
            return blurBitmap(bitmap);
                }

                @Override
                protected void onPostExecute(Bitmap aVoid) {
                    ivBackground.setImageBitmap(aVoid);
                }
            }.execute();
        }

        @Override
        public void onLoadingCancelled(String imageUri, View view) {

        }
    });
}
private Bitmap blurBitmap(Bitmap bitmap) {
    Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);

    RenderScript rs = RenderScript.create(MyActivity.this);
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
    Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);
    blurScript.setRadius(25.f);
    blurScript.setInput(allIn);
    blurScript.forEach(allOut);
    allOut.copyTo(outBitmap);
    bitmap.recycle();
    rs.destroy();
    return outBitmap;
}