WordPress.org

Ready to get started?Download WordPress

Forums

Simple Taxonomies - any place of the post (12 posts)

  1. Raft
    Member
    Posted 5 years ago #

    How to insert the function in any place of the post, but not at the end of it?

  2. MichaelH
    Member
    Posted 5 years ago #

    Wouldn't you put the code in your template before the_content?

    From yoast's example:

    <div id="yoast-taxonomy">
      <span class="taxonomy-people">
        People:
          <a href="http://example.com/people/joost/" rel="tag">Joost</a>,
          <a href="http://example.com/people/marieke/" rel="tag">Marieke</a>,
          <a href="http://example.com/people/tycho/" rel="tag">Tycho</a>
      </span>
    </div>
    <?php
    the_content('<p class="serif">Read the rest of this entry &raquo;</p>');
    ?>
  3. Raft
    Member
    Posted 5 years ago #

    I just activated plugin and it appeared after the_content. And I need to put the 1st Slug before the_content, and the 2nd slug after it. Sorry for my English)

  4. MichaelH
    Member
    Posted 5 years ago #

  5. Raft
    Member
    Posted 5 years ago #

    I looked at the info but didn't find the answer to my question

  6. Zack Katz
    Member
    Posted 4 years ago #

    Add this to your theme's functions.php file:

    function show_taxonomies_here() {
    global $post;
    $opt  = get_option('yoast_simpletax');
    $output = '';
    foreach ( $opt['taxonomies'] as $taxonomy ) {
    $terms = get_the_term_list( $post->ID, $taxonomy['name'], $taxonomy['label'].':</dt><dd>', ',</dd><dd>', '</dd>' );
             if ($terms) {
                // For each taxonomy, create a dt wrapper (Definition Term)
                $output .= "\t".'<dt class="taxonomy-'.$taxonomy['name'].'">'.$terms."\n";
             }
    }
    echo '<dl class="yoast-taxonomy">'."\n".$output."\n".'</dl>';
    }

    Then put if(function_exists(show_taxonomies_here )) { show_taxonomies_here();} in your theme where you want it.

    Untested code, but it should work.

  7. Txurlo
    Member
    Posted 4 years ago #

    Just wanted to state, for posterity, that katzwebdesign's code works like a charm. Thank you :-)

  8. Ovidiu
    Member
    Posted 4 years ago #

    are there any shortcodes available? i.e. I made the taxonomies: country,city,location and only want to display them underneath posts that actually deal with these things. so manually insertign a shortcode to display them woudl be great.

    if that is not possible, and I have ot go editing templates, what would be my best bet to only show them on specific posts?

  9. Ovidiu
    Member
    Posted 4 years ago #

    anyone? having shortcodes is so much greater than having to deal with templates per post :-(

  10. Zack Katz
    Member
    Posted 4 years ago #

    If you want to make it a shortcode, add this to your functions.php instead:

    function simple_taxonomies_shortcode() {
    	return show_taxonomies_here();
    }
    add_shortcode('simpletax', 'simple_taxonomies_shortcode');
    
    function show_taxonomies_here() {
    global $post;
    $opt  = get_option('yoast_simpletax');
    $output = '';
    foreach ( $opt['taxonomies'] as $taxonomy ) {
    $terms = get_the_term_list( $post->ID, $taxonomy['name'], $taxonomy['label'].':</dt><dd>', ',</dd><dd>', '</dd>' );
             if ($terms) {
                // For each taxonomy, create a dt wrapper (Definition Term)
                $output .= "\t".'<dt class="taxonomy-'.$taxonomy['name'].'">'.$terms."\n";
             }
    }
    return '<dl class="yoast-taxonomy">'."\n".$output."\n".'</dl>';
    }

    Then you can use [simpletax] and have it show up wherever you want it inside a post.

  11. Ovidiu
    Member
    Posted 4 years ago #

    just brilliant :-) works perfect.

  12. Ovidiu
    Member
    Posted 4 years ago #

    just one last silly question:

    if I didn't use this code, but the default plugin settings, and set it to auto append the taxonomies after the cotnent, would it always show them, whether I had taxonomies attached to a post or not?

    I notice this code only displays if there really are taxonomies attached to a certain post...

Topic Closed

This topic has been closed to new replies.

About this Topic