WordPress限制类别页面中的帖子

时间:2013-10-27 09:02:32

标签: php wordpress loops

这是我的WordPress循环代码......:)

<?php if(have_posts()) : ?>
        <?php while(have_posts()) : the_post(); ?>
        <?php if (is_category('instagram')) {?>

        <?php
            $__width = '225';
            $__height = '225';
        ?>
            <div id="instagram-photos">
                <a href="<?php the_permalink() ?>"class="instagram-photo">
                <div class="photo"><?php custom_get_post_attachments(get_the_ID(), $__width, $__height, get_the_title()); ?>    </div>
                </a>
            </div>

            <?php }elseif(is_category('runway')) { ?>
            <?php
            $__width = '298';
            $__height = '500';
            ?>
            <div id="runway-category">
                <a href="<?php the_permalink() ?>" class="runway-category-posts">
                <div class="photo"><?php custom_get_post_attachments(get_the_ID(), $__width, $__height, get_the_title()); ?><div class="runway-title"><?php the_title(); ?></div></div>
                </a>            
            </div>
            <?php } elseif(is_category('')){?>
        <article <?php post_class(); ?>>
                    <div class="latest-posts">
                    <div class="latest-posts-info">
                    <div class="title"><h1><?php the_title(); ?><h1></div>
                    <div class="text">
                    <?php the_excerpt(); ?>
                    </div>
                    <div class="post-share">
                        <div class="facebook-like" style="float:left;">
                            <a href="http://www.facebook.com/sharer.php?u=<?php the_permalink() ?>" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/facebook-icon.png" /></a>
                        </div>
                        <div class="twitter-follow" style="float:left;">
                            <a href="http://twitter.com/share?text=<?php the_title(); ?>&url=<?php the_permalink() ?>" target="_blank" ><img src="<?php echo get_template_directory_uri(); ?>/images/twitter-icon.png" /></a>
                        </div>
                        <div class="google-share">
                            <a href="https://plus.google.com/share?url=<?php the_permalink() ?>" target="_blank" ><img src="<?php echo get_template_directory_uri(); ?>/images/google-icon.png" /></a>
                        </div>
                    </div>
                    <div class="clear"></div><div class="post-read-more"><a href="<?php the_permalink() ?>" class="read-more">Read More</a></div>
                    <div class="clear"></div>
                </div>
                <div class="latest-posts-img">
                    <?php //echo get_the_post_thumbnail(); ?>
                    <?php custom_get_post_attachments(get_the_ID(), $__width, $__height, get_the_title()); ?>                   
                </div>
                <div class="clear"></div>
                </div>
        </article>
        <?php }?>
        <?php endwhile; else: ?>
        <div class="content">
        <p class="not-found-p">No articles found!</p>
        </div>
        <?php endif; ?>

如您所见,我的条件很少is_category('instagram')

事情是:我需要将帖子数量限制在确切的类别中,而不是限制它们 我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

我不确定我们是否可以用wordpress方式执行此操作..但这是解决方法 -

$no_of_posts = 5;

$post_counter = 0;

if(is_Category('instagram') && ($no_of_posts<=$post_counter)) {
// bunch of code 
$post_counter++;
}

未经测试,但有些事可以让你去