Make WordPress Core

Opened 21 years ago

Closed 18 years ago

#1969 closed defect (bug) (fixed)

Check for category and author page existence

Reported by: chuyskywalker's profile chuyskywalker Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.0
Component: General Keywords: needs-patch
Focuses: Cc:

Description

If you create a category, and then try to access it before there are any posts in it, Wordpress will return you the 404.php page instead of the category.php.

I would have assumed that you'd get a category.php with no posts on it -- the category *does* exist, it's just empty.

Attachments (2)

is_category.diff (1.0 KB) - added by chuyskywalker 21 years ago.
fixes said category/404 bug
is_category-better.diff (877 bytes) - added by chuyskywalker 21 years ago.
whoops, added a bit exta to that last one…

Download all attachments as: .zip

Change History (14)

@chuyskywalker
21 years ago

fixes said category/404 bug

@chuyskywalker
21 years ago

whoops, added a bit exta to that last one...

#1 @chuyskywalker
21 years ago

  • Cc bg|has-patch added

... and then, like lightening, it strikes and I find the culprit.

#2 @davidhouse
21 years ago

  • Cc bg|has-patch removed
  • Keywords bg|has-patch added

Tags go in the Keywords field, not the CC field. :)

#3 @chuyskywalker
21 years ago

hehe, what a noob :) Thanks! (That's what I get for submitting patches at 2am...)

#4 @matt
21 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [3215]) Don't show 404s for empty cats, fixes #1969

#5 @joelgilmore
20 years ago

  • Milestone changed from 2.0 to 2.1
  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Summary changed from Empty categories return 404 instead of using archive.php to Check for category and author page existence
  • Version changed from 1.6 to 2.0.1

I think a better modification, which I can't see that this does, is to check whether the category (or author page) exists, and if so, go to it even if it has no posts.

The appropriate code would be

	if (is_author() || is_category()){
		if ((!$wp_query->get_queried_object()) && !is_404() && !is_search() && ( $this->did_permalink || (!empty($_SERVER['QUERY_STRING']) && (false === strpos($_SERVER['REQUEST_URI'], '?'))) ) ) {
				$wp_query->set_404();
				status_header( 404 );
		}	elseif( is_404() != true ) {
			status_header( 200 );
		}
	} else { // If not in an author or category page
		if ( (0 == count($wp_query->posts)) && !is_404() && !is_search() && ( $this->did_permalink || (!empty($_SERVER['QUERY_STRING']) && (false === strpos($_SERVER['REQUEST_URI'], '?'))) ) ) {
				$wp_query->set_404();
				status_header( 404 );
		}	elseif( is_404() != true ) {
				status_header( 200 );
		}
	}// End author/cat select

This works very well on my <a href="http://www.dividingline.org/>site</a>, and also applies to author pages, since I display information about Subscribers as well as Contributors et al.

#6 @_ck_
20 years ago

What is really strange is that for a user/author with no posts:

/index.php?author_name=example
works and will show author.php template even with zero posts

/author/example
will FAIL (even in 2.1a2) and show 404 template
until they have at least one post and then it will work

I believe it has to do with the way WP_QUERY in query.php parses the URL and first believes it's on a page with posts for the rewrite URL so it fails for the author. Very strange.

The 404 patch code by joelgilmore works but I dislike the idea of patching the result. I wish they could fix it on the parsing. 2.1a2 still does not have any attempt to fix what-so-ever.

#7 @matt
20 years ago

  • Milestone changed from 2.1 to 2.2

#8 @foolswisdom
19 years ago

  • Keywords has-patch added; bg|has-patch removed
  • Milestone changed from 2.2 to 2.3

#9 @westi
19 years ago

  • Keywords needs-patch added; has-patch removed

This needs-patch for the remaining issue - "empty author's"

Marking at such.

#10 @ryan
19 years ago

  • Milestone changed from 2.3 to 2.4 (next)

#11 @JDTrower
18 years ago

A patch that fixes tickets #3345 and #1969 has been posted on #3345. It needs testing, however it fixes the problems mentioned in this ticket.

#12 @Nazgul
18 years ago

  • Milestone 2.5 deleted
  • Resolution set to fixed
  • Status changed from reopened to closed
  • Version changed from 2.0.1 to 2.0

Reclosing as fixed, as the remaining issue is being adressed in #3345.

Note: See TracTickets for help on using tickets.