Make WordPress Core

Changeset 5149


Ignore:
Timestamp:
03/31/2007 06:16:12 AM (18 years ago)
Author:
matt
Message:

All the query stuff we need for tag= URLs to work.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/default/archive.php

    r5105 r5149  
    22
    33    <div id="content" class="narrowcolumn">
    4 
     4<?php is_tag(); ?>
    55        <?php if (have_posts()) : ?>
    66
     
    88<?php /* If this is a category archive */ if (is_category()) { ?>
    99        <h2 class="pagetitle">Archive for the &#8216;<?php single_cat_title(); ?>&#8217; Category</h2>
    10 
     10<?php } elseif( is_tag() ) { ?>
     11<h2 class="pagetitle">Archive for the &#8216;<?php single_cat_title(); ?>&#8217; Tag</h2>
    1112      <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
    1213        <h2 class="pagetitle">Archive for <?php the_time('F jS, Y'); ?></h2>
     
    4142                </div>
    4243
    43                 <p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?></p>
     44                <p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?></p>
    4445
    4546            </div>
  • trunk/wp-content/themes/default/search.php

    r3517 r5149  
    1919                <small><?php the_time('l, F jS, Y') ?></small>
    2020
    21                 <p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?></p>
     21                <p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?></p>
    2222            </div>
    2323
  • trunk/wp-includes/category-template.php

    r5111 r5149  
    3939    }
    4040    return apply_filters('category_link', $catlink, $category_id);
     41}
     42
     43function get_tag_link( $tag_id ) {
     44    global $wp_rewrite;
     45    $catlink = $wp_rewrite->get_category_permastruct();
     46
     47    $category = &get_category($tag_id);
     48    $category_nicename = $category->category_nicename;
     49
     50    if ( empty($catlink) ) {
     51        $file = get_option('home') . '/';
     52        $catlink = $file . '?tag=' . $category_nicename;
     53    } else {
     54
     55        $catlink = str_replace('%tag%', $category_nicename, $catlink);
     56        $catlink = get_option('home') . user_trailingslashit($catlink, 'category');
     57    }
     58    return apply_filters('tag_link', $catlink, $category_id);
    4159}
    4260
     
    183201    $return = $before;
    184202    foreach ( $tags as $tag )
    185         $tag_links[] = '<a href="' . get_category_link($tag->cat_ID) . '">' . $tag->cat_name . '</a>';
     203        $tag_links[] = '<a href="' . get_tag_link($tag->cat_ID) . '">' . $tag->cat_name . '</a>';
    186204
    187205    $tag_links = join( $sep, $tag_links );
  • trunk/wp-includes/category.php

    r5119 r5149  
    207207}
    208208
     209function get_category_by_slug( $slug  ) {
     210    global $wpdb;
     211    $slug = sanitize_title( $slug );
     212    if ( empty( $slug ) )
     213        return false;
     214    $category = $wpdb->get_var( "SELECT * FROM $wpdb->categories WHERE category_nicename = '$slug' " );
     215    return get_category( $category );
     216}
     217
    209218// Get the ID of a category from its name
    210219function get_cat_ID($cat_name='General') {
  • trunk/wp-includes/classes.php

    r5051 r5149  
    22
    33class WP {
    4     var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots');
     4    var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots');
    55
    66    var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type');
  • trunk/wp-includes/query.php

    r5087 r5149  
    8484        return true;
    8585
     86    return false;
     87}
     88
     89function is_tag( $slug = '' ) {
     90    global $wp_query;
     91    if ( !$wp_query->is_tag )
     92        return false;
     93
     94    if ( empty( $slug ) )
     95        return true;
     96
     97    $cat_obj = $wp_query->get_queried_object();
     98    if ( $category == $cat_obj->category_nicename )
     99        return true;
    86100    return false;
    87101}
     
    306320    var $is_author = false;
    307321    var $is_category = false;
     322    var $is_tag = false;
    308323    var $is_search = false;
    309324    var $is_feed = false;
     
    330345        $this->is_author = false;
    331346        $this->is_category = false;
     347        $this->is_tag = false;
    332348        $this->is_search = false;
    333349        $this->is_feed = false;
     
    384400            , 'w'
    385401            , 'category_name'
     402            , 'tag'
    386403            , 'author_name'
    387404            , 'feed'
     
    532549            }
    533550
     551            if (  '' != $qv['tag'] )
     552                $this->is_tag = true;
     553
    534554            if ( empty($qv['author']) || ($qv['author'] == '0') ) {
    535555                $this->is_author = false;
     
    542562            }
    543563
    544             if ( ($this->is_date || $this->is_author || $this->is_category) )
     564            if ( ($this->is_date || $this->is_author || $this->is_category || $this->is_tag ) )
    545565                $this->is_archive = true;
    546566        }
     
    838858            $out_cats = substr($out_cats, 0, -2);
    839859            if ( strlen($in_cats) > 0 )
    840                 $in_cats = " AND $wpdb->post2cat.category_id IN ($in_cats)";
     860                $in_cats = " AND $wpdb->post2cat.category_id IN ($in_cats) AND rel_type = 'category' ";
    841861            if ( strlen($out_cats) > 0 ) {
    842862                $ids = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE $wpdb->post2cat.category_id IN ($out_cats)");
     
    855875        }
    856876
     877        if ( '' != $q['tag'] ) {
     878            $reqcat= get_category_by_slug( $q['tag'] );
     879            if ( !empty($reqcat) )
     880                $reqcat = $reqcat->cat_ID;
     881            else
     882                $reqcat = 0;
     883
     884            $q['cat'] = $reqcat;
     885
     886            $tables = ", $wpdb->post2cat, $wpdb->categories";
     887            $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) LEFT JOIN $wpdb->categories ON ($wpdb->post2cat.category_id = $wpdb->categories.cat_ID) ";
     888            $whichcat = " AND category_id IN ({$q['cat']}) AND rel_type = 'tag' ";
     889            $groupby = "{$wpdb->posts}.ID";
     890        }
     891
    857892        // Category stuff for nice URLs
    858893        if ( '' != $q['category_name'] ) {
     
    882917            $tables = ", $wpdb->post2cat, $wpdb->categories";
    883918            $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) LEFT JOIN $wpdb->categories ON ($wpdb->post2cat.category_id = $wpdb->categories.cat_ID) ";
    884             $whichcat = " AND category_id IN ({$q['cat']}, ";
     919            $whichcat = " AND category_id IN ({$q['cat']} ";
    885920            $whichcat .= get_category_children($q['cat'], '', ', ');
    886921            $whichcat = substr($whichcat, 0, -2);
    887             $whichcat .= ")";
     922            $whichcat .= ") AND rel_type = 'category'";
    888923            $groupby = "{$wpdb->posts}.ID";
    889924        }
     925
     926
    890927
    891928        // Author/user stuff
  • trunk/wp-includes/template-loader.php

    r5104 r5149  
    3434        return;
    3535    } else if ( is_category() && $template = get_category_template()) {
     36        include($template);
     37        return;
     38    } else if ( is_tag() && $template = get_tag_template()) {
    3639        include($template);
    3740        return;
  • trunk/wp-includes/theme.php

    r5087 r5149  
    329329}
    330330
     331function get_tag_template() {
     332    $template = '';
     333    if ( file_exists(TEMPLATEPATH . "/tag-" . get_query_var('tag') . '.php') )
     334        $template = TEMPLATEPATH . "/tag-" . get_query_var('tag') . '.php';
     335    elseif ( file_exists(TEMPLATEPATH . "/tag.php") )
     336        $template = TEMPLATEPATH . "/tag.php";
     337
     338    return apply_filters('tag_template', $template);
     339}
     340
     341
    331342function get_date_template() {
    332343    return get_query_template('date');
Note: See TracChangeset for help on using the changeset viewer.