Make WordPress Core


Ignore:
Timestamp:
01/25/2008 07:29:01 PM (17 years ago)
Author:
ryan
Message:

First cut at Manage->Tags. Props jhodgdon. see #5684

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/template.php

    r6659 r6660  
    231231        echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', ($checked ? ' checked="checked"' : "" ), '/> ', $name, "</label></li>";
    232232    }
     233}
     234
     235// Tag stuff
     236
     237// Returns a single tag row (see tag_rows below)
     238// Note: this is also used in admin-ajax.php!
     239function _tag_row( $tag, $class = '' ) {
     240        $count = number_format_i18n( $tag->count );
     241        $count = ( $count > 0 ) ? "<a href='edit.php?tag=$tag->slug'>$count</a>" : $count;
     242       
     243        $out = '';
     244        $out .= '<tr id="tag-' . $tag->term_id . '"' . $class . '>';
     245        $out .= '<th scope="row">' . $tag->term_id . '</th>';
     246
     247        $out .= '<td>' . apply_filters( 'term_name', $tag->name ) . '</td>';
     248
     249        $out .= "<td>$count</td>";     
     250        $out .= '<td><a href="edit-tags.php?action=edit&amp;tag_ID=' . $tag->term_id . '" class="edit">' .
     251            __( 'Edit' ) . "</a></td>" .
     252            '<td><a href="' . wp_nonce_url( "edit-tags.php?action=delete&amp;tag_ID=$tag->term_id",
     253                    'delete-tag_' . $tag->term_id ) .
     254                '" class="delete:the-list:tag-' . $tag->term_id . ' delete">' .
     255                __( 'Delete' ) . "</a></td>";
     256        $out .= '</tr>';
     257       
     258        return $out;
     259}
     260
     261// Outputs appropriate rows for the Nth page of the Tag Management screen,
     262// assuming M tags displayed at a time on the page
     263// Returns the number of tags displayed
     264function tag_rows( $page = 0, $pagesize = 20 ) {
     265   
     266    // Get a page worth of tags
     267    $start = $page * $pagesize;
     268    $tags = get_terms( 'post_tag', "offset=$start&number=$pagesize&hide_empty=0"  );
     269   
     270    // convert it to table rows
     271    $out = '';
     272    $class = '';
     273    $i = 0;
     274    $count = 0;
     275    foreach( $tags as $tag ) {
     276        if( $i ) {
     277            $i = 0;
     278            $class = ' class="alternate"';
     279        } else {
     280            $i = 1;
     281            $class = '';
     282        }
     283
     284        $out .= _tag_row( $tag, $class );
     285        $count++;
     286    }
     287   
     288    // filter and send to screen
     289    $out = apply_filters('tag_rows', $out);
     290    echo $out;
     291    return $count;
    233292}
    234293
Note: See TracChangeset for help on using the changeset viewer.