WordPress的阵列,以显示某些类别和展后摘录后和功能荷兰国际集团(Wordpress arra

2019-07-31 05:20发布

大家好寻找一个WordPress的帮助。 我需要把一个简单的查询/阵列显示从一定猫例如,“新闻,其中将包括特色图片帖子帖子。

任何人都可以请帮助?

加里

Answer 1:

试试这个

<?php
    $query = new WP_Query('category_name=News&posts_per_page=4');
    if($query->have_posts()) : while($query->have_posts()) : $query->the_post();
    if (has_post_thumbnail()) {
        ?>
            <a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a>
        <?php
    }
    ?>
    <h2><a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <?php
    the_excerpt(); // or the_content(); for full post content
    endwhile;endif;
?>


Answer 2:

不要使用query_posts()。 它的目的是修改默认的WordPress的循环,不应该被用于一般的查询。 使用WP查询或获取的帖子来代替。

这里有一些文档后缩略图

下面是基于什么你告诉我可能工作的一个小例子。 请注意,“showposts”已改为“posts_per_page”,因为被弃用的2.1版本“showposts”:

<?php
$q = new WP_Query(array('cat'=>8, 'posts_per_page'=>4));
if($q->have_posts()) : while($q->have_posts()) : $q->the_post();
    the_excerpt();
    if(has_post_thumbnail())
        the_post_thumbnail('thumbnail');
endwhile;endif;
?>

更新:

基于你给我的例子,这应该让你开始:

<div id="slider2">
<div class="viewport">
    <?php
    $q = new WP_Query(array('cat'=>8, 'posts_per_page'=>4));
    if($q->have_posts()) : while($q->have_posts()) : $q->the_post();
    ?>
    <div class="newsPost">
        <div class="news-date"><?php the_date(); ?></div>
        <div class="newstitle"><?php the_title(); ?></div>
        <div class="news-des"><?php the_excerpt(); ?></div>
        <?php if(has_post_thumbnail()){ ?>
        <div class="newsimg"><?php the_post_thumbnail(); ?></div>
        <?php } ?>
        <p><a href="<?php the_permalink(); ?>">Read More...</a></p>
    </div>
    <?php endwhile;endif; ?>   
</div>
</div>​


文章来源: Wordpress array to show post from certain category and show post excerpt and feature ing