【问题标题】:Display post and custom post type by user in wordpress在 wordpress 中按用户显示帖子和自定义帖子类型
【发布时间】:2015-02-28 15:53:35
【问题描述】:

我的模板页面 author.php 有一个奇怪的问题 我的页面显示用户创建的所有帖子和所有自定义 post_type。

我的问题: 如果用户在自定义 post_type "evenement" 中创建了一篇文章(总共只有一篇文章) 文章没有出现在模板页面author.php中,但是现在我的用户在默认的wordpress中创建了另一篇文章,两个帖子出现在模板页面author.php中

我的代码:

<?php
if(isset($_GET['author_name'])) :
$curauth = get_userdatabylogin($author_name);
else :
$curauth = get_userdata(intval($author));
?>   
 <div class="info-diffusion">

    <h1 class="postheader entry-title">Les tutos et astuces de <?php echo $curauth->nickname; ?></h1>

    <?php if (have_posts()) : query_posts('cat=172'); while (have_posts()) : the_post(); ?>
    <div class="dif-info-pack">
    <?php echo the_post_thumbnail('thumbnail'); ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>

    </div>
    <?php endwhile; wp_reset_query(); else :?>
    <p><?php echo $curauth->nickname; ?> n'a pas encore créé de tuto et astuce !</p>
    <?php endif;?>
    </div>






    <div class="info-diffusion">
    <h1 class="postheader entry-title">Les vidéos de <?php echo $curauth->nickname; ?></h1>

    <?php
    global $wp_query;
    $args = array_merge( $wp_query->query_vars, array( 'post_type' => 'post_video' ) );


    if (have_posts()) : query_posts( $args ); while (have_posts()) : the_post(); ?>
    <div class="dif-info-pack">
    <?php echo the_post_thumbnail('thumbnail'); ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>

    </div>
    <?php endwhile; wp_reset_query(); else :?>
    <p><?php echo $curauth->nickname; ?> n'a pas encore posté de vidéo !</p>
    <?php endif;?>
    </div>

第二个问题是管理员的问题,“未发布文章”的信息没有显示

如果你有一个想法... 特纳克的

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    WordPress query_posts() 函数完全替换了原来的查询,所以:

    <?php if (have_posts()) : query_posts('cat=172'); while (have_posts()) : the_post(); ?>
    

    测试 original 查询是否有任何帖子,然后替换该查询。可能不是你想要的。

    改为:

    <?php query_posts('cat=172&author=' . $curauth->ID); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    

    以正确的顺序获取内容,并在适当时显示“未发布文章”消息。请注意,由于您完全替换了查询,因此您需要添加 author 参数来完成您想要的操作。

    您的第二个 query_posts 也存在同样的顺序问题:

    query_posts( $args ); 
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-11
      • 2016-12-29
      • 2022-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多