• Can’t get my head around this one and hope I can explain this clearly as it’s giving me a headache!

    I’m developing a site that features holidays by rail.

    When I get down to the single post about the holiday itinerary, in the right hand sidebar I want to be able to show the main hotel for the holiday, then underneath some alternatives (upgrades/downgrades) and then underneath again the hotels used on the outward/return parts of the journey.
    For example, a trip to Venice will have an overnight stay enroute and another on the return trip, a main hotel and say 3 alternatives.

    I’ve been unable to think of a way to use the tags to relate them without getting duplicates.

    Also, some of the hotels, particularly the enroute ones will apply to more than pne holiday.

    Any ideas very gratefully received.
    Nick

Viewing 5 replies - 1 through 5 (of 5 total)
  • Can offer you this as an example you could play with:

    for use in the loop, list all posts with tags contained on current post, excluding the current post

    <?php
    $tags = wp_get_post_tags($post->ID);
    if ($tags) {
      $term_ids=array();
      foreach($tags as $tag) {
        array_push($term_ids,$term->term_id);
      }
      $args=array(
        'tag__in' => $term_ids,
        'post__not_in' => array($post->ID),
        'post_type' => 'post',
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'caller_get_posts'=> 1
      );
      $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        echo 'List of Related Posts';
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
          <?php
        endwhile;
      }
    wp_reset_query();  // Restore global post data stomped by the_post().
    }
    ?>

    Thread Starter justshopandgive

    (@justshopandgive)

    Thanks for that – bit advanced for me really.

    Also, I don’t think that is quite what I’m looking for. If I have a post of a holiday (for example, with ‘Venice at Christmas’ as a tag) then my main hotel and alternative hotels (with ‘Venice at Christmas’ as a tag also) means the main one would show fine as it is the only one (hence ‘main’) but my alternative hotels list would also include the main one again.

    Have I interpreted what your code does correctly?

    Thanks very much for replying though.
    Nick

    Thread Starter justshopandgive

    (@justshopandgive)

    What I have been trying is using a post excerpt widget to display the hotel info and then using a widget context plugin to determine which page to display which hotels. It works but means I could potentially end up with hundreds of widgets in my right sidebar (admin area) to cover all hoiday/hotel combinations.

    Just hoping there was a more elegant solution.

    One thought is having categories like Venice Main Hotel,Venice Alternative Hotels, etc and display posts within a category with a sidebar widget. This again though could mean a lot of widgets to manipulate in the admin area.
    Nick

    You might then want to consider some kind of related posts type plugin that doesn’t require coding.

    Example:
    https://www.ads-software.com/extend/plugins/yet-another-related-posts-plugin/

    Thread Starter justshopandgive

    (@justshopandgive)

    I have been looking at plugins, just can’t seem to get them to do exactly what I want.
    Maybe I’ll have to pay someone for some coding!
    Thanks again,
    Nick

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Kind of related posts but a bit different’ is closed to new replies.