• Resolved Pete

    (@perthmetro)


    I have this code that displays all the custom terms of a specific custom taxonomy(XYZ). Would someone be kind enough to add to this to get it to have an unlinked comma between each term but not after the last term.

    Many thanks, Pete

    <?php $args = array('taxonomy' => 'XYZ'); ?>
    <?php $tax_menu_items = get_categories( $args ); foreach ( $tax_menu_items as $tax_menu_item ):?>
    <a href="<?php echo get_term_link($tax_menu_item,$tax_menu_item->taxonomy); ?>"><?php echo $tax_menu_item->name; ?></a>
    <?php endforeach; ?>
Viewing 15 replies - 1 through 15 (of 20 total)
  • Thread Starter Pete

    (@perthmetro)

    Can this please be moved to How-To and Troubleshooting, thanks

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Done. And please do not use the imaginary modalert tag. That’s not how you contact the moderators.

    Don’t abuse the correct tag BTW as that will land you in trouble. ??

    Thread Starter Pete

    (@perthmetro)

    sorry about that, I got mixed up with ‘modlook’.. is that the right way to contact a mod for something like this?

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    That is the right tag but to be honest leaving this topic in Hacks would have been fine too and modlook wouldn’t really be necessary.

    Both sub-forums get the same visibility and people who take time in How-To and Troubleshooting often see Hacks as well.

    Thread Starter Pete

    (@perthmetro)

    Cheers thanks for that ??

    leaving this topic in Hacks would have been fine

    I was the one who moved to Hacks as that is specifically a coding help sub-forum and tends to be used by the very people who could come up with a solution. In fact I was hoping to come up with something up myself but got side-tracked by a more urgent issue.

    Thread Starter Pete

    (@perthmetro)

    Ahhhh, i was wondering why I couldn’t find it in the forum, i thought i was going a bit crazy for a minute there ??

    Try:

    <?php $args = array('taxonomy' => 'XYZ'); ?>
    <?php $tax_menu_items = get_categories( $args );
    $tax_tot = count( $tax_menu_items ); // count number of items in returned array
    $c = 0; // set up a counter;
    foreach ( $tax_menu_items as $tax_menu_item ):
    $c++; // Increment counter ?>
    <a href="<?php echo get_term_link($tax_menu_item,$tax_menu_item->taxonomy); ?>"><?php echo $tax_menu_item->name; ?></a>
    if ($c < $tax_tot ) echo ',';
    <?php endforeach; ?>

    FYI: to locate your posts, just view your profile (top right of every page) for a list of the topics you started and contributed to.

    Thread Starter Pete

    (@perthmetro)

    Thanks… and yes, that’s how i found out where it was ??

    No luck with that, this line didn’t highlight correctly in notepad++
    if ($c < $tax_tot ) echo ',';

    Ugh! My bad!

    <?php $args = array('taxonomy' => 'XYZ'); ?>
    <?php $tax_menu_items = get_categories( $args );
    $tax_tot = count( $tax_menu_items ); // count number of items in returned array
    $c = 0; // set up a counter;
    foreach ( $tax_menu_items as $tax_menu_item ):
    $c++; // Increment counter ?>
    <a href="<?php echo get_term_link($tax_menu_item,$tax_menu_item->taxonomy); ?>"><?php echo $tax_menu_item->name; ?></a>
    <?php if ($c < $tax_tot ) echo ',';?>
    <?php endforeach; ?>
    Thread Starter Pete

    (@perthmetro)

    ahh added the php tags ??

    Thread Starter Pete

    (@perthmetro)

    Thanks, for that. Much appreciated ??

    Thread Starter Pete

    (@perthmetro)

    Sorry for being pedantic but there is a space before the comma and no space after the comma… I was hoping for it to be the opposite ??

    <?php $args = array('taxonomy' => 'XYZ'); ?>
    <?php $tax_menu_items = get_categories( $args );
    $tax_tot = count( $tax_menu_items ); // count number of items in returned array
    $c = 0; // set up a counter;
    foreach ( $tax_menu_items as $tax_menu_item ):
    $c++; // Increment counter ?>
    <a href="<?php echo get_term_link($tax_menu_item,$tax_menu_item->taxonomy); ?>"><?php echo $tax_menu_item->name; ?></a>
    <?php if ($c < $tax_tot ) echo ', ';?>
    <?php endforeach; ?>
    Thread Starter Pete

    (@perthmetro)

    There is still a space before the comma??

    <li><b>Skills: </b><?php $args = array('taxonomy' => 'skill'); ?>
    <?php $tax_menu_items = get_categories( $args );
    $tax_tot = count( $tax_menu_items ); // count number of items in returned array
    $c = 0; // set up a counter;
    foreach ( $tax_menu_items as $tax_menu_item ):
    $c++; // Increment counter ?>
    <a href="<?php echo get_term_link($tax_menu_item,$tax_menu_item->taxonomy); ?>"><?php echo $tax_menu_item->name; ?></a>
    <?php if ($c < $tax_tot ) echo ', '; ?>
    <?php endforeach; ?></li>

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Separator for custom terms display’ is closed to new replies.