Wordpress |模板| category-id.php |显示包含链接的帖子列表

时间:2016-06-30 11:54:24

标签: wordpress while-loop categories custom-wordpress-pages

我正在创建类别模板(按ID)。在每个类别模板中,我需要显示帖子标题列表(及其链接)。

我正在使用的代码(如下)无效。我已经使用echo检查了变量,并且正在输入正确的ID号,所以我假设故障在于WHILE循环。

任何和所有帮助都非常感激。

<div class="col-xs-12" style="text-align:justify;">
<table class="table table-striped">

    <?php

    $category = get_category( get_query_var( 'cat' ) );
    $cat_id = $category->cat_ID;                            

    $query = new WP_Query( array( 'cat' => '70', 'orderby' =>
    'title', 'order' => 'ASC', 'posts_per_page' => '-1' ) ); 

    while ( $query->have_posts() ) : $query->the_post();

    echo '<tr><td><a href="';

    the_permalink();

    echo '">';

    the_title();

    echo '</a></td></tr>';

    endwhile;

    ?>
    </table>
    </div>

1 个答案:

答案 0 :(得分:0)

<?php
$cat_id  = get_query_var('cat');
$showposts = 10;
$args = array('cat' => $cat_id, 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => $showposts,'post_status' => 'publish');
query_posts($args);
    if (have_posts()) : while (have_posts()) : the_post(); ?>      
    <tr>
        <td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td>
    </tr>
    <?php endwhile; else: ?>
        <?php _e('No Posts Sorry.'); ?>
    <?php endif; ?>

请您尝试上面的代码吗?