【问题标题】:Wordpress: category page not for post'sWordpress:类别页面不适用于帖子
【发布时间】:2011-04-26 19:41:07
【问题描述】:

首先请让我解释一下我的问题。我使用 wordpress 为 Flash 游戏创建网站,所以我没有特定的页面供帖子使用。我添加每个游戏

<code>
    post-new.php?post_type=game
</code>

你可以看到它不是 wordpress 的常规帖子。 我尝试使用 codex 中的这段代码:

<code>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); 
    $i = 0;
    $loop = new WP_Query(array('post_type' => 'game', 'post_per_page' => 5 ));
    while ($loop->post_type()) : $loop->game();
    ?>
</code>
<code>
    <?php if ( in_category('') ) { ?>
               <div class="post-cat-three">
     <?php } else { ?>
               <div class="post">
     <?php } ?>
     <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

     <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>

     <div class="entry">
       <p>Category: <?php single_cat_title(); ?></p>

     </div>

     <p class="postmetadata">Posted in <?php the_category(', '); ?></p>  
</code>

我认为它确实必须适用于帖子,但在这种情况下,我尝试为游戏更改帖子,尝试了很多方法,但还没有成功。 谁能告诉我这段代码有什么变化? 我认为这个问题始于“有帖子”和“循环”。 谢谢。

【问题讨论】:

    标签: wordpress categories


    【解决方案1】:

    我希望这会有所帮助。这是来自我的 WordPress 自定义帖子类型(循环):

    <?php query_posts('post_type=clients&showposts=1000'); 
    

    if (have_posts()) : while (have_posts()) : the_post(); $nameofclient = get_post_meta($post->ID,'name_of_client',true); $clientcompany = get_post_meta($post->ID,'company_of_client',true);?> <div <?php post_class();?> id="ka-<?php the_ID(); ?>"> <h2 class="categorytitle"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> &lt;?php the_content(); ?&gt;&lt;p class="ats_autors"&gt;/ &lt;?php if($nameofclient): echo '&lt;span class="client"&gt;'.$nameofclient.'&lt;/span&gt;'; endif; if($clientcompany): if($nameofclient){echo ', ';} echo '&lt;span class="client-company"&gt;'.$clientcompany.'&lt;/span&gt;'; endif; ?&gt;&lt;/p&gt;&lt;/div&gt;&lt;?php endwhile; endif;wp_reset_query();?&gt;

    【讨论】:

    • 谢谢,但我无法将你的循环应用到我的代码中,可能是因为我的 php 技能低或其他原因,但我有一个错误分类页面。我尝试为我的类别更改您的“name_of_clients”和“公司”,但这没有帮助。无论如何,谢谢!
    • 这是用于“自定义post type”的,类似于帖子,正如我从您的代码中了解到的那样。是的,这不适用于categories
    【解决方案2】:

    刚刚发现一个错误:in_category('') 必须用 slug 中的类别 ID 填写。 http://codex.wordpress.org/Function_Reference/in_category#Parameters

    正确的是 in_category('some-game-cat-slug')

    另外值得一读http://new2wp.com/noob/query_posts-wp_query-differences/

    【讨论】:

      猜你喜欢
      • 2023-03-31
      • 1970-01-01
      • 2018-06-16
      • 2018-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多