I have this code but I can't get to delete the div with the class otrasObras
<?php
$test = "";
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$test .= ',' . $tag->name;
}
}
$test = substr($test, 1);
query_posts('tag='.$test.'&showposts=-1');
if(have_posts()){
?>
<div class="otrasObras">
<h3>Contenido relacionado:</h3>
<ul>
<?php
while (have_posts()) : the_post();
if($post->ID != $idPost):
?>
<li>
<a href="<?php the_permalink(); ?>" title="Ver la obra <?php the_title(); ?>">
<h4><?php the_title(); ?></h4>
</a>
</li>
<?php
endif;
endwhile;
wp_reset_query();
?>
</ul>
</div>
<?php } ?>
I read a bit about this in here http://codex.wordpress.org/Function_Reference/WP_Query but they were using the object syntax.
EDIT: .otrasObras
is a module that I want to show only when it has content, and the content are other posts with the same tag, so if there are no more posts with that tag, I don't want it to pass the if(have_posts()) conditional, but this seems to not work, as it gets printed all the time
if(have_posts())
conditional, but this seems to not work, as it gets printed all the timepost_tag
as taxonomy for build in tags :-)query_posts
. It breaks the main query object. Related posts relies on this main query object, so you don't just break the main query object, but you also break related posts functions. UseWP_Query
orget_posts
instead