动态过滤类别循环


Filter Category Loop Dynamically

我正在尝试显示一个带有动态类别过滤器的自定义循环。

作为一个设置,我有所有用户名的类别,这些类别是在用户创建帐户时创建的。

所以我试图回显用户的用户名作为类别过滤器。它工作时,我的echo是在页面的其他地方,但它不工作,当我试图嵌入它像这样:

<?php query_posts('category_name=global $current_user; if ( isset($current_user) ) {echo $current_user->user_login;} &posts_per_page=10'); ?> &posts_per_page=6'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>  
<?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?>
<?php endwhile; else: ?>
NO Posts Present 
<?php endif; ?>

在不确定是否应该使用query_posts的情况下,您可以尝试重构您的查询。

<?php
  global $current_user;
  $cat = (isset($current_user)) ? "category_name=$current_user->user_login&" : "";
  query_posts($cat . 'posts_per_page=6'); 
?>

您可能也想阅读有关query_posts的文档