WordPress.org

Ready to get started?Download WordPress

Forums

How to have an multipage alphabetical Tag index (68 posts)

  1. Scouse84
    Member
    Posted 4 years ago #

    Hi,

    I run a music website, which has articles on over a 100 different bands and each article is tagged with the bands name.

    For the last couple of weeks I've been trying to create an index of the bands using the tags. So far I can only get all the tags on one page split into columns, which can be seen here http://www.addictmusic.co.uk/a-z/

    What I ideally want is to have a multi-page index, which will group the pages alphabetically, with an alphabetical navbar at the top.

    So all tags under A would be on one page and all tags under B on the next and so on.

    I have tried the A-Z index plugin, but it doesn't split the pages by letter or use the tags properly

    If anyone can help I would be very grateful

    Thanks

  2. Mark / t31os
    Moderator
    Posted 4 years ago #

    How do you create the current list, do you use a page template?.. if so, can i see what you have so far..

    Shouldn't be too hard to do what you're asking...

    get_terms supports a parameter called "name__like" which allows you to return a list of tags that start with a particular letter, which makes it ideal for what you need.

    All that's essentially needed now is some code to manage the various different pages for each letter (and course numeric values). Should be easy enough, but i'd like to see what you have currently first..

  3. Scouse84
    Member
    Posted 4 years ago #

    Thanks for the reply.

    Currently I use the Multi-column Tag Map plugin

  4. Mark / t31os
    Moderator
    Posted 4 years ago #

    Ok, that's great but it doesn't help me understand how your current page creates it's index of post tags..

    Does the plugin do it all for you?

  5. Scouse84
    Member
    Posted 4 years ago #

    yeah, it does.

    I just add a page and the following code [mctagmap columns="2" more="more!" hide="yes" num_show="100"]

    Which then creates the index

  6. Mark / t31os
    Moderator
    Posted 4 years ago #

    I've made a page template for you to use. You'll need to do update the HTML to suit your theme, can you manage that?

    I have a working copy, i'm just testing it a little then i'll provide the code for you..

  7. Mark / t31os
    Moderator
    Posted 4 years ago #

    Hi Scouse,

    See the following for page template code.
    http://wordpress.pastebin.ca/1730939

    Copy the code from the bottom most area of that page (further down), paste it into an empty file, save that file as something like atozindex.php , upload the file to your theme's folder, then create a page (or using your existing a-z one) and attach the new template (should be selectable to the right) and save.

    View the page, let me know if that's what you had in mind (bearing in mind, i couldn't write the HTML to fit perfectly because i'm not running the same theme). I did put some elements in to match what's on your current page, so it should only require minor adjustment..

    EDIT: You might find this version a little easier to work with, moved the PHP stuff to the top, and the HTML stuff toward the bottom (you may find this easier).
    http://wordpress.pastebin.ca/1730948

  8. Scouse84
    Member
    Posted 4 years ago #

    Thanks I'll give it a go

  9. Scouse84
    Member
    Posted 4 years ago #

    Fantastic, works like a charm.

  10. Mark / t31os
    Moderator
    Posted 4 years ago #

    Happy to help.. ;)

  11. ka81
    Member
    Posted 4 years ago #

    Thanx for code!!!!

    but, a few questions!
    page - komanda

    i'm using a http://wordpress.org/extend/plugins/template-tag-shortcodes/ plugin.
    /wp-admin/page.php?action=edit&post=1266

    [wp_tag_cloud smallest=8 largest=10 number=10000 order=ASC exclude=16,58,59,60,61,62,63,64,65,66,67,68,69,70,72,71,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,90,101,102,103,104,105,106,107,108,109,110,112,113,114,115,116,117,118,119,120,121,122,123,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,213,354,355,380,381]

    1) the footer is missed :(
    i just can't understand what to change in your code.
    2) when click (fo example) on letter E - tags=e we don't get a page with only E-tags.. :(
    3) the list of tags is not exluding what i need to exclude. :(

    Please, help with that..

  12. ka81
    Member
    Posted 4 years ago #

    1) the footer is missed :(
    i just can't understand what to change in your code.

    that one is dealed. was a problem with missing </div>.

    but the main problems still exist.

  13. Tessi
    Member
    Posted 4 years ago #

    Please..please, suggest any issues, i have a similar problem))
    Maybe, t31os_'s code isn't work correctly in WP v.2.9.1 ?? differently "recalculating" tags?
    2ka81, what is you're version?

    p.s. sorry for my english, i hope you understand me :)))

  14. ka81
    Member
    Posted 4 years ago #

    <meta name="generator" content="WordPress 2.8.6" />

  15. ka81
    Member
    Posted 4 years ago #

    t31os_

    help please....

  16. Mark / t31os
    Moderator
    Posted 4 years ago #

    So what's the problem specifically, that non-matching tags are being listed on some pages?

  17. ka81
    Member
    Posted 4 years ago #

    http://x-files.net.ua/?page_id=1266

    2) when click (fo example) on letter E - we don't get a page with only E-tags.
    http://x-files.net.ua/?page_id=1266?tags=e - not only E, but all tags.

    3) the list of tags is not exluding what i need to exclude. is it possible to exclude?
    i'm using a http://wordpress.org/extend/plugins/template-tag-shortcodes/ plugin with this code:
    [wp_tag_cloud smallest=8 largest=10 number=10000 order=ASC exclude=16,58,59,60,61,62,63,64,65,66,67,68,69,70,72,71,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,90,101,102,103,104,105,106,107,108,109,110,112,113,114,115,116,117,118,119,120,121,122,123,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,213,354,355,380,381]
    .

  18. Mark / t31os
    Moderator
    Posted 4 years ago #

    You should ask the author for support if you need help using a particular plugin (or seek out the authors documentation, if there is any).

    I can't advise you on software i don't use (although i could guess, it may not be helpful). You're welcome to try the code i posted, and i'll happily help you with that, because i can see and know all the associated code.

  19. ka81
    Member
    Posted 4 years ago #

    well, if you'll get smth on your mind about my problem, that whould be great to have some advise from you.

    about author of code: i look through http://wordpress.pastebin.ca/1730939 and just can't get how to contact to author... would you please point me?..

  20. Mark / t31os
    Moderator
    Posted 4 years ago #

    I wrote the code in the pastebin.. ;) It's for use as a page template.

    You mentioned the template tag shortcodes plugin before, so i assumed you were wanting to use that alongside or instead of the pastebin code.

    If you're using the code i supplied (in the pastebin), are you saying there's a problem with incorrect tags showing up using it "as is"? Or are you trying to use this code "inside / alongside / in conjunction with" the aforementioned plugin?

  21. ka81
    Member
    Posted 4 years ago #

    well, step by step my actions:
    1) created a file azindex.php and placed it into /themes/simple-notepad/ with CHMOD 777

    2) in admin panel Theme editor (/wp-admin/theme-editor.php?file=/themes/simple-notepad/azindex.php&theme=Simple+Notepad) i added your code to azindex.php:

    <?php
    /*
    Template Name: Tag Index
    */
    
    get_header();
    
    $valid_characters = range( 'a' , 'z' );
    $valid_numbers = array(1,2,3,4,5,6,7,8,9,0);
    
    $nav = array();
    // Build nav array
    foreach( $valid_characters as $key => $character )
    	$nav[] = '<a href="' . get_permalink( $post->ID ) . '?tags=' . $character . '">' . strtoupper( $character ) . '</a>';
    foreach( $valid_numbers as $key => $number )
    	$nav[] = '<a href="' . get_permalink( $post->ID ) . '?tags=' . $number . '">' . $number . '</a>';
    
    // Array to hold tags, needs to be set, so the empty check works when none of the switch cases hit a match (for whatever reason)
    $tags = array();
    // Array that will hold arrays of tags based on their first letter
    $tag_array = array();
    
    // Main switch
    switch( true ) {
    	// If request for tag with particular letter
    	case ( isset( $_GET['tags'] ) ):
    		// If it's in the arrays created earlier, get tafs and sort into array
    		case ( in_array( $_GET['tags'] , $valid_characters ) || in_array( $_GET['tags'] , $valid_numbers ) ):
    			$tags = get_terms( 'post_tag' , "hide_empty=0&name__like=$_GET[tags]" );
    
    			if( !empty( $tags ) ) {
    				foreach( $tags as $tag ) {
    					$tag_array[$tag->name{0}][] = '<li><a href="'.get_tag_link( $tag->term_id ).'">'.$tag->name.'</a></li>';
    				}
    			}
    		break;
    	break;
    	case ( !isset( $_GET['tags'] ) ):
    	default:
    		$tags = get_terms( 'post_tag' , 'hide_empty=0' );
    
    		if( !empty( $tags ) ) {
    			foreach( $tags as $tag ) {
    				$tag_array[$tag->name{0}][] = '<li><a href="'.get_tag_link( $tag->term_id ).'">'.$tag->name.'</a></li>';
    			}
    		}
    	break;
    }
    // If theres only one item in the array ( well one key ) , then it's a requested tag letter, so add a "Show all" link at the start of the nav
    if( count( $tag_array ) == 1 ) array_unshift( $nav , '<a href="' . get_permalink( $post->ID ) . '">Show all</a>' );
    ?>
    
    <div id="content" class="widecolumn">
    	<!-- Feel free to add regular stuff you want here, like the_content() etc. -->
    	<div class="nav">
    		<?php
    			// Imploding an array is an easy and reliable way to create a string with seperators
    			echo implode( ' | ' , $nav );
    		?>
    	</div>
    <?php
    	// If there's tags in the array
    	if( !empty( $tag_array ) ) {
    		foreach( $tag_array as $character => $character_tags ) {
    		?>
    			<div class="tagindex">
    				<h4><?php echo $character; ?></h4>
    				<ul class="links">
    					<?php foreach( $character_tags as $key => $tag ) { echo $tag; } ?>
    				</ul>
    			</div>
    		<?php
    		}
    	}
    	else {
    		?>
    		<h4>No tags found</h4>
    		<?php
    	}
    	?>
    </div>
    </div>
    <?php get_footer(); ?>

    3) added a new page (/wp-admin/page-new.php) with empty textarea.
    on the right side i choose Tag Index for template.

    4) finaly, we have http://x-files.net.ua/?page_id=1266

    ----
    problem:
    clicking on any letter, we will get to page where will be all the tags, not what we choose.

    P.s.

  22. Mark / t31os
    Moderator
    Posted 4 years ago #

    Perhaps you have something else interacting with the page...

    I've just taken the code straight from your post above, created a file using the same process as you've laid out above.

    Page loads appropriate tags for me..

    Can you "test" under the default theme?

  23. ka81
    Member
    Posted 4 years ago #

    the same thing with default theme. :(
    i can give you the full access to my blog if you wish, so you could look through what is wrong.

    Please, very need your code to be working :)

  24. Mark / t31os
    Moderator
    Posted 4 years ago #

    Maybe there's a problem with one of the functions i referenced.

    Are you on PHP4 by any chance?..

    If no, then i'd suggest toggling plugins to see if that has an effect (ie. turn off, test page, if no change re-enable, and so on for each).

  25. ka81
    Member
    Posted 4 years ago #

    PHP5 the latest.
    about turning off plugins - will try.

    P.S. again:

    i can give you the full access to my blog if you wish, so you could look through what is wrong.

    Please, very need your code to be working :)

  26. ka81
    Member
    Posted 4 years ago #

    well, I deactivated all my active (21) plugins.
    waited a little bit, cleared a cache in browser, got to http://x-files.net.ua/?page_id=1266 , clicked on letter P (and any other).
    and no result, http://x-files.net.ua/?page_id=1266?tags=p - shows all tags, not only started with letter P.
    :(

  27. Mark / t31os
    Moderator
    Posted 4 years ago #

    Ok email me some login credentials and i'll take a look for you...

    [moderated]

    Excuse the name, it's where spam goes. Since i'm posting it openly (where the spammers can see it) i'd prefer to use it... ;)

  28. ka81
    Member
    Posted 4 years ago #

    i send an e-mail to [moderated]

  29. Mark / t31os
    Moderator
    Posted 4 years ago #

    Just going to take a look now..

    EDIT: Spotted the error, will be corrected shortly.. ;)

    EDIT2: All done, have emailed you, incase you're not monitoring the thread.

    Problem was i hadn't accounted for default permalinks (silly mistake)..

  30. Mark / t31os
    Moderator
    Posted 4 years ago #

    For clarity, the fix for above.
    http://wordpress.pastebin.ca/1746118

Topic Closed

This topic has been closed to new replies.

About this Topic