0

我想按一个类别显示我在投资组合过滤器中的最后一个项目,我已经添加了显示我所有最新投资组合项目的代码,我只需要在我的投资组合类别中按类别 ID 过滤它。

<?php if (_sg('Home')->showLatestP()) { ?>
<?php
    $args = array();
    $args['post_type'] = 'portfolio';
    $args['posts_per_page'] = 20;
    $args['meta_key'] = '_thumbnail_id';
    query_posts($args);
?>

<div class="divider"></div>
<?php if (have_posts()) { ?>
<div class="<?php _sg('Home')->eLatestPType(); ?>">
    <?php $i = 0; ?>
    <ul class="slides">
        <?php while (have_posts()) : the_post(); $i++; ?>
            <?php if ($i == 1 OR $i % 5 == 0) echo '<li><ul>'; ?>
            <li class="col1-4<?php if ($i % 4 == 0) echo ' omega'; ?>">
                <div class="proj-img<?php if (_sg('PortfolioPost', TRUE)->getType(get_the_ID()) == 'video') echo ' proj-video'; ?>">
                    <?php the_post_thumbnail('sg_portfolio4', array('alt' => get_the_title())); ?>
                    <?php if (_sg('Home')->getLatestPImgType() == 'large') { ?>
                        <?php $big = (_sg('PortfolioPost', TRUE)->getType(get_the_ID()) == 'video') ? _sg('PortfolioPost', TRUE)->getVideoUrl(get_the_ID()) : wp_get_attachment_url(get_post_thumbnail_id()); ?>
                        <a href="<?php echo $big; ?>" class="prettyPhoto zoom" title="<?php the_title(); ?>"></a>
                    <?php } else { ?>
                        <a href="<?php the_permalink(); ?>"></a>
                    <?php } ?>
                </div>
                <div class="proj-info"><h4><a class="enter-icn" href="<?php the_permalink(); ?>"><?php echo sg_text_trim(get_the_title(), 30); ?></a></h4>
                    <?php if (_sg('Home')->getLatestPText() == 'categories') { ?>
                        <p><?php echo sg_the_tag_list('portfolio_category', ', ', FALSE); ?></p>
                    <?php } else { ?>
                        <p><?php echo sg_text_trim(get_the_excerpt(), 30); ?></p>
                    <?php } ?>
                </div>
            </li>
            <?php if ($i % 4 == 0) echo '</ul></li>'; ?>
        <?php endwhile; ?>
        <?php if ($i % 4 != 0) echo '</ul></li>'; ?>
    </ul>
</div>
<?php } else {
    $empty_extras = __('Portfolio is empty', SG_TDN);
    echo sg_message($empty_extras);
} ?>
<?php } ?>

谢谢你的帮助。

4

1 回答 1

0

用户类似

$args = array(
    'post_type' => 'portfolio',
    'cat' => 'category_id',
    'posts_per_page' => 20,
    'order' => 'DESC'
    );

或者试试

$args = array(
    'post_type' => 'portfolio',
    'category_name' => 'slug_category',
    'posts_per_page' => 20,
    'order' => 'DESC'
    );

顺序键,确定显示您的帖子的顺序。你可以在这里找到额外的参考

于 2013-09-29T13:11:51.277 回答