Show related ads including images by category
Hi there
I was looking for a easy way to show related ads including images on my new Classipress site (
www.udlejerbasen.dk DANISH).
Maybe it is not the best way to do it, but here is how i did it:
In "single-ad_listing-php" add this code where you want the related ads to show up.
PHP Code:
<ul>
<?php
$term = wp_get_object_terms($post->ID, APP_TAX_CAT);
$parent = $term[0]->parent;
$parents[] = $term[0]->term_id;
$sql = "SELECT term_id, slug FROM `wp_ub_terms` WHERE term_id = $parent";
$resultat = mysql_query($sql);
while($post=mysql_fetch_array($resultat)) {
$newslug = $post['slug'];
}
$thePostID = $wp_query->post->ID;
$args = array( 'numberposts' => 3, 'orderby' => 'rand', 'post_type' => APP_POST_TYPE, APP_TAX_CAT => $newslug, 'exclude' => $thePostID);
$rand_posts = get_posts( $args );
foreach( $rand_posts as $post ) : ?>
<li><?php cp_ad_featured_thumbnail(); ?><a id="related-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
You can se an example here:
http://www.udlejerbasen.dk/annonce/21m-trailerlift/