需要帮助制作一个显示类别的wordpress循环,如果它是真的,

时间:2013-04-24 10:13:54

标签: php wordpress

目前我只是在理论上思考我需要做什么,我正在编辑另一个开发人员代码,所以它可能有点棘手。

我创建了一个名为“home”的新catergory,并希望我分配给此catergory的帖子覆盖主页上显示的当前帖子。因此,如果它被选中,它将出现在主页上。

我有3个自定义帖子类型,每个都有一个名为home的catergory。

这是我目前获得的显示最新帖子的代码。它没有变化,我只需要就此提供指导。

<?php
$query               = new WP_Query('post_type=testimonial&showposts=1&paged=' . $paged);
$postcount           = 0; ?>

 <?php if ($query->have_posts()) : ?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<?php $postcount++; ?>

<li> 
<a href="<?php the_permalink(); ?>"></a>
<a href="<?php the_permalink(); ?>">

<?php
if (has_post_thumbnail()) { 
// check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail('thumb-casestudy');
                                    }else { 
                                    ?>

<img src ="<?php bloginfo('template_url'); ?>/assets/images/default.jpg" alt="<?php the_title(); ?>"/>
<?php } ?></a>
<h4><a href  ="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<p class     ="hm_text"><?php 
//the_excerpt(); 
echo get_post_meta($query->post->ID, 'wpld_cf_home_page_text', true) ?></p>




</li>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>

1 个答案:

答案 0 :(得分:0)

  

创建帖子类别名称=主页

 <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
        'category_name'=>'home',
        'post_type' => 'post',
        'showposts' => '10',
        '&paged' => $paged,
    );
    $wp_query->query( $args );
    $postcount           = 0; 
?>

<?php if ($wp_query->have_posts()) : ?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php $postcount++; ?>
<li> 
    <a href="<?php the_permalink(); ?>">
    <?php
        if (has_post_thumbnail()) { 
                the_post_thumbnail('thumb-casestudy');
        }else { 
    ?>
        <img src ="<?php bloginfo('template_url'); ?>/assets/images/default.jpg" alt="<?php the_title(); ?>"/>
    <?php } ?>
        </a>
    <h4><a href ="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
</li>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>