• Hi I want to achieve something very spoecific. I should say that I have tried the plugins listed on this site, but haven’t found anyone/or I have not been god enough to modify it so that it would do this.

    Under each post in my single.php I would like to show 2 random posts from the tags associated with the post, together with an image from a custom field plus the Excerpt.

    So under each post, I would like to get two random posts from the tags returned by:

    <?php
    $posttags = get_the_tags();
    if ($posttags) {
    foreach($posttags as $tag) {
    echo $tag->name . ' ';
    }
    }
    ?>

    And show them like this:

    <div class="related_posts">
      <h2>Related posts</h2>
      <div class="first_related"> <a href="<?php the_permalink(); ?>"><img src="customfield_image" /></a>
        <p><a href="<?php the_permalink(); ?>">
          <?php the_title(); ?>
          </a></p>
        <p>
          <?php the_excerpt(); ?>
        </p>
      </div>
      <div class="second_related"> <a href="<?php the_permalink(); ?>"><img src="customfield_image" /></a>
        <p><a href="<?php the_permalink(); ?>">
          <?php the_title(); ?>
          </a></p>
        <p>
          <?php the_excerpt(); ?>
        </p>
      </div>
    </div>

    I have also tried to have a look at the “Custom Post Listing” plugin but I couldn’t see if it would be able to do this.

    Hopefully someone can give me some leads to follow.

Viewing 3 replies - 16 through 18 (of 18 total)
  • Well, complete begginer here, but, how to exclude a determinated tag, or, to be more specific, a tag containing a determinated WORD, to be displayed in that code ?

    I’m learning a lot of PHP but to do that… I’m lost. Meanwhile if someone can figure out the right syntax it could be cool.

    By the rest, I got it working and it’s really cool.

    I’ve tried the following, which doesn’t throw error messages ?? But it seems to filter all the tags.

    $posttags = get_the_tags();
              if(strpos($posttags->nice_name,"THE WORD TO EXCLUDE HERE")!==false){
    if ($posttags) {
    	foreach($posttags as $tag) {
    		$sep = ( $tags ) ? ',' : '';
    		$tags .= $sep . '\'' . $tag->name . '\'';
    	}
    }
    }

    What I’ve added is this part if(strpos($posttags->nice_name,"THE WORD TO EXCLUDE HERE")!==false){

    , and the final closing }

    Please help

    @kasperbs – not sure if you got this all worked out now, but the next version of Yet Another Related Posts Plugin will have a templating feature which will let you do exactly this very nicely. In fact, I just released a beta of this next version: 3.0 beta 1. I also wrote up a tutorial on the templating feature.

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘Show related posts with excerpt and key/value’ is closed to new replies.