WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display relevant taxonomy tags beside each post within Loop (5 posts)

  1. aliceralph
    Member
    Posted 2 years ago #

    I have a couple of different taxonomies - 'resources' and 'get-involved' - with a number of terms within each.

    I am displaying a custom loop on my homepage which will show content across all taxonomies which have been added to a 'featured' category.

    I am wondering how I could add in the relevant taxonomies within the loop. For example:

    <title>
    <excerpt>
    <taxonomies that this item has selected... eg: Case Studies, Report>
    <featured image>

    Just to confuse things further, I am displaying them as multiple loops (hopefully the code makes sense!) as per http://perishablepress.com/multiple-loops-and-multiple-columns-with-wordpress/ This is my code:

    <?php query_posts('showposts=2, cat=19'); ?>
    <?php $posts = get_posts('numberposts=2&offset=0'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count1 = 0; if ($count1 == "2") { break; } else { ?>
    <div class="homeresources">
    <h3>
    <a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
    <?php the_title(); ?>
    </a>
    </h3>
    <span class="homeresourcestext">
    <?php my_excerpt(5); ?>
    </span>
    <a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
    <?php the_post_thumbnail(); ?>
    </a>
    </div>
    <?php $count1++; } ?>
    <?php endforeach; ?>
    
    <?php query_posts('showposts=1'); ?>
    <?php $posts = get_posts('numberposts=1&offset=2'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count2 = 0; if ($count2 == "1") { break; } else { ?>
    
    <div class="homeresources3">
    <h3>
    <a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
    <?php the_title(); ?>
    </a>
    </h3>
    <span class="homeresourcestext">
    <?php my_excerpt(5); ?>
    </span>
    <a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
    <?php the_post_thumbnail(); ?>
    </a>
    </div>
    <?php $count2++; } ?>
    <?php endforeach; ?>

    Any advice welcomed! Thanks in advance.

  2. aliceralph
    Member
    Posted 2 years ago #

    Hi guys, still really stuck on this. Any advice very welcome!! Please let me know if more info needed as maybe I've not explained fully?

    No worries if not... thanks anyway :)

  3. aliceralph
    Member
    Posted 2 years ago #

    WOOHOO! Just managed to work it out myself, even if it took bloody hours. Doesn't add commas between taxonomies if it is listed under more than one but otherwise works a charm.

    Posting it now in case this helps anybody else in the future:

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

  4. masok88
    Member
    Posted 2 years ago #

    Hey I'm actually looking to do the same thing. Looking at your code I can't actually see where you're calling your custom taxonomies.

    <?php $loop = new WP_Query( array( 'post_type' => 'entries', 'posts_per_page' => 1000 ) ); ?>
    
    		<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
    			<div class="thumbnail">
    			     <?php if ( has_post_thumbnail()) : ?>
    				  <?php the_post_thumbnail( array(256,159) ); ?>
    				 <?php endif; ?>
    		        <div class="folio-meta">
    		            <h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
    		            <hr/>
    		            <p class="post-tags"> <?php the_tags('', ', ', '<br />'); ?> </p>
    		        </div>
    		    </div><!-- .view.transition-effect-->
    
    		<?php endwhile; ?>

    I've got the first post working somehow but all subsequent posts aren't showing their 'tags'. Any ideas?

  5. aliceralph
    Member
    Posted 2 years ago #

    They've taken out my code but here it is in Pastebin:

    http://pastebin.com/7UbEVrMe

    This is the bit that shows my taxonomy name within the loop:

    <?php
    $terms = get_the_terms($post->ID, 'resources');
    echo '';
    foreach ($terms as $taxindex => $taxitem) {
    echo '<h3>' . $taxitem->name . ':</h3>';
    }
    echo ''
    ?>

    'resources' is the name of my taxonomy. Hope that helps. I don't fully understand it myself but it seems to work!

Topic Closed

This topic has been closed to new replies.

About this Topic