• Resolved gcarson

    (@gcarson)


    Hi,

    I’m attempting to print out my tags, one letter on each page I created. I’m using the name__like function and it works great. For example, for tags starting with the letter A, I’m suing

    $tags = get_tags( array('name__like' => "a", 'order' => 'ASC') );

    However, I can’t figure out how to print tags that start with a number. I’ve tried wrapping the numbers in single quotes, double quotes, or statements but it only seems to give me the first number I enter. I need it to print out tags starting with the numbers 1 through 9. Any thoughts on how to accomplish this?

    Thanks,

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter gcarson

    (@gcarson)

    anyone have any thoughts on this?

    Works for me with numbers, are you sure the given tags are tagged onto posts currently?..

    get_tags won’t return tags not assigned to posts by default … if you want to show tags that aren’t associated with any posts then you’ll need to add the hide_empty parameter in and set it to 0 or false

    Thread Starter gcarson

    (@gcarson)

    Thanks for the reply. Here’s what I’m doing. I’m printing out all my tags alphabetically. However, instead of printing out A-Z on one page (i have thousands of tags), I’m doing it by letter. I have the letter pages working, but can’t get the number page to work. So, I have a link that says something like ‘view tags that begin with a #’ and I want to print out all tags that begin with a number (or even code it to say print tags that don’t begin with a letter). But I can’t figure out how to do it. Any combination I do only prints out tags that begin with 1 and not any other number. Any thoughts?

    Have a look at the example i gave here, does this help at all?
    http://wordpress.org/support/topic/346157?replies=10

    Thread Starter gcarson

    (@gcarson)

    Will take a look. Here’s the code I currently use on my ‘Tags that begin with the letter A’ page. I have a page and change the A for each letter. The letters work, the page with numbers doesn’t. I’ll play around and report back.

    <?php
    $tags = get_tags( array('name__like' => "a", 'order' => 'ASC') );
    $tags_count = count($tags);
    $count = intval( $tags->count );
    $percolumn = ceil($tags_count / 3);
    
    for ($i = 0;$i < $tags_count;$i++):
        if ($i < $percolumn):
        $tag_left .= '
    	<li><a href="'. get_tag_link($tags[$i]->term_id) . '"rel="tag">' . $tags[$i]->name .' (' . $tags[$i]->count . ')</a></li>
    ' . "\n";
        elseif ($i >= $percolumn && $i < $percolumn*2):
        $tag_mid .= '
    	<li><a href="'. get_tag_link($tags[$i]->term_id) . '"rel="tag">' . $tags[$i]->name .'  (' . $tags[$i]->count . ')</a></li>
    ' . "\n";
        elseif ($i >= $percolumn*2):
        $tag_right .= '
    	<li><a href="'. get_tag_link($tags[$i]->term_id) . '"rel="tag">' . $tags[$i]->name .' (' . $tags[$i]->count . ')</a></li>
    ' . "\n";
        endif;
    endfor;
    ?>
    
    <div class="list">
    <ul>
    <?php echo $tag_left; ?>
    </ul>
    </div>
    
    <div class="list">
    <ul>
    <?php echo $tag_mid; ?>
    </ul>
    </div>
    
    <div class="list">
    <ul>
    <?php echo $tag_right; ?>
    </ul>
    </div>

    This prints the list out in three columns

    Thread Starter gcarson

    (@gcarson)

    just tested the script you posted.. its pretty neat.. not exactly what i was looking for but maybe I can tweak to make it work..

    Thread Starter gcarson

    (@gcarson)

    Yeah, can’t figure out how to combine your code to work with what I have. On my pages, I have my navigation bar.. then under that, i have search by # | A | …. Z. Those then link to individual pages. I’m not sure how to modify the code you presented so that I can have the navigation in my header and then the output on each individual page.

    Thread Starter gcarson

    (@gcarson)

    Tried a bad fix but it worked. I just did an array for each number and then merged all the arrays. Hope this helps someone. And if someone has a cleaner way to do this, please let us know.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘name__like statement for numbers’ is closed to new replies.