相关文章WordPress

时间:2015-07-24 09:08:12

标签: wordpress posts

我正在寻找一个解决方案,以显示来自不同CPT的相关帖子。 有两个CPT(项目和产品)都有多个子类别(不知道是否可以......)。

当出现在:单一帖子>项目CPT>跑车 在页脚中,它必须显示最新的两个帖子:产品CPT>跑车

我现在的代码只是在CPT上过滤,而不是SubCategrories。这是single_products.php的代码:

    
    <section class="content">
        <div class="container">
            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                <h1><?php the_title(); ?></h1>
                <?php the_content(); ?>
            <?php endwhile; endif; ?>
        </div>
    </section>

    <div class="container">
        <div class="divider-small"></div>
    </div>

    <section class="news">

        <div class="container">
            <h2>Related projects</h2>
            <div class="row">

                <?php 
                $wp_query = new WP_Query(array('post_type' => 'projects', 'post__not_in' => array( $post->ID ), 'showposts' => 2)); 
                $i = 0;
                if ( $wp_query->have_posts() ): while( $wp_query->have_posts() ) : $wp_query->the_post(); ?>


                <div class="col-md-6 item">

                    <div class="<?php if($i++ == 1): echo 'green'; else: echo 'blue'; endif; ?> clearfix">

                        <div class="col-sm-6">

                            <div class="text">                              
                                <h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
                                <p><?php echo excerpt(20); ?></p>
                            </div>  <!-- end text -->

                            <div class="meer-news">
                                <a href="<?php the_permalink(); ?>" class="readmore" title="<?php the_title(); ?>">Lees meer ></a>
                            </div> <!-- end meer-news -->

                        </div>   <!-- end col-sm-6 -->

                        <div class="col-sm-6">
                            <div class="image">
                                <?php
                                if ( has_post_thumbnail() ) :
                                        the_post_thumbnail( 'news_latest' );
                                    else: 
                                        // backup
                                    endif;
                                ?>
                            </div> <!-- end image -->
                        </div> <!-- end col-sm-6 -->

                    </div>

                </div> <!-- end item -->
                <?php endwhile; endif; wp_reset_query(); ?>

            </div> <!-- end row -->
        </div> <!-- end container -->

    </section>

0 个答案:

没有答案
相关问题