Ask your WordPress questions! Pay money and get answers fast! (more info)

display custom taxonomy tags OUTSIDE the loop WordPress

<blockquote>
EDIT: The answer has been found here...
[[LINK href="http://wordpress.org/support/topic/how-to-display-custom-taxonomy-tags-outside-the-loop?replies=2#post-3041465"]]http://wordpress.org/support/topic/how-to-display-custom-taxonomy-tags-outside-the-loop?replies=2#post-3041465[[/LINK]]

$suburbs = get_terms('suburbs','hide-empty=0&orderby=id');
shuffle($suburbs);
foreach ( $suburbs as $suburb ) {
if( ++$count > 10 ) break;
echo "COUNT:$count ID:$suburb->term_id NAME:$suburb->name SLUG:$suburb->slug <br />";
}

</blockquote>

I hope I can explain this correctly... the WordPress terminology with custom taxonomies is a bit confusing for for me...

I have a normal page with 100 custom tags assigned to it. These custom tags are assigned to the 'electrician'.

I have a template page called taxonomy-electrician.php

This template page simply shows the below, depending on the custom tag...

<?php single_tag_title(); ?> is an electrician

In effect it makes me 100 different pages (1 for each custom tag)

I have another group of 50 custom tags from a different custom taxonomy (suburbs).
NB: This group of 50 tags are not related in any way way to the 100 'electrician' custom tags

On my taxonomy-electrician page I also want to show a list of 10 random custom tags from the other custom taxonomy (suburbs).

In effect I want the taxonomy-electrician.php page to look like this...

Bill is an electrician

[10 random tags from 'suburbs']


************************************
******* edit *************************
************************************

OK Basically I want to show this OUTSIDE the loop, that is, show this anywhere in any template file...
<?php
wp_tag_cloud( array( 'taxonomy' => 'suburb', 'format' => 'flat', 'order' => 'rand', 'separator' => ', ','number' => 45, ) );
?>

Answers (2)

2012-08-04

Arnav Joy answers:

see this url
http://wordpress.org/support/topic/get-tags-specific-to-category


pjeaje comments:

Thanks but i don't think it's what I'm asking for... maybe it's me not explaining it correctly? Categories really have nothing to to do with it... the focus is displaying the tags/terms from a custom taxonomy group anywhere in any theme file.


Arnav Joy comments:

try the code there by replacing "category" to your taxonomy name "suburbs"


pjeaje comments:

I need something like this... but I want to be able to have control over the number of tags displayed, the order (random) and how the tags are separated e.g. list, by comma etc.
<?php
$taxonomy = 'electrician';
$queried_term = get_term_by( 'slug', get_query_var($taxonomy) );
$terms = get_terms($taxonomy);
if ($terms) {
foreach($terms as $term) {
echo '<li><a href="' . $term->slug . '">' . $term->name .'</a></li>';
}
}
?>


pjeaje comments:

There's a variety of codes there... which one in particular are you inferring?


Arnav Joy comments:

code by "john.andrews"


pjeaje comments:

Do I replace EVERY instance of category' with 'taxonomy' ?


pjeaje comments:

It would be nice if you could paste the code here with all the changes that need to be made. Thanks.


Arnav Joy comments:

try this



<?php

wp_tag_cloud( array( 'taxonomy' => 'suburb', 'format' => 'list', 'order' => 'RAND', 'number' => 10, echo => 1 ) );

?>




pjeaje comments:

That kills my theme :)


Arnav Joy comments:

forgot to place a quote sign , here it is

<?php



wp_tag_cloud( array( 'taxonomy' => 'suburb', 'format' => 'list', 'order' => 'RAND', 'number' => 10, 'echo' => 1 ) );



?>


pjeaje comments:

OK this is the same problem I've been getting for ages... for some reason it's just picking out 10 tags and randomising those same 10 tags each time the page refreshes... i need a completely new random set of 10 tags each time... this isn't happening ?????


pjeaje comments:

Any other ideas?

2012-08-04

Jatin Soni answers:

Here is the code I am using for my own template and works fine

<?php // Let's get the data we need
$term_category = get_the_term_list( $post->ID, 'your_cpt_category', '', ', ', '' );
$term_tags = get_the_term_list( $post->ID, 'your_cpt_tags', '', ', ', '' );
?>


and than echo the variable

<?php echo $term_category; ?>
<?php echo $term_tags; ?>


This will surely render the taxonomy


pjeaje comments:

Where do i insert these?


pjeaje comments:

OK get it working but it's only half of what i need... I need apply arguments to it, namely randomise it, numberise it and separatise it...


Jatin Soni comments:

Okay let me try with that too. I will post another code in few minutes.


Jatin Soni comments:

Ah! sorry I missunderstood.....I still confuse what arguments you want on it


pjeaje comments:

Pretty much all the normal tag cloud arguments


pjeaje comments:

Any luck?


Jatin Soni comments:

Not yet, this require to create function or a small kind of plugin need more effort to put to make it works.