Forum Replies Created

Viewing 15 replies - 1 through 15 (of 23 total)
  • Thread Starter Seijun

    (@seijun)

    No problem. You can also find it by searching the forum for taxonomy shortcode. Here is the topic:
    http://wordpress.org/support/topic/display-custom-taxonomy-output-within-posts-1

    And here is the code, goes in functions.php:

    function get_tax() {
    	global $post;
    	$tax_and_terms = '';
            $tax_and_terms .= strip_tags( get_the_term_list( $post->ID, 'gender', '<dl><dt>Gender: </dt><dd>', ', ', '</dd>' ), '<dl><dt><dd>' );
            $tax_and_terms .= strip_tags( get_the_term_list( $post->ID, 'age', '<dt>Age: </dt><dd>', ', ', '</dd>' ), '<dl><dt><dd>' );
    	$tax_and_terms .= get_the_term_list( $post->ID, 'location', '<dt>Loc: </dt><dd>', ', ', '</dd>' );
            $tax_and_terms .= strip_tags( get_the_term_list( $post->ID, 'status', '<dt>Status: </dt><dd>', ', ', '</dd>' ), '<dl><dt><dd>' );
    	$tax_and_terms .= get_the_term_list( $post->ID, 'contact', '<dt>Contact: </dt><dd>', ' or ', '</dd></dl>' );
    	return $tax_and_terms;
    }
    add_shortcode('tax', 'get_tax');

    The shortcode “tax” will output the terms for my custom taxonomies (gender, age, status, location, and contact) in definition list form. Strip tags is used to keep some terms from linking to their taxonomy archive pages. Working example is here:
    http://wolfdogrescue.net/adoption/all-available/male/amarook-nv/

    Thread Starter Seijun

    (@seijun)

    I almost didn’t. A very nice member here helped me write a shortcode to insert my custom taxonomy info directly into the post. Now it shows up in feeds also.

    I have this same problem! Say I have the image “taz1.jpg”. Searching for “taz” or even “taz1” returns “No media attachments found.”

    Thread Starter Seijun

    (@seijun)

    You are awesome!
    Thank you so much, you have made my life infinitely easier today.
    For anyone interested, my final code is

    function get_tax() {
    	global $post;
    	$tax_and_terms = '';
            $tax_and_terms .= strip_tags( get_the_term_list( $post->ID, 'gender', '<dl><dt>Gender: </dt><dd>', ', ', '</dd>' ), '<dl><dt><dd>' );
            $tax_and_terms .= strip_tags( get_the_term_list( $post->ID, 'age', '<dt>Age: </dt><dd>', ', ', '</dd>' ), '<dl><dt><dd>' );
    	$tax_and_terms .= get_the_term_list( $post->ID, 'location', '<dt>Loc: </dt><dd>', ', ', '</dd>' );
            $tax_and_terms .= strip_tags( get_the_term_list( $post->ID, 'status', '<dt>Status: </dt><dd>', ', ', '</dd>' ), '<dl><dt><dd>' );
    	$tax_and_terms .= get_the_term_list( $post->ID, 'contact', '<dt>Contact: </dt><dd>', ' or ', '</dd></dl>' );
    	return $tax_and_terms;
    }
    add_shortcode('tax', 'get_tax');

    Thread Starter Seijun

    (@seijun)

    Thanks. And for allowing certain tags? This seemed logical, but didn’t work.
    $tax_and_terms .= strip_tags( get_the_term_list( $post->ID, 'gender' <dl><dt>Gender: ', ', ', '</dt>' )$tax_and_terms, '<dl><dt>,<dd>,&nbsp' );

    Thread Starter Seijun

    (@seijun)

    Thanks, that helped a lot!
    I need the strip_tags though to remove the url that is attached to every term. I only want the terms for “loc.” and “contact” to be links. Strip_tags was removing my dl/dt tags as well so I had those added back in. How do I add strip_tags back to the new code?

    Thread Starter Seijun

    (@seijun)

    I replaced echo with return and replaced the_terms with get_the_terms. After replacing echo with return the output is now within the post, but only shows the first taxonomy in the list (gender:female)

    function get_tax() {
    
    $terms_as_text = get_the_term_list( $post->ID, 'gender', '<dl class="my-stats2"><dt>Gender:&nbsp</dt><dd>', ', ', '</dd>' ) ;
    return strip_tags($terms_as_text, '<dl><dt>,<dd>,&nbsp');
    
    $terms_as_text = get_the_term_list( $post->ID, 'age', '<dt>Age:&nbsp</dt><dd>', ', ', '</dd>' ) ;
    return strip_tags($terms_as_text, '<dt>,<dd>,&nbsp');
    
    get_the_terms( $post->ID, 'location', '<dt>Loc:&nbsp</dt><dd>', ', ', '</dd>' );
    
    $terms_as_text = get_the_term_list( $post->ID, 'status', '<dt>Status:&nbsp</dt><dd>', ', ', '</dd>' ) ;
    return strip_tags($terms_as_text, '<dt>,<dd>,&nbsp');
    
    get_the_terms( $post->ID, 'contact', '<dt>Contact:&nbsp</dt><dd>', ' or ', '</dd></dl>' );
    
    }
    add_shortcode('tax', 'get_tax');

    It’s not moving on the the second item in the list. I’m guessing there is something else I need to separate each “get_the_terms” statement, but I have no idea what.

    Thread Starter Seijun

    (@seijun)

    Ok, I’ve been working on this some more, and I’ve got the shortcode to render the php, but it’s still putting the output ABOVE the post and not in it. Please, PLEASE help me out if you can. My code is as follows:

    function get_tax() {
    
    $terms_as_text = get_the_term_list( $post->ID, 'gender', '<dl class="my-stats"><dt>Gender:&nbsp</dt><dd>', ', ', '</dd>' ) ;
    echo strip_tags($terms_as_text, '<dt>,<dd>,&nbsp');
    
    $terms_as_text = get_the_term_list( $post->ID, 'age', '<dt>Age:&nbsp</dt><dd>', ', ', '</dd>' ) ;
    echo strip_tags($terms_as_text, '<dt>,<dd>,&nbsp');
    
    the_terms( $post->ID, 'location', '<dt>Loc:&nbsp</dt><dd>', ', ', '</dd>' );
    
    $terms_as_text = get_the_term_list( $post->ID, 'status', '<dt>Status:&nbsp</dt><dd>', ', ', '</dd>' ) ;
    echo strip_tags($terms_as_text, '<dt>,<dd>,&nbsp');
    
    the_terms( $post->ID, 'contact', '<dt>Contact:&nbsp</dt><dd>', ' or ', '</dd></dl>' );
    
    }
    add_shortcode('tax', 'get_tax');
    Thread Starter Seijun

    (@seijun)

    Ok, I have the shortcode part figured out, but I don’t know how to make the shortcode use a block of php without getting errors. Here is my shortcode code:

    function get_tax() {
    	return 'php code here';
    }
    add_shortcode('tax', 'get_tax');

    And this is the php code I want the shortcode to execute (displays a list of taxonomy terms associated with the post):

    <dl class="my-stats">
    
    $terms_as_text = get_the_term_list( $post->ID, 'gender', '<dt>Gender:&nbsp</dt><dd>', ', ', '</dd>' ) ;
    echo strip_tags($terms_as_text, '<dt>,<dd>,&nbsp');
    
    $terms_as_text = get_the_term_list( $post->ID, 'age', '<dt>Age:&nbsp</dt><dd>', ', ', '</dd>' ) ;
    echo strip_tags($terms_as_text, '<dt>,<dd>,&nbsp');
    
    the_terms( $post->ID, 'location', '<dt>Loc:&nbsp</dt><dd>', ', ', '</dd>' );
    
    $terms_as_text = get_the_term_list( $post->ID, 'status', '<dt>Status:&nbsp</dt><dd>', ', ', '</dd>' ) ;
    echo strip_tags($terms_as_text, '<dt>,<dd>,&nbsp');
    
    the_terms( $post->ID, 'contact', '<dt>Contact:&nbsp</dt><dd>', ' or ', '</dd>' );
    
    </dl>

    Can anyone help, please?

    Thread Starter Seijun

    (@seijun)

    *bump*

    Thread Starter Seijun

    (@seijun)

    So basically one just deletes the sidebar and the other also deletes the sidebar but also gives the option to replace it with something else..

    Thread Starter Seijun

    (@seijun)

    <?php
    $term = get_term_by( 'slug', get_query_var('tag'), 'post_tag' );
    if ( $term )
      echo term_description( $term->term_id, 'post_tag' );
    ?>

    Did not work. Neither did these variations:

    <?php echo term_description( '', get_query_var( 'taxonomy' ) ); ?>

    <?php
    $termDescription = term_description( '', get_query_var( 'taxonomy' ) );
    if($termDescription != '') : ?>
    <div class="tag-desc"><?php echo $termDescription; ?></div>
    <?php endif; ?>
    <?php
    $termdescription = term_description();
    if ( ! empty( $termdescription ) )
    echo '' . $termdescription . '';
    ?>
    Thread Starter Seijun

    (@seijun)

    Would just plain is_multitax() work for both all muti tax and single tax pages, or does my conditional also need to include is_tax for single tax pages?

    Here is the code for my description. I got this from a tutorial on making tax archive pages. Sorry if the answer is obvious, I don’t really know any php.

    <?php
    if ( tag_description() !== '' ) { ?>
    <?php echo tag_description(); ?>
    <?php } ?>

    Thread Starter Seijun

    (@seijun)

    Putting get_terms instead of get_the_terms also has no effect.

    Thread Starter Seijun

    (@seijun)

    @ aut0poietic:: Thank you for taking the time to reply. I tried the code in your last post

    $terms = get_the_terms( $post->ID, 'operating_system', "fields=names") ;

    But the results were same as before. No output of any kind, as if the code did not even exist.

Viewing 15 replies - 1 through 15 (of 23 total)