• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Custom page template for tag list, please advise

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Custom page template for tag list, please advise

This topic is: resolved

Tagged: custom page templates, php, tags, taxonomies

  • This topic has 14 replies, 5 voices, and was last updated 11 years, 6 months ago by Genesis Developer.
Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • August 13, 2014 at 9:21 pm #118694
    cookieandkate
    Member

    Hello!

    I'm trying to create a custom page template that creates a list of my tags, ordered alphabetically, with labels for each letter. I based my code on this template. It's almost where I want it to be, but not quite. I'm sure that what I want to accomplish is possible, but my PHP knowledge is lacking. I'd really appreciate your help!

    Here's how the page looks now: http://i.imgur.com/cG7b9gQ.png

    Here's what I want to change:
    I want the page content to display before inserting the tags list.
    I want to get rid of the random word, "Array," that displays on the page right before the letter, "A".
    Unnecessary, but I'd like to automatically capitalize the first letter of the tags, if possible. (Just the first letter, not both.)

    Here's my code:

    
    <?php
    /*
    Template Name: Tag Index
     */
    
    //* Remove standard post content output
    remove_action( 'genesis_post_content', 'genesis_do_post_content' );
    remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
    
    add_action( 'genesis_entry_content', 'sk_page_archive_content' );
    add_action( 'genesis_post_content', 'sk_page_archive_content' );
    /**
     * This function outputs posts grouped by year and then by months in descending order.
     *
     */
    function sk_page_archive_content() {
    
         global $post;
         echo // Make an array from A to Z.
    $characters = range('A','Z');
    
    // Retrieve all tags
    $getTags = get_tags( array( 'order' => 'ASC') );
    
    // Retrieve first letter from tag name
    $isFirstCharLetter = ctype_alpha(substr($getTags[0]->name, 0, 1));
    
    // Special Character and Number Loop
    // Run a check to see if the first tag starts with a letter
    // If it does not, run this
    if ( $isFirstCharLetter == false ){
    
         // Print a number container
         $html .= "<div class='tag-group'>";
         $html .= "<h3 class='tag-title'>#</h3>";
         $html .= "<ul class='tag-list'>";
    
         // Special Character/Number Loop
         while( $isFirstCharLetter == false ){
    
              // Get the current tag
              $tag = array_shift($getTags);
    
              // Get the current tag link
              $tag_link = get_tag_link($tag->term_id);
    
              // Print List Item
              $html .= "<li class='tag-item'>";
    
              // Check to see how many tags exist for the current letter then print appropriate code
            if ( $tag->count > 1 ) {
                $html .= "<p><a href='{$tag_link}' title='View all {$tag->count} articles with the tag of {$tag->name}' class='{$tag->slug}'>";
            } else {
                $html .= "<p><a href='{$tag_link}' title='View the article tagged {$tag->name}' class='{$tag->slug}'>";
            }
    
            // Print tag name and count then close the list item
              $html .= "<span class='tag-name'>{$tag->name}</span></a><span class='tag-count'>({$tag->count})</span></p>";
              $html .= "</li>";
    
              // Retrieve first letter from tag name
              // Need to redefine the global variable since we are shifting the array
              $isFirstCharLetter = ctype_alpha(substr($getTags[0]->name, 0, 1));
    
         }
    
         // Close the containers
         $html .= "</ul>";
         $html .= "</div>";
    }
    
    // Letter Loop
    do {
    
         // Get the right letter
         $currentLetter = array_shift($characters);
    
         // Print stuff
         $html .= "<div class='tag-group'>";
         $html .= "<div class='tag-title' id='{$currentLetter}'>{$currentLetter}</div>";
         $html .= "<ul class='tag-list'>";
    
         // While we have tags, run this loop
         while($getTags){
    
              // Retrieve first letter from tag name
              $firstChar = substr($getTags[0]->name, 0, 1);
    
              // Does the first letter match the current letter?
              // Check both upper and lowercase characters for true
              if ( strcasecmp($currentLetter, $firstChar) == 0 ){
    
                   // Get the current tag
                   $tag = array_shift($getTags);
    
                   // Get the current tag link
                   $tag_link = get_tag_link($tag->term_id);
    
                   // Print stuff
                   $html .= "<li class='tag-item'>";
    
                   // Check to see how many tags exist for the current letter then print appropriate code
                if ( $tag->count > 1 ) {
                    $html .= "<p><a href='{$tag_link}' title='View all {$tag->count} articles with the tag of {$tag->name}' class='{$tag->slug}'>";
                } else {
                    $html .= "<p><a href='{$tag_link}' title='View the article tagged {$tag->name}' class='{$tag->slug}'>";
                }
    
                // Print more stuff
                   $html .= "<span class='tag-name'>{$tag->name}</span></a><span class='tag-count'>({$tag->count})</span></p>";
                   $html .= "</li>";
    
              } else {
                   break 1;
              }
         }
    
         $html .= "</ul>";
         $html .= "</div>";
    } while ( $characters ); // Will loop over each character in the array
    
    // Let's see what we got:
    echo($html);
    
    ?>
              <?php
    }
    
    remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );
    remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
    remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );
    
    genesis();
    August 13, 2014 at 9:30 pm #118696
    AnitaC
    Keymaster

    What exactly do you mean by:

    I want the page content to display before inserting the tags list.

    Are you trying to accomplish something like this - http://www.web-savvy-marketing.com/live/?theme=Sarah%20Ellen or this - http://www.web-savvy-marketing.com/live/?theme=Carla%20Anna?


    Need help with customization or troubleshooting? Reach out to me.

    August 13, 2014 at 9:34 pm #118697
    Brad Dalton
    Participant

    This answers one question http://wpsites.net/web-design/using-php-code-to-change-words-letters-to-uppercase-lowercase/

    Rather than hard code it into a tag.php template file you could use get_template_part


    Tutorials for StudioPress Themes.

    August 13, 2014 at 9:41 pm #118698
    Brad Dalton
    Participant

    This is what i would use and change the code to displays tags http://wpsites.net/web-design/custom-genesis-archives-template-show-all-posts-in-all-categories/


    Tutorials for StudioPress Themes.

    August 13, 2014 at 9:54 pm #118699
    cookieandkate
    Member

    Thanks, you two.

    Anita: No, I don't see anything on those themes like what I want.

    I understand that the code I provided strips the page content from the code. I don't want that to happen. I want to be able to add page content like I would for any page, THEN I want the tag list that I've designed to display underneath that content.

    Brad: Thank you for sharing the capitalization trick. I don't know where to insert that code into my PHP template, though.

    Your category solution is cool, but I have a couple hundred tags that I'm trying to list. I just want the tag names to appear in an alphabetical list, like I've already designed, but I want the page content to appear above it. Do you know how to make that happen?

    I'd really love your help here! Thank you,
    Kate

    August 14, 2014 at 6:26 am #118758
    cookieandkate
    Member

    If it's too complicated to insert the page text before the list, I'd like to be able to insert HTML code to display above the list in my PHP code. I can't figure out how to do that. I still can't figure out how to remove the word "Array" that shows up before my list. (Again, here's my screenshot: http://i.imgur.com/cG7b9gQ.png)

    August 14, 2014 at 11:58 am #118831
    Lauren @ OnceCoupled
    Member

    To add the content of the page, just call it at the beginning of your function: the_content();

    I'm not sure where that "Array" is coming from. When you view the page source, what containers is it in? And it's only printed once at the very beginning of all the letters, yes?


    We create mobile-first, PageSpeed-optimized, pixel-perfect custom themes! https://www.oncecoupled.com

    August 14, 2014 at 12:33 pm #118836
    Genesis Developer
    Member

    I want the page content to display before inserting the tags list.

    Comment out this code like

    //* Remove standard post content output
    /*remove_action( 'genesis_post_content', 'genesis_do_post_content' );
    remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
    
    add_action( 'genesis_entry_content', 'sk_page_archive_content' );
    add_action( 'genesis_post_content', 'sk_page_archive_content' );*/

    Now filter the the_content() function. Then you will get your page content at top.

    add_filter( 'the_content', 'sk_page_archive_content', ); 
    function sk_page_archive_content($content) {
      // WRITE YOUR EXISTING CODE HERE
      // Now remove this line echo($html);and write the following code
      $content .= $html;
    
      return $content;
    }
    

    Download Genesis Featured Posts Combo Widget | Simple Grid Layouts Plugin for Posts, CPTs and terms
    You can request new tips/help.

    August 14, 2014 at 11:15 pm #118902
    cookieandkate
    Member

    Thank you all so much for your help! Lauren, yes, "Array" is only printed once at the beginning of the letters. <div class="entry-content" itemprop="text">Array<div class='tag-group'><div class='tag-title' id='A'>A</div>

    Genrock, I really appreciate your detailed instructions. I believe I'm implemented them as instructed, but I'm getting a blank page. Do you see what's wrong here? I'm stuck and would so appreciate your help.

    
    <?php
    /*
    Template Name: Tag Index
     */
    
    //* Remove standard post content output
    /*remove_action( 'genesis_post_content', 'genesis_do_post_content' );
    remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
    
    add_action( 'genesis_entry_content', 'sk_page_archive_content' );
    add_action( 'genesis_post_content', 'sk_page_archive_content' );*/
    
    add_filter( 'the_content', 'sk_page_archive_content', ); 
    function sk_page_archive_content($content) {
    /**
     * This function outputs posts grouped by year and then by months in descending order.
     *
     */
    function sk_page_archive_content() {
    
         global $post;
         echo // Make an array from A to Z.
    $characters = range('A','Z');
    
    // Retrieve all tags
    $getTags = get_tags( array( 'order' => 'ASC') );
    
    // Retrieve first letter from tag name
    $isFirstCharLetter = ctype_alpha(substr($getTags[0]->name, 0, 1));
    
    // Special Character and Number Loop
    // Run a check to see if the first tag starts with a letter
    // If it does not, run this
    if ( $isFirstCharLetter == false ){
    
         // Print a number container
         $html .= "<div class='tag-group'>";
         $html .= "<h3 class='tag-title'>#</h3>";
         $html .= "<ul class='tag-list'>";
    
         // Special Character/Number Loop
         while( $isFirstCharLetter == false ){
    
              // Get the current tag
              $tag = array_shift($getTags);
    
              // Get the current tag link
              $tag_link = get_tag_link($tag->term_id);
    
              // Print List Item
              $html .= "<li class='tag-item'>";
    
              // Check to see how many tags exist for the current letter then print appropriate code
            if ( $tag->count > 1 ) {
                $html .= "<p><a href='{$tag_link}' title='View all {$tag->count} articles with the tag of {$tag->name}' class='{$tag->slug}'>";
            } else {
                $html .= "<p><a href='{$tag_link}' title='View the article tagged {$tag->name}' class='{$tag->slug}'>";
            }
    
            // Print tag name and count then close the list item
              $html .= "<span class='tag-name'>{$tag->name}</span></a><span class='tag-count'>({$tag->count})</span></p>";
              $html .= "</li>";
    
              // Retrieve first letter from tag name
              // Need to redefine the global variable since we are shifting the array
              $isFirstCharLetter = ctype_alpha(substr($getTags[0]->name, 0, 1));
    
         }
    
         // Close the containers
         $html .= "</ul>";
         $html .= "</div>";
    }
    
    // Letter Loop
    do {
    
         // Get the right letter
         $currentLetter = array_shift($characters);
    
         // Print stuff
         $html .= "<div class='tag-group'>";
         $html .= "<div class='tag-title' id='{$currentLetter}'>{$currentLetter}</div>";
         $html .= "<ul class='tag-list'>";
    
         // While we have tags, run this loop
         while($getTags){
    
              // Retrieve first letter from tag name
              $firstChar = substr($getTags[0]->name, 0, 1);
    
              // Does the first letter match the current letter?
              // Check both upper and lowercase characters for true
              if ( strcasecmp($currentLetter, $firstChar) == 0 ){
    
                   // Get the current tag
                   $tag = array_shift($getTags);
    
                   // Get the current tag link
                   $tag_link = get_tag_link($tag->term_id);
    
                   // Print stuff
                   $html .= "<li class='tag-item'>";
    
                   // Check to see how many tags exist for the current letter then print appropriate code
                if ( $tag->count > 1 ) {
                    $html .= "<p><a href='{$tag_link}' title='View all {$tag->count} articles with the tag of {$tag->name}' class='{$tag->slug}'>";
                } else {
                    $html .= "<p><a href='{$tag_link}' title='View the article tagged {$tag->name}' class='{$tag->slug}'>";
                }
    
                // Print more stuff
                   $html .= "<span class='tag-name'>{$tag->name}</span></a><span class='tag-count'>({$tag->count})</span></p>";
                   $html .= "</li>";
    
              } else {
                   break 1;
              }
         }
    
         $html .= "</ul>";
         $html .= "</div>";
    } while ( $characters ); // Will loop over each character in the array
    
    // Let's see what we got:
    $content .= $html;
    
      return $content;
    }
    
    ?>
              <?php
    }
    
    remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );
    remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
    remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );
    
    genesis();
    August 14, 2014 at 11:17 pm #118903
    cookieandkate
    Member

    Ok, I realize I have repeats of sk_page_archive_content... but removing one or the other doesn't solve the problem.

    August 14, 2014 at 11:38 pm #118908
    Genesis Developer
    Member

    Please change this line

    add_filter( 'the_content', 'sk_page_archive_content', );

    with

    add_filter( 'the_content', 'sk_page_archive_content' );

    I made mistake


    Download Genesis Featured Posts Combo Widget | Simple Grid Layouts Plugin for Posts, CPTs and terms
    You can request new tips/help.

    August 14, 2014 at 11:41 pm #118909
    Genesis Developer
    Member

    Here is the full code http://pastebin.com/7sqRZau9


    Download Genesis Featured Posts Combo Widget | Simple Grid Layouts Plugin for Posts, CPTs and terms
    You can request new tips/help.

    August 14, 2014 at 11:49 pm #118911
    Genesis Developer
    Member

    Code is working for me. I tested it on my site. You need to add the CSS for design and it'll look very nice.

    Replace this line echo // Make an array from A to Z. by // Make an array from A to Z. and Array text will remove from page.


    Download Genesis Featured Posts Combo Widget | Simple Grid Layouts Plugin for Posts, CPTs and terms
    You can request new tips/help.

    August 15, 2014 at 12:20 am #118916
    cookieandkate
    Member

    Genwrock, that code works marvelously! Thank you so very much!!!

    August 15, 2014 at 12:30 am #118918
    Genesis Developer
    Member

    You're welcome. Glad to help you.

    Please mark the thread as RESOLVED


    Download Genesis Featured Posts Combo Widget | Simple Grid Layouts Plugin for Posts, CPTs and terms
    You can request new tips/help.

  • Author
    Posts
Viewing 15 posts - 1 through 15 (of 15 total)
  • The topic ‘Custom page template for tag list, please advise’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble