Похожие объявления в Classipress
Создаём красивые блоки похожих объявлений в конце каждого объявления. Подходит для Classipress 3.5.1 и на более ранние версии.
single-ad_listing.php
после
1 |
<?php wp_reset_query(); ?> |
вставляем:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
<div class="clr" id="related-ads"></div> <?php // Related ads $custom_taxterms = wp_get_object_terms( $post->ID, 'ad_cat', array('fields' => 'ids') ); // 'ad_tag' - похожие по тегам, 'ad_cat'- похожие в категории $args = array( 'post_type' => 'ad_listing', 'post_status' => 'publish', 'posts_per_page' => 5, // 5 - количество похожих объявлений в блоке 'orderby' => 'rand', 'order' => 'DESC', 'tax_query' => array( array( 'taxonomy' => 'ad_cat', // 'ad_cat' - похожие по тегам, 'ad_tag'- похожие в категории - 'field' => 'id', 'terms' => $custom_taxterms ) ), 'post__not_in' => array ($post->ID), ); $related_items = new WP_Query( $args ); // loop over query if ($related_items->have_posts()) : ?> <h2 class="description-area"><?php _e( 'Похожие объявления', APP_TD ); ?></h2> <?php while ( $related_items->have_posts() ) : $related_items->the_post(); ?> <div class="post-block-out pbo <?php cp_display_style( 'featured' ); ?>"> <div class="post-block"> <ul> <li> <div class="post-left"> <?php if ( $cp_options->ad_images ) cp_ad_loop_thumbnail(); ?> </div> <div class="<?php cp_display_style( array( 'ad_images', 'ad_class' ) ); ?>"> <?php appthemes_before_post_title(); ?> <h3><a href="<?php the_permalink(); ?>"><?php if ( mb_strlen( get_the_title() ) >= 75 ) echo mb_substr( get_the_title(), 0, 75 ).'...'; else the_title(); ?></a></h3> <div class="clr"></div> <p class="post-meta"> <span class="folder"><?php if ( $post->post_type == 'post' ) the_category( ', ' ); else echo get_the_term_list( $post->ID, APP_TAX_CAT, '', ', ', '' ); ?></span> | <span class="owner"><?php if ( $cp_options->ad_gravatar_thumb ) appthemes_get_profile_pic( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_email' ), 16 ); ?><?php the_author_posts_link(); ?></span> | <span class="clock"><span><?php echo appthemes_date_posted( $post->post_date ); ?></span></span> </p> <div class="clr"></div> <p class="post-desc"><?php echo cp_get_content_preview( 160 ); ?></p> <div class="clr"></div> <?php appthemes_after_post_title(); ?> <div class="clr"></div> <?php appthemes_before_post_content(); ?> <div class="clr"></div> </div> <div class="pad5"></div> <div class="clr"></div> </li> </div><!-- /post-block --> </div><!-- /post-block-out pbo --> <?php endwhile; echo '</ul>'; endif; wp_reset_postdata(); ?> |
