• Resolved Kiran

    (@kiranbhai)


    I want to show tag based post in related post. Here is the complete template code for my related post loop (loop.related.post.php ) What changes do I need to make in this loop? My theme is custom.

    <?php
    global $wpdb, $post, $wp_query;
    $URLs_Link_MP3 = get_post_meta( $post->ID, 'URLs_Link_MP3', true );
    $durations_MP3 = get_post_meta( $post->ID, 'durations_MP3', true );
    if(!$durations_MP3) $durations_MP3 = '0';
    global $wpdb, $post, $wp_query;
    $durations_MP3 = get_post_meta( $post->ID, 'durations_MP3', true ); if(!$durations_MP3) $durations_MP3 = '0';?>
    <div class="col-sm-6 item" data-id="<?php the_ID(); ?>" data-value="<?php echo $URLs_Link_MP3 ; ?>" >
        <div class="row">
            <div class="button dark player loader" duration="<?php echo $durations_MP3 ; ?>">
                <svg class="icon icon-play">
                    <use xlink:href="#icon-play"/>
                </svg>
            </div>
            <a class="details" href="<?php the_permalink() ?>" title="<?php the_title(); ?> PDF Download">
                <h2 class="title"><?php the_title(); ?></h2>
                <p><?php echo $durations_MP3 ; ?> <?php global $opt_themes; if($opt_themes['rtones_Sec']) { ?><?php echo $opt_themes['rtones_Sec']; ?><?php } ?> - <?= ex_themes_get_post_view_(); ?> <?php global $opt_themes; if($opt_themes['rtones_Author_Download']) { ?><?php echo $opt_themes['rtones_Author_Download']; ?><?php } ?></p>
            </a>
        </div>
        <?php global $opt_themes; if($opt_themes['ex_themes_tags_all_active_']) { ?>
            <div class="row">
                <?php
                $post_tags = get_the_tags();
                if ( ! empty( $post_tags ) ) {
                    echo '<ul class="tags">';
                    foreach( $post_tags as $post_tag ) {
                        echo '<li><a href="' . get_tag_link( $post_tag ) . '">' . str_replace('ringtones', ' ', $post_tag->name) . '</a></li>';
                    }
                    echo '</ul>';
                }   else {
                    echo '<ul class="tags">';
                    echo '<li><a>no tags</a></li>';
                    echo '</ul>';
                }
                ?>
            </div>
        <?php } ?>
        <div class="row">
            <div class="actions">
                <div class="button light fav">
                    <?php if ( shortcode_exists( 'favorite_button' ) ): ?><?php echo do_shortcode( '[favorite_button]' ); ?><?php else: ?><?php endif;?>
                </div>
                <div class="button light share">
                    <svg class="icon">
                        <use xlink:href="#icon-share"/>
                    </svg>
                </div>
                <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
                    <div class="button dark download">
                        <svg class="icon">
                            <use xlink:href="#icon-download2"/>
                        </svg>
                    </div>
                </a>
            </div>
        </div>
    </div>
    

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator t-p

    (@t-p)

    Thread Starter Kiran

    (@kiranbhai)

    Yes, saw it, but it’s not working. Somebody help me please.

    Thread Starter Kiran

    (@kiranbhai)

    I have prepared this related post loop. But is not working. Can you give any suggestion on this?

    function rtones_related_post() {   ?>
        <?php
        global $wpdb, $post, $opt_themes;
        $tags = get_post_tags($post->ID);
        $numbers = 	$opt_themes['ex_themes_related_posts_numbers_'];
        if ($tags) {
            $tag_ids = array();
            foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
            $args=array(
                //'tag' => $tags->slug,
                'post_type' => 'post',
                'post_status' => 'publish',
                'orderby'   => 'rand',
                'post__not_in' => array($post->ID),
                'posts_per_page'=> $numbers,
                'caller_get_posts'=> 1
            );
            $my_query = new WP_Query( $args );
            if( $my_query->have_posts() ) {
                while ($my_query->have_posts()) : $my_query->the_post(); ?>
                    <?php get_template_part('template/loop.home'); ?>
                <?php endwhile; }
            echo '';
            wp_reset_query();
        }?>
    <?php }
    
    Thread Starter Kiran

    (@kiranbhai)

    Working ….. I put this code and it is working successfully.

    // Get the current post's tags
        $tags = wp_get_post_tags( $post->ID );
        $tagIDs = array();
        if ( $tags ) {
            // Fill an array with the current post's tag ids
            $tagcount = count( $tags );
            for ( $i = 0; $i < $tagcount; $i++ ) {
                $tagIDs[$i] = $tags[$i]->term_id;
            }
            // Query options, the magic is with 'tag__in'
            $args = array(
                'tag__in' => $tagIDs,
                'post__not_in' => array( $post->ID ),
                'showposts'=> 5
            );
            $my_query = new WP_Query( $args );
    
    Moderator t-p

    (@t-p)

    Glad its sorted ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Show Related posts loop based on tags’ is closed to new replies.