0

这是我的 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')

问题是:我需要将帖子数量限制在确切的类别中,而不是完全限制。
我怎样才能做到这一点?

4

1 回答 1

0

我不确定我们是否可以用 wordpress 方式做到这一点.. 但这是解决方法 -

$no_of_posts = 5;

$post_counter = 0;

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

未经测试,但类似的东西可以让你继续前进

于 2013-10-27T11:30:27.563 回答