addclass to related posts
-
Hi,
i built an archive in my footer. The archive displays the title from all my posts (i use 7 post types). I have 2 types of page templates, 1 where you see an overview of the chosen post-type. Then there’s the single — which displays a single post. The archive is present at all page-templates.
Id need help with a function which understands which categories that the posts displayed in the overview uses then compare it with the posts in the archive, if one or more cat’s are the same id like to add a class to those posts in the archive..
E.g in the overview there are 2 posts which have the same cat’s as 10 of the posts in the archive then the 10 posts would get an calss. Same would be for the single page.This is the code im using.
generating the archive<?php $recentPosts = new WP_Query(array('orderby' => 'menu_order', 'post_type' => array('highlights', 'artiklar','intervju', 'portfolio', 'pressrum', 'myo_polling'))); while( $recentPosts->have_posts() ) : $recentPosts->the_post(); ?> <a href="<?php echo get_permalink( get_page_by_path( 'fragebanken' ) ) ?>#<?php the_ID();?> "> <?php the_title();?> </a> <? endwhile ;?>
This is some code i’ve been trying with but it needs to be written together with above
$categories = get_the_category($post->ID); if ($categories) { $category_ids = array(); foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id; $args=array( 'category__in' => $category_ids, 'post__not_in' => array($post->ID), 'showposts'=>-1, // Number of related posts that will be shown. 'caller_get_posts'=>1 );
This is the query im grabing post with to the overview.
<?php $myQuery = new WP_Query(array('showposts' => -1, 'post_type' => ('artiklar'))); while( $myQuery->have_posts() ) : $myQuery->the_post(); ?>
- The topic ‘addclass to related posts’ is closed to new replies.