0

我正在尝试使用动态类别过滤器显示自定义循环。

作为设置,我有所有用户名的类别,一旦用户创建帐户,就会创建这些用户名。

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

<?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; ?>

任何帮助将不胜感激,谢谢。

4

1 回答 1

1

在不解决是否应该使用 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的文档。

于 2013-03-03T06:06:33.630 回答