首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WordPress限制类别中的帖子页面

WordPress限制类别中的帖子页面
EN

Stack Overflow用户
提问于 2013-10-27 17:02:32
回答 1查看 158关注 0票数 0

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

代码语言:javascript
复制
<?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'),我只有几个条件。

问题是:我需要限制帖子的数量在确切的类别,而不是在所有他们。

我该怎么做呢?

EN

回答 1

Stack Overflow用户

发布于 2013-10-27 19:30:28

我不确定我们是否可以用wordpress的方式来做这件事..但这是一个变通的方法--

代码语言:javascript
复制
$no_of_posts = 5;

$post_counter = 0;

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

未经测试,但可以让您继续前进

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19616297

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档