Advertisement
Guest User

Tag List

a guest
Aug 15th, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.45 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: Tag Index
  4.  */
  5.  
  6. //* Remove standard post content output
  7. /*remove_action( 'genesis_post_content', 'genesis_do_post_content' );
  8. remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
  9.  
  10. add_action( 'genesis_entry_content', 'sk_page_archive_content' );
  11. add_action( 'genesis_post_content', 'sk_page_archive_content' );*/
  12.  
  13. add_filter( 'the_content', 'sk_page_archive_content');
  14. /**
  15.  * This function outputs posts grouped by year and then by months in descending order.
  16.  *
  17.  */
  18. function sk_page_archive_content($content) {
  19.  
  20.      global $post;
  21.      echo // Make an array from A to Z.
  22. $characters = range('A','Z');
  23.  
  24. // Retrieve all tags
  25. $getTags = get_tags( array( 'order' => 'ASC') );
  26.  
  27. // Retrieve first letter from tag name
  28. $isFirstCharLetter = ctype_alpha(substr($getTags[0]->name, 0, 1));
  29.  
  30. // Special Character and Number Loop
  31. // Run a check to see if the first tag starts with a letter
  32. // If it does not, run this
  33. if ( $isFirstCharLetter == false ){
  34.  
  35.      // Print a number container
  36.      $html .= "<div class='tag-group'>";
  37.      $html .= "<h3 class='tag-title'>#</h3>";
  38.      $html .= "<ul class='tag-list'>";
  39.  
  40.      // Special Character/Number Loop
  41.      while( $isFirstCharLetter == false ){
  42.  
  43.           // Get the current tag
  44.           $tag = array_shift($getTags);
  45.  
  46.           // Get the current tag link
  47.           $tag_link = get_tag_link($tag->term_id);
  48.  
  49.           // Print List Item
  50.           $html .= "<li class='tag-item'>";
  51.  
  52.           // Check to see how many tags exist for the current letter then print appropriate code
  53.         if ( $tag->count > 1 ) {
  54.             $html .= "<p><a href='{$tag_link}' title='View all {$tag->count} articles with the tag of {$tag->name}' class='{$tag->slug}'>";
  55.         } else {
  56.             $html .= "<p><a href='{$tag_link}' title='View the article tagged {$tag->name}' class='{$tag->slug}'>";
  57.         }
  58.  
  59.         // Print tag name and count then close the list item
  60.           $html .= "<span class='tag-name'>{$tag->name}</span></a><span class='tag-count'>({$tag->count})</span></p>";
  61.           $html .= "</li>";
  62.  
  63.           // Retrieve first letter from tag name
  64.           // Need to redefine the global variable since we are shifting the array
  65.           $isFirstCharLetter = ctype_alpha(substr($getTags[0]->name, 0, 1));
  66.  
  67.      }
  68.  
  69.      // Close the containers
  70.      $html .= "</ul>";
  71.      $html .= "</div>";
  72. }
  73.  
  74. // Letter Loop
  75. do {
  76.  
  77.      // Get the right letter
  78.      $currentLetter = array_shift($characters);
  79.  
  80.      // Print stuff
  81.      $html .= "<div class='tag-group'>";
  82.      $html .= "<div class='tag-title' id='{$currentLetter}'>{$currentLetter}</div>";
  83.      $html .= "<ul class='tag-list'>";
  84.  
  85.      // While we have tags, run this loop
  86.      while($getTags){
  87.  
  88.           // Retrieve first letter from tag name
  89.           $firstChar = substr($getTags[0]->name, 0, 1);
  90.  
  91.           // Does the first letter match the current letter?
  92.           // Check both upper and lowercase characters for true
  93.           if ( strcasecmp($currentLetter, $firstChar) == 0 ){
  94.  
  95.                // Get the current tag
  96.                $tag = array_shift($getTags);
  97.  
  98.                // Get the current tag link
  99.                $tag_link = get_tag_link($tag->term_id);
  100.  
  101.                // Print stuff
  102.                $html .= "<li class='tag-item'>";
  103.  
  104.                // Check to see how many tags exist for the current letter then print appropriate code
  105.             if ( $tag->count > 1 ) {
  106.                 $html .= "<p><a href='{$tag_link}' title='View all {$tag->count} articles with the tag of {$tag->name}' class='{$tag->slug}'>";
  107.             } else {
  108.                 $html .= "<p><a href='{$tag_link}' title='View the article tagged {$tag->name}' class='{$tag->slug}'>";
  109.             }
  110.  
  111.             // Print more stuff
  112.                $html .= "<span class='tag-name'>{$tag->name}</span></a><span class='tag-count'>({$tag->count})</span></p>";
  113.                $html .= "</li>";
  114.  
  115.           } else {
  116.                break 1;
  117.           }
  118.      }
  119.  
  120.      $html .= "</ul>";
  121.      $html .= "</div>";
  122. } while ( $characters ); // Will loop over each character in the array
  123.  
  124.   // Let's see what we got:
  125.   if( $html )
  126.    $content .= $html;
  127.  
  128.   return $content;
  129. }
  130.  
  131. remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );
  132. remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
  133. remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );
  134.  
  135. genesis();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement