All the query stuff we need for tag= URLs to work.
git-svn-id: http://svn.automattic.com/wordpress/trunk@5149 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
2706ae78bd
commit
14f1c622ff
|
@ -1,13 +1,14 @@
|
||||||
<?php get_header(); ?>
|
<?php get_header(); ?>
|
||||||
|
|
||||||
<div id="content" class="narrowcolumn">
|
<div id="content" class="narrowcolumn">
|
||||||
|
<?php is_tag(); ?>
|
||||||
<?php if (have_posts()) : ?>
|
<?php if (have_posts()) : ?>
|
||||||
|
|
||||||
<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
|
<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
|
||||||
<?php /* If this is a category archive */ if (is_category()) { ?>
|
<?php /* If this is a category archive */ if (is_category()) { ?>
|
||||||
<h2 class="pagetitle">Archive for the ‘<?php single_cat_title(); ?>’ Category</h2>
|
<h2 class="pagetitle">Archive for the ‘<?php single_cat_title(); ?>’ Category</h2>
|
||||||
|
<?php } elseif( is_tag() ) { ?>
|
||||||
|
<h2 class="pagetitle">Archive for the ‘<?php single_cat_title(); ?>’ Tag</h2>
|
||||||
<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
|
<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
|
||||||
<h2 class="pagetitle">Archive for <?php the_time('F jS, Y'); ?></h2>
|
<h2 class="pagetitle">Archive for <?php the_time('F jS, Y'); ?></h2>
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@
|
||||||
<?php the_content() ?>
|
<?php the_content() ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
|
<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>
|
<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>
|
||||||
<small><?php the_time('l, F jS, Y') ?></small>
|
<small><?php the_time('l, F jS, Y') ?></small>
|
||||||
|
|
||||||
<p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
|
<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php endwhile; ?>
|
<?php endwhile; ?>
|
||||||
|
|
|
@ -40,6 +40,24 @@ function get_category_link($category_id) {
|
||||||
return apply_filters('category_link', $catlink, $category_id);
|
return apply_filters('category_link', $catlink, $category_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_tag_link( $tag_id ) {
|
||||||
|
global $wp_rewrite;
|
||||||
|
$catlink = $wp_rewrite->get_category_permastruct();
|
||||||
|
|
||||||
|
$category = &get_category($tag_id);
|
||||||
|
$category_nicename = $category->category_nicename;
|
||||||
|
|
||||||
|
if ( empty($catlink) ) {
|
||||||
|
$file = get_option('home') . '/';
|
||||||
|
$catlink = $file . '?tag=' . $category_nicename;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$catlink = str_replace('%tag%', $category_nicename, $catlink);
|
||||||
|
$catlink = get_option('home') . user_trailingslashit($catlink, 'category');
|
||||||
|
}
|
||||||
|
return apply_filters('tag_link', $catlink, $category_id);
|
||||||
|
}
|
||||||
|
|
||||||
function get_category_parents($id, $link = FALSE, $separator = '/', $nicename = FALSE){
|
function get_category_parents($id, $link = FALSE, $separator = '/', $nicename = FALSE){
|
||||||
$chain = '';
|
$chain = '';
|
||||||
$parent = &get_category($id);
|
$parent = &get_category($id);
|
||||||
|
@ -182,7 +200,7 @@ function get_the_tags( $before, $sep, $after ) {
|
||||||
|
|
||||||
$return = $before;
|
$return = $before;
|
||||||
foreach ( $tags as $tag )
|
foreach ( $tags as $tag )
|
||||||
$tag_links[] = '<a href="' . get_category_link($tag->cat_ID) . '">' . $tag->cat_name . '</a>';
|
$tag_links[] = '<a href="' . get_tag_link($tag->cat_ID) . '">' . $tag->cat_name . '</a>';
|
||||||
|
|
||||||
$tag_links = join( $sep, $tag_links );
|
$tag_links = join( $sep, $tag_links );
|
||||||
$tag_links = apply_filters( 'the_tags', $tag_links );
|
$tag_links = apply_filters( 'the_tags', $tag_links );
|
||||||
|
|
|
@ -206,6 +206,15 @@ function get_category_by_path($category_path, $full_match = true, $output = OBJE
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_category_by_slug( $slug ) {
|
||||||
|
global $wpdb;
|
||||||
|
$slug = sanitize_title( $slug );
|
||||||
|
if ( empty( $slug ) )
|
||||||
|
return false;
|
||||||
|
$category = $wpdb->get_var( "SELECT * FROM $wpdb->categories WHERE category_nicename = '$slug' " );
|
||||||
|
return get_category( $category );
|
||||||
|
}
|
||||||
|
|
||||||
// Get the ID of a category from its name
|
// Get the ID of a category from its name
|
||||||
function get_cat_ID($cat_name='General') {
|
function get_cat_ID($cat_name='General') {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class WP {
|
class WP {
|
||||||
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');
|
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');
|
||||||
|
|
||||||
var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type');
|
var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type');
|
||||||
var $extra_query_vars = array();
|
var $extra_query_vars = array();
|
||||||
|
|
|
@ -86,6 +86,20 @@ function is_category ($category = '') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function is_tag( $slug = '' ) {
|
||||||
|
global $wp_query;
|
||||||
|
if ( !$wp_query->is_tag )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if ( empty( $slug ) )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
$cat_obj = $wp_query->get_queried_object();
|
||||||
|
if ( $category == $cat_obj->category_nicename )
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function is_comments_popup () {
|
function is_comments_popup () {
|
||||||
global $wp_query;
|
global $wp_query;
|
||||||
|
|
||||||
|
@ -305,6 +319,7 @@ class WP_Query {
|
||||||
var $is_time = false;
|
var $is_time = false;
|
||||||
var $is_author = false;
|
var $is_author = false;
|
||||||
var $is_category = false;
|
var $is_category = false;
|
||||||
|
var $is_tag = false;
|
||||||
var $is_search = false;
|
var $is_search = false;
|
||||||
var $is_feed = false;
|
var $is_feed = false;
|
||||||
var $is_comment_feed = false;
|
var $is_comment_feed = false;
|
||||||
|
@ -329,6 +344,7 @@ class WP_Query {
|
||||||
$this->is_time = false;
|
$this->is_time = false;
|
||||||
$this->is_author = false;
|
$this->is_author = false;
|
||||||
$this->is_category = false;
|
$this->is_category = false;
|
||||||
|
$this->is_tag = false;
|
||||||
$this->is_search = false;
|
$this->is_search = false;
|
||||||
$this->is_feed = false;
|
$this->is_feed = false;
|
||||||
$this->is_comment_feed = false;
|
$this->is_comment_feed = false;
|
||||||
|
@ -383,6 +399,7 @@ class WP_Query {
|
||||||
, 'year'
|
, 'year'
|
||||||
, 'w'
|
, 'w'
|
||||||
, 'category_name'
|
, 'category_name'
|
||||||
|
, 'tag'
|
||||||
, 'author_name'
|
, 'author_name'
|
||||||
, 'feed'
|
, 'feed'
|
||||||
, 'tb'
|
, 'tb'
|
||||||
|
@ -531,6 +548,9 @@ class WP_Query {
|
||||||
$this->is_category = true;
|
$this->is_category = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( '' != $qv['tag'] )
|
||||||
|
$this->is_tag = true;
|
||||||
|
|
||||||
if ( empty($qv['author']) || ($qv['author'] == '0') ) {
|
if ( empty($qv['author']) || ($qv['author'] == '0') ) {
|
||||||
$this->is_author = false;
|
$this->is_author = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -541,7 +561,7 @@ class WP_Query {
|
||||||
$this->is_author = true;
|
$this->is_author = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ($this->is_date || $this->is_author || $this->is_category) )
|
if ( ($this->is_date || $this->is_author || $this->is_category || $this->is_tag ) )
|
||||||
$this->is_archive = true;
|
$this->is_archive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -837,7 +857,7 @@ class WP_Query {
|
||||||
$in_cats = substr($in_cats, 0, -2);
|
$in_cats = substr($in_cats, 0, -2);
|
||||||
$out_cats = substr($out_cats, 0, -2);
|
$out_cats = substr($out_cats, 0, -2);
|
||||||
if ( strlen($in_cats) > 0 )
|
if ( strlen($in_cats) > 0 )
|
||||||
$in_cats = " AND $wpdb->post2cat.category_id IN ($in_cats)";
|
$in_cats = " AND $wpdb->post2cat.category_id IN ($in_cats) AND rel_type = 'category' ";
|
||||||
if ( strlen($out_cats) > 0 ) {
|
if ( strlen($out_cats) > 0 ) {
|
||||||
$ids = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE $wpdb->post2cat.category_id IN ($out_cats)");
|
$ids = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE $wpdb->post2cat.category_id IN ($out_cats)");
|
||||||
if ( is_array($ids) && count($ids > 0) ) {
|
if ( is_array($ids) && count($ids > 0) ) {
|
||||||
|
@ -854,6 +874,21 @@ class WP_Query {
|
||||||
$groupby = "{$wpdb->posts}.ID";
|
$groupby = "{$wpdb->posts}.ID";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( '' != $q['tag'] ) {
|
||||||
|
$reqcat= get_category_by_slug( $q['tag'] );
|
||||||
|
if ( !empty($reqcat) )
|
||||||
|
$reqcat = $reqcat->cat_ID;
|
||||||
|
else
|
||||||
|
$reqcat = 0;
|
||||||
|
|
||||||
|
$q['cat'] = $reqcat;
|
||||||
|
|
||||||
|
$tables = ", $wpdb->post2cat, $wpdb->categories";
|
||||||
|
$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) ";
|
||||||
|
$whichcat = " AND category_id IN ({$q['cat']}) AND rel_type = 'tag' ";
|
||||||
|
$groupby = "{$wpdb->posts}.ID";
|
||||||
|
}
|
||||||
|
|
||||||
// Category stuff for nice URLs
|
// Category stuff for nice URLs
|
||||||
if ( '' != $q['category_name'] ) {
|
if ( '' != $q['category_name'] ) {
|
||||||
$reqcat = get_category_by_path($q['category_name']);
|
$reqcat = get_category_by_path($q['category_name']);
|
||||||
|
@ -881,13 +916,15 @@ class WP_Query {
|
||||||
|
|
||||||
$tables = ", $wpdb->post2cat, $wpdb->categories";
|
$tables = ", $wpdb->post2cat, $wpdb->categories";
|
||||||
$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) ";
|
$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) ";
|
||||||
$whichcat = " AND category_id IN ({$q['cat']}, ";
|
$whichcat = " AND category_id IN ({$q['cat']} ";
|
||||||
$whichcat .= get_category_children($q['cat'], '', ', ');
|
$whichcat .= get_category_children($q['cat'], '', ', ');
|
||||||
$whichcat = substr($whichcat, 0, -2);
|
$whichcat = substr($whichcat, 0, -2);
|
||||||
$whichcat .= ")";
|
$whichcat .= ") AND rel_type = 'category'";
|
||||||
$groupby = "{$wpdb->posts}.ID";
|
$groupby = "{$wpdb->posts}.ID";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Author/user stuff
|
// Author/user stuff
|
||||||
|
|
||||||
if ( empty($q['author']) || ($q['author'] == '0') ) {
|
if ( empty($q['author']) || ($q['author'] == '0') ) {
|
||||||
|
|
|
@ -35,6 +35,9 @@ if ( defined('WP_USE_THEMES') && constant('WP_USE_THEMES') ) {
|
||||||
} else if ( is_category() && $template = get_category_template()) {
|
} else if ( is_category() && $template = get_category_template()) {
|
||||||
include($template);
|
include($template);
|
||||||
return;
|
return;
|
||||||
|
} else if ( is_tag() && $template = get_tag_template()) {
|
||||||
|
include($template);
|
||||||
|
return;
|
||||||
} else if ( is_author() && $template = get_author_template() ) {
|
} else if ( is_author() && $template = get_author_template() ) {
|
||||||
include($template);
|
include($template);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -328,6 +328,17 @@ function get_category_template() {
|
||||||
return apply_filters('category_template', $template);
|
return apply_filters('category_template', $template);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_tag_template() {
|
||||||
|
$template = '';
|
||||||
|
if ( file_exists(TEMPLATEPATH . "/tag-" . get_query_var('tag') . '.php') )
|
||||||
|
$template = TEMPLATEPATH . "/tag-" . get_query_var('tag') . '.php';
|
||||||
|
elseif ( file_exists(TEMPLATEPATH . "/tag.php") )
|
||||||
|
$template = TEMPLATEPATH . "/tag.php";
|
||||||
|
|
||||||
|
return apply_filters('tag_template', $template);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function get_date_template() {
|
function get_date_template() {
|
||||||
return get_query_template('date');
|
return get_query_template('date');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue