ThemeShaper Forums » Thematic

[closed]

Customize Multi-Column Tag Map to fetch specific post-type

(8 posts)
  • Started 2 years ago by WebInk
  • Latest reply from helgatheviking
  • This topic is not resolved
  1. I'm using a plugin called "Multi-Column Tag Map" that lets you display all tags that were used and arrange them in a alphabetical order. This plugin works fine in a regular post-type but It's not working on a custom post-type that I created. I created a new post-type called 'books' and has an additional taxonomy(Tags) of 'Writers' and 'Tags'.

    I followed this to create my custom post type: http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress

    How do i customize this to fetch my tags from my custom post-type?

    This is the plugin code:

    <?php
    /*
    Plugin Name: Multi-column Tag Map
    Plugin URI: http://tugbucket.net/wordpress/wordpress-plugin-multi-column-tag-map/
    Description: Multi-column Tag Map displays a columnized  and alphabetical (English) listing of all tags used in your site similar to the index pages of a book.
    Version: 8.0
    Author: Alan Jackson
    Author URI: http://tugbucket.net
    */
    
    /*  Copyright 2009-2011  Alan Jackson (alan[at]tugbucket.net)
    
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    */
    
    function wp_mcTagMap($options='') {
    
        $ns_options = array(
                        "columns" => "2",
                        "more" => "View More",
                        "hide" => "no",
                        "num_show" => "5",
                        "toggle" => "no",
                        "show_empty" => "yes",
                       );
    
        if(strpos($options, '|')) {
        $options = explode("|",$options);
        } else {
        $options = explode("&",$options);
        }
    
        foreach ($options as $option) {
    
            $parts = explode("=",$option);
            $options[$parts[0]] = $parts[1];
    
        }
    
        if ($options['columns']) {
        $ns_options['columns'] = $options['columns'];
        } else {
        $options['columns'] = 2;
        }
    
        if ($options['more']) {
        $ns_options['more'] = htmlentities($options['more'], ENT_QUOTES);
        } else {
        $options['more'] = "View more";
        }
    
        if ($options['hide']) {
        $ns_options['hide'] = $options['hide'];
        } else {
        $options['hide'] = "no";
        }
    
        if ($options['num_show']) {
        $ns_options['num_show'] = $options['num_show'];
        } else {
        $options['num_show'] = 5;
        }
    
        if ($options['toggle']) {
        $ns_options['toggle'] = $options['toggle'];
        } else {
        $options['toggle'] = "no";
        }
    
        if ($options['show_empty']) {
        $ns_options['show_empty'] = $options['show_empty'];
        } else {
        $options['show_empty'] = "yes";
        }
    
        $show_empty = $options['show_empty'];
        if($show_empty == "yes"){
            $show_empty = "0";
        }
        if($show_empty == "no"){
            $show_empty = "1";
        }
        $list = '<!-- begin list --><div id="mcTagMap">';
        $tags = get_terms('post_tag', 'order=ASC&hide_empty='.$show_empty.''); // new code!
        $groups = array();
    
        if( $tags && is_array( $tags ) ) {
            foreach( $tags as $tag ) {
                $first_letter = strtoupper( $tag->name[0] );
                $groups[ $first_letter ][] = $tag;
            }
        if( !empty ( $groups ) ) {
            $count = 0;
            $howmany = count($groups);
    
            // this makes 2 columns
            if ($options['columns'] == 2){
            $firstrow = ceil($howmany * 0.5);
            $secondrow = ceil($howmany * 1);
            $firstrown1 = ceil(($howmany * 0.5)-1);
            $secondrown1 = ceil(($howmany * 1)-0);
            }
    
            //this makes 3 columns
            if ($options['columns'] == 3){
            $firstrow = ceil($howmany * 0.33);
            $secondrow = ceil($howmany * 0.66);
            $firstrown1 = ceil(($howmany * 0.33)-1);
            $secondrown1 = ceil(($howmany * 0.66)-1);
            }
    
            //this makes 4 columns
            if ($options['columns'] == 4){
            $firstrow = ceil($howmany * 0.25);
            $secondrow = ceil(($howmany * 0.5)+1);
            $firstrown1 = ceil(($howmany * 0.25)-1);
            $secondrown1 = ceil(($howmany * 0.5)-0);
            $thirdrow = ceil(($howmany * 0.75)-0);
            $thirdrow1 = ceil(($howmany * 0.75)-1);
            }
    
            //this makes 5 columns
            if ($options['columns'] == 5){
            $firstrow = ceil($howmany * 0.2);
            $firstrown1 = ceil(($howmany * 0.2)-1);
            $secondrow = ceil(($howmany * 0.4));
            $secondrown1 = ceil(($howmany * 0.4)-1);
            $thirdrow = ceil(($howmany * 0.6)-0);
            $thirdrow1 = ceil(($howmany * 0.6)-1);
            $fourthrow = ceil(($howmany * 0.8)-0);
            $fourthrow1 = ceil(($howmany * 0.8)-1);
            }
    
            foreach( $groups as $letter => $tags ) {
                if ($options['columns'] == 2){
                if ($count == 0 || $count == $firstrow || $count ==  $secondrow) {
                    if ($count == $firstrow){
                    $list .= "\n<div class='holdleft noMargin'>\n";
                    $list .="\n";
                    } else {
                    $list .= "\n<div class='holdleft'>\n";
                    $list .="\n";
                    }
                    }
                    }
                if ($options['columns'] == 3){
                if ($count == 0 || $count == $firstrow || $count ==  $secondrow) {
                    if ($count == $secondrow){
                    $list .= "\n<div class='holdleft noMargin'>\n";
                    $list .="\n";
                    } else {
                    $list .= "\n<div class='holdleft'>\n";
                    $list .="\n";
                    }
                    }
                    }
                if ($options['columns'] == 4){
                if ($count == 0 || $count == $firstrow || $count ==  $secondrow || $count == $thirdrow) {
                    if ($count == $thirdrow){
                    $list .= "\n<div class='holdleft noMargin'>\n";
                    $list .="\n";
                    } else {
                    $list .= "\n<div class='holdleft'>\n";
                    $list .="\n";
                    }
                    }
                    }
                if ($options['columns'] == 5){
                if ($count == 0 || $count == $firstrow || $count ==  $secondrow || $count == $thirdrow || $count == $fourthrow ) {
                    if ($count == $fourthrow){
                    $list .= "\n<div class='holdleft noMargin'>\n";
                    $list .="\n";
                    } else {
                    $list .= "\n<div class='holdleft'>\n";
                    $list .="\n";
                    }
                    }
                    }
    
        $list .= '<div class="tagindex">';
        $list .="\n";
        $list .='<h4>' . apply_filters( 'the_title', $letter ) . '</h4>';
        $list .="\n";
        $list .= '<ul class="links">';
        $list .="\n";
        $i = 0;
        foreach( $tags as $tag ) {
            $url = attribute_escape( get_tag_link( $tag->term_id ) );
            $name = apply_filters( 'the_title', $tag->name );
        //  $name = ucfirst($name);
            $i++;
            $counti = $i;
            if ($options['hide'] == "yes"){
            $num2show = $options['num_show'];
            $num2show1 = ($options['num_show'] +1);
            $toggle = ($options['toggle']);
    
            if ($i != 0 and $i <= $num2show) {
                $list .= '
    <li><a title="' . $name . '" href="' . $url . '">' . $name . '</a></li>
    ';
                $list .="\n";
                }
            if ($i > $num2show && $i == $num2show1 && $toggle == "no") {
                $list .=  "<li class=\"morelink\">"."<a>".$options['more']."</a>".""."\n";
                }
            if ($i >= $num2show1){
                   $list .= '<li class="hideli"><a title="' . $name . '" href="' . $url . '">' . $name . '</a>';
                   $list .="\n";
            }
            } else {
                $list .= '
    <li><a title="' . $name . '" href="' . $url . '">' . $name . '</a></li>
    ';
                $list .="\n";
            }   
    
        }
            if ($options['hide'] == "yes" && $toggle != "no" && $i == $counti && $i > $num2show) {
                $list .=  "<li class=\"morelink\">"."<a>".$options['more']."</a>"."<a>".$options['toggle']."</a>".""."\n";
            }
        $list .= '';
        $list .="\n";
        $list .= '</div>';
        $list .="\n\n";
            if ($options['columns'] == 3 || $options['columns'] == 2){
            if ( $count == $firstrown1 || $count == $secondrown1) {
                $list .= "</div>";
                }
                }
            if ($options['columns'] == 4){
            if ( $count == $firstrown1 || $count == $secondrown1 || $count == $thirdrow1) {
                $list .= "</div>";
                }
                }
            if ($options['columns'] == 5){
            if ( $count == $firstrown1 || $count == $secondrown1 || $count == $thirdrow1 || $count == $fourthrow1) {
                $list .= "</div>";
                }
                }
    
            $count++;
                }
            }
        $list .="</div>";
        $list .= "<div style='clear: both;'></div></div><!-- end list -->";
            }
        else $list .= '<p>Sorry, but no tags were found</p>';
    
    print $list ;
    
    }
    // end long code
    
    // short code begins
    function sc_mcTagMap($atts, $content = null) {
            extract(shortcode_atts(array(
                        "columns" => "2",
                        "more" => "View More",
                        "hide" => "no",
                        "num_show" => "5",
                        "toggle" => "no",
                        "show_empty" => "yes",
                        "name_divider" => "|", // added 09.02.11
                        "tag_count" => "no",
                        "exclude" => "",
                        "descriptions" => "no",
                        "width" => "",
                        "equal" => "no",
            ), $atts));
    
        if($show_empty == "yes"){
            $show_empty = "0";
        }
        if($show_empty == "no"){
            $show_empty = "1";
        }
    
        if($width){
            $tug_width = "style=\"width: ". $width ."px;\"";
        }
        if($equal == "yes" && $columns != "1"){
            $equalize = 'mcEqualize';
        }
        if($toggle != "no"){
            $toggable = "toggleYes";
        } else {
            $toggable = "toggleNo";
        }
        $list = '<!-- begin list --><div id="mcTagMap" class="'.$equalize.' '.$toggable.'">';
        $tags = get_terms('post_tag', 'order=ASC&hide_empty='.$show_empty.''); // new code!
    
        /* exclude tags */
        foreach($tags as $tag){
            $fl = mb_substr($tag->name,0,1);
            $ll = mb_substr($tag->name,1);
            $tag->name = $fl.$ll;
            if (preg_match('/(?<=^|[^\p{L}])' . preg_quote($tag->name,'/') . '(?=[^\p{L}]|$)/ui', $exclude)) {
                unset($tag->name);
            }
        }
    
        $groups = array();
        if( $tags && is_array( $tags ) ) {
            foreach( $tags as $tag ) {
            /* exclude tags */
            if(isset($tag->name)){
                // added 09.02.11
                if (strlen(strstr($tag->name, $name_divider))>0) {
                    $tag->name = preg_replace("/\s*([\\".$name_divider."])\s*/", "$1", $tag->name);
                    $tagParts = explode($name_divider, $tag->name);
                    $tag->name = $tagParts[1].', '.$tagParts[0];
                }
    
                $first_letter = mb_strtoupper( mb_substr($tag->name,0,1) ); /* Thanks to Birgir Erlendsson */
                $groups[ $first_letter ][] = $tag;
                ksort($groups);
            }
            }
        if( !empty ( $groups ) ) {
            $count = 0;
            $howmany = count($groups);
    
            // this makes 2 columns
            if ($columns == 2){
            $firstrow = ceil($howmany * 0.5);
            $secondrow = ceil($howmany * 1);
            $firstrown1 = ceil(($howmany * 0.5)-1);
            $secondrown1 = ceil(($howmany * 1)-0);
            }
    
            //this makes 3 columns
            if ($columns == 3){
            $firstrow = ceil($howmany * 0.33);
            $secondrow = ceil($howmany * 0.66);
            $firstrown1 = ceil(($howmany * 0.33)-1);
            $secondrown1 = ceil(($howmany * 0.66)-1);
            }
    
            //this makes 4 columns
            if ($columns == 4){
            $firstrow = ceil($howmany * 0.25);
            $secondrow = ceil(($howmany * 0.5)+1);
            $firstrown1 = ceil(($howmany * 0.25)-1);
            $secondrown1 = ceil(($howmany * 0.5)-0);
            $thirdrow = ceil(($howmany * 0.75)-0);
            $thirdrow1 = ceil(($howmany * 0.75)-1);
            }
    
            //this makes 5 columns
            if ($columns == 5){
            $firstrow = ceil($howmany * 0.2);
            $firstrown1 = ceil(($howmany * 0.2)-1);
            $secondrow = ceil(($howmany * 0.4));
            $secondrown1 = ceil(($howmany * 0.4)-1);
            $thirdrow = ceil(($howmany * 0.6)-0);
            $thirdrow1 = ceil(($howmany * 0.6)-1);
            $fourthrow = ceil(($howmany * 0.8)-0);
            $fourthrow1 = ceil(($howmany * 0.8)-1);
            }
    
            foreach( $groups as $letter => $tags ) {
                if ($columns == 2){
                if ($count == 0 || $count == $firstrow || $count ==  $secondrow) {
                    if ($count == $firstrow){
                    $list .= "\n<div class='holdleft noMargin' ". $tug_width .">\n";
                    $list .="\n";
                    } else {
                    $list .= "\n<div class='holdleft' ". $tug_width .">\n";
                    $list .="\n";
                    }
                    }
                    }
                if ($columns == 3){
                if ($count == 0 || $count == $firstrow || $count ==  $secondrow) {
                    if ($count == $secondrow){
                    $list .= "\n<div class='holdleft noMargin' ". $tug_width .">\n";
                    $list .="\n";
                    } else {
                    $list .= "\n<div class='holdleft' ". $tug_width .">\n";
                    $list .="\n";
                    }
                    }
                    }
                if ($columns == 4){
                if ($count == 0 || $count == $firstrow || $count ==  $secondrow || $count == $thirdrow) {
                    if ($count == $thirdrow){
                    $list .= "\n<div class='holdleft noMargin' ". $tug_width .">\n";
                    $list .="\n";
                    } else {
                    $list .= "\n<div class='holdleft' ". $tug_width .">\n";
                    $list .="\n";
                    }
                    }
                    }
                if ($columns == 5){
                if ($count == 0 || $count == $firstrow || $count ==  $secondrow || $count == $thirdrow || $count == $fourthrow ) {
                    if ($count == $fourthrow){
                    $list .= "\n<div class='holdleft noMargin' ". $tug_width .">\n";
                    $list .="\n";
                    } else {
                    $list .= "\n<div class='holdleft' ". $tug_width .">\n";
                    $list .="\n";
                    }
                    }
                    }
    
        $list .= '<div class="tagindex">';
        $list .="\n";
        $list .='<h4>' . apply_filters( 'the_title', $letter ) . '</h4>';
        $list .="\n";
        $list .= '<ul class="links">';
        $list .="\n";
        $i = 0;
    
        uasort( $tags, create_function('$a, $b', 'return strnatcasecmp($a->name, $b->name);') ); // addded 09.02.11
    
        foreach( $tags as $tag ) {
            /* exclude tags */
            if(isset($tag->name)){
            // added 9.28.11
            if($tag_count == "yes"){
                $mctagmap_count = ' <span class="mctagmap_count">('.$tag->count.')</span>';
            }
    
            $url = attribute_escape( get_tag_link( $tag->term_id ) );
            $name = apply_filters( 'the_title', $tag->name );
            if($descriptions == "yes"){
                $mctagmap_description = '<span class="tagDescription">' . $tag->description . '</span>';
            }
            //$name = ucfirst($name);
            $i++;
            $counti = $i;
            if ($hide == "yes"){
            $num2show = $num_show;
            $num2show1 = ($num_show +1);
            //$toggle = ($options['toggle']);
    
            if ($i != 0 and $i <= $num2show) {
                $list .= '
    <li><a title="' . $name . '" href="' . $url . '">' . $name . '</a>'. $mctagmap_count . $mctagmap_description . '</li>
    ';
                $list .="\n";
                }
            if ($i > $num2show && $i == $num2show1 && $toggle == "no") {
                $list .=  "<li class=\"morelink\">"."<a>".$more."</a>".""."\n";
                }
            if ($i >= $num2show1){
                   $list .= '<li class="hideli"><a title="' . $name . '" href="' . $url . '">' . $name . '</a>' . $mctagmap_count . $mctagmap_description . '';
                   $list .="\n";
            }
            } else {
                $list .= '
    <li><a title="' . $name . '" href="' . $url . '">' . $name . '</a>' . $mctagmap_count . $mctagmap_description . '</li>
    ';
                $list .="\n";
            }
            }   
    
        }
            if ($hide == "yes" && $toggle != "no" && $i == $counti && $i > $num2show) {
                $list .=  "<li class=\"morelink\">"."<a>".$more."</a>"."<a>".$toggle."</a>".""."\n";
            }    
    
        $list .= '';
        $list .="\n";
        $list .= '</div>';
        $list .="\n\n";
            if ($columns == 3 || $columns == 2){
            if ( $count == $firstrown1 || $count == $secondrown1) {
                $list .= "</div>";
                }
                }
            if ($columns == 4){
            if ( $count == $firstrown1 || $count == $secondrown1 || $count == $thirdrow1) {
                $list .= "</div>";
                }
                }
            if ($columns == 5){
            if ( $count == $firstrown1 || $count == $secondrown1 || $count == $thirdrow1 || $count == $fourthrow1) {
                $list .= "</div>";
                }
                }
    
            $count++;
                }
            }
        $list .="</div>";
        $list .= "<div style='clear: both;'></div></div><!-- end list -->";
            }
        else $list .= '<p>Sorry, but no tags were found</p>';
    
    return $list;
    
    }
    
    add_shortcode("mctagmap", "sc_mcTagMap");
    // end shortcode
    
    function mctagmap_donate($links, $file) {
    $plugin = plugin_basename(__FILE__);
    // create link
    if ($file == $plugin) {
    return array_merge( $links, array( sprintf( '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GX8RH7F2LR74J">Donate to mctagmap development</a>', $plugin, __('Donate') ) ));
    }
    return $links;
    }
    add_filter( 'plugin_row_meta', 'mctagmap_donate', 10, 2 );
    
    // the JS and CSS
    add_action('wp_head', 'mcTagMapCSSandJS');
    function mcTagMapCSSandJS(){
    $mctagmapVersionNumber = "8.0";
    $mctagmapCSSpath = './wp-content/themes/'.get_template().'/multi-column-tag-map/mctagmap.css';
        echo "\n";
        if(file_exists($mctagmapCSSpath)){
            echo '<link rel="stylesheet" href="'.$mctagmapCSSpath.'?ver='.$mctagmapVersionNumber.'" type="text/css" media="screen" />';
        } else {
            echo '<link rel="stylesheet" href="'.WP_PLUGIN_URL.'/multi-column-tag-map/mctagmap.css?ver='.$mctagmapVersionNumber.'" type="text/css" media="screen" />';
        }
        echo "\n";
        echo '<script type="text/javascript" src="'.WP_PLUGIN_URL.'/multi-column-tag-map/mctagmap.js?ver='.$mctagmapVersionNumber.'"></script>';
        echo "\n\n";
    }
    
    // overwrite single_tag_title()
    add_filter('single_tag_title', 'mctagmap_single_tag_title', 1, 2);
    function mctagmap_single_tag_title($prefix = '') {
        global $wp_query;
        if ( !is_tag() )
            return;
    
        $tag = $wp_query->get_queried_object();
    
        if ( ! $tag )
            return;
    
        $my_tag_name = str_replace('|', '', $tag->name);
        if ( !empty($my_tag_name) ) {
            if ( $display )
                echo $prefix . $my_tag_name;
            else
                return $my_tag_name;
        }
    }
    
    ?>
    Posted 2 years ago #
  2. in future, please use backticks to display code....on a US keyboard it is next to the 1 on the top left. i've edited your post b/c it broke the site layout.

    this question is sort of way beyond a thematic question. you might want to post it at wordpress.stackexchange.com or wordpress.org/support

    doesn't the latest thematic display tags from taxonomies now anyway?

    Posted 2 years ago #
  3. Hi Helga, Thank You again. :) I've already posted this in wordpress.stackexchange.com. I also posted here because I'm hoping some of you guys here knows some solution.

    I'm trying to create an index page of tags that is sort alphabetically. example all tags that begins in 'A' should be in 'A' section or all tags that begins with 'G' should be placed in 'G' section.

    I'm doubt Thematic support it natively. -- but it's just me. I'm not sure.

    Any ideas or alternative to this?

    Posted 2 years ago #
  4. now that your question is clearer, no thematic doesn't support that natively. but can't you just do a loop with the results from get_terms() , which can sort terms alphabetically.

    http://codex.wordpress.org/Function_Reference/get_terms

    in your loop you can use a little conditional logic to control how often you trigger the grouping. i'm using categories b/c i don't have enough useful terms in another other taxonomy. obviously, change to suit.

    $terms = get_terms( 'category', array('orderby'=>'slug','order'=>'DSC'));
    
    $xletter = NULL;
    
    foreach($terms as $term){
    
       $letter = substr($term->slug, 0, 1); //gets first letter of slug
    
       if($letter != $xletter){  //if the letter has  changed then print it out
    	echo '<h2>' .$letter . '</h2>';
    }
    
    $xletter = substr($term->slug, 0, 1); //gets first letter of slug
    
    echo $term->name . '';  //echo the term name
    
    }
    Posted 2 years ago #
  5. Hi Helga,

    Thank your again the solution. Apologize for my stupid question, How can this be implemented/test? do I need to create a custom template? or insert in my function.php? -- how do i link it to my page 'Tags Map' or should I install a plugin where i can run php on specific page?

    thanks in advance!

    Posted 2 years ago #
  6. i'd create a custom template. either a page template if you want to be able to edit some text in it from the backend of WP. or as the taxonomy archive. taxonomy-writers.php or taxonomy-tags.php or taxonomy.php to have it apply to all custom taxonomies. then paste this in where you'd like it to display.

    i still don't understand what the tag maps are so can't help there.

    Posted 2 years ago #
  7. The "Tag Map" Basically is for user who wants to browser articles that has that tag. eg, they only want to browser articles that has a tag of "DIY"

    I'm building a mini online library of articles. Now I created a custom post type so I/We can create pages/post of books (separate to other post/pages). Now book has it's own custom taxonomy like "Writer/Author" and "Tags". Tags will be use to categorize or identify the book or article. I use Tags over Category since, I don't need to have a child category or parent category. A one level would work for me and Tags suits to it.

    I hope this make sense. Thanks!

    Posted 2 years ago #
  8. i guess it makes sense (not really), but i don't see how the 'map' any different from a taxonomy archive? if you are on the bacon tag archive you'll only see posts that are tagged w/ the term 'bacon'.

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.