【问题标题】:How to show only the articles from current category in wordpress?如何在wordpress中只显示当前类别的文章?
【发布时间】:2014-03-22 11:02:31
【问题描述】:

我只想显示当前类别中的文章,我目前所在的位置。我写了代码来查看每一篇文章。我使用插件高级自定义字段,它可以为管理中的新帖子创建更多字段。

现在我有了这个代码:

<?php $the_query = new WP_Query( 'cat=' ); ?>
<div id="category-window">
<div id="others" style="width:<?php echo $wp_query->post_count*400?>px"> 
  <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
  <div class="other-box">
    <div id="other-name"><?php the_title(); ?></div>
    <div id="other-left"><?php the_field(misto); ?><br><?php the_field(rok); ?></div>
    <div id="other-right"><?php foreach((get_the_category()) as $category) {echo $category->cat_name . '<br>';} ?></div>
    <div id="other-line"></div>
    <div id="other-about"><?php the_field(dej); ?></div>
    <div id="other-gallery">
      <a class="other-photo fancybox" rel="<?php the_title(); ?>" href="<?php the_field(obrazek1); ?>">
    <img src="<?php the_field(obrazek1); ?>" style="width: 85px; height: 50px;">
      </a>
      <a class="other-photo fancybox" rel="<?php the_title(); ?>" href="<?php the_field(obrazek2); ?>">
    <img src="<?php the_field(obrazek2); ?>" style="width: 85px; height: 50px;">
      </a>
      <a class="other-photo fancybox" rel="<?php the_title(); ?>" href="<?php the_field(obrazek3); ?>">
    <img src="<?php the_field(obrazek3); ?>" style="width: 85px; height: 50px;">
      </a>
    </div>
    </div><?php endwhile; ?>
</div>
</div>

问题就在第一行,我不知道在“cat =”后面写什么,当我想自动执行时。例如,当我在“汽车”类别中时,它会自动仅显示该类别中的文章。

感谢您的每一个帮助:)

【问题讨论】:

    标签: php wordpress categories


    【解决方案1】:

    这样的事情应该可以工作:

    <?php
    
    $postid = get_the_ID();
    $catid = get_the_category( $postid );
    
    ?>
    

    这应该让你得到猫的身份。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多