Help needed with if/while statement please?
-
Hi guys,
I use the following code to display related posts based on assigned tags. I’m trying to tweak it slightly but am having some problems due to my inexperience with php.
My first question, does anyone know how to amend the code so that after the ‘if’ statement and before the start of the ‘while’ statement i can insert a h2 heading? Whenever i try and change the code i get a white blank screen indicating an error in the code.
Secondly, in the arguments section, how do i add a category specifier so that wodrpress will only display these posts based on tags from a certain category? Again, when i tried to add the argument it was ignored so i presume another error.
Thanks, and hear is the code…
<?php //for use in the loop, list 3 post titles related to first tag on current post $backup = $post; // backup the current object $tags = wp_get_post_tags($post->ID); $tagIDs = array(); if ($tags) { $tagcount = count($tags); for ($i = 0; $i < $tagcount; $i++) { $tagIDs[$i] = $tags[$i]->term_id; } $args=array( 'tag__in' => $tagIDs, 'post__not_in' => array($post->ID), 'showposts'=> 3, 'orderby'=> 'rand', 'caller_get_posts'=> 1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?>
- The topic ‘Help needed with if/while statement please?’ is closed to new replies.