Handling Nonexistent Parent Directories #27

Open
splorp opened this Issue Dec 11, 2011 · 27 comments

Comments

Projects
None yet
2 participants
@splorp
Owner

splorp commented Dec 11, 2011

I’ve been thinking about what we could do to automatically (and cleanly) handle parent directories that do not exist by default.

For example, the contents of a given category are available at a URL such as:

http://splorp.me/category/getoffmylawn

But there is no page designated for the parent directory:

http://splorp.me/category/

It would make sense to provide a “category” landing page of some sort, even if it simply echoes a restyled version of the wp_list_categories() function used in the sidebar.

Along with the /category/ subdirectory, we should handle /tag/ and /date/ as well.

cdharrison added a commit that referenced this issue Dec 22, 2011

@cdharrison

This comment has been minimized.

Show comment
Hide comment
@cdharrison

cdharrison Dec 22, 2011

Collaborator

Just committed a category.php and tag.php file to the theme that should address this. In trying to avoid adding classes to the h1 and category/tag description for these templates, I used some adjacent selectors in layout-advanced.css that may not work in IE6.

Live preview of these changes:

Collaborator

cdharrison commented Dec 22, 2011

Just committed a category.php and tag.php file to the theme that should address this. In trying to avoid adding classes to the h1 and category/tag description for these templates, I used some adjacent selectors in layout-advanced.css that may not work in IE6.

Live preview of these changes:

@cdharrison

This comment has been minimized.

Show comment
Hide comment
@cdharrison

cdharrison Dec 22, 2011

Collaborator

Date-based archives are handled by archive.php. If what I've done for categories and tags works for you, I can update archive.php to match it better...

Collaborator

cdharrison commented Dec 22, 2011

Date-based archives are handled by archive.php. If what I've done for categories and tags works for you, I can update archive.php to match it better...

@cdharrison

This comment has been minimized.

Show comment
Hide comment
@cdharrison

cdharrison Dec 22, 2011

Collaborator

Re-reading the issue, I think I misunderstood the request. If the parent category is empty, you want a list of children posted, correct?

Collaborator

cdharrison commented Dec 22, 2011

Re-reading the issue, I think I misunderstood the request. If the parent category is empty, you want a list of children posted, correct?

@splorp

This comment has been minimized.

Show comment
Hide comment
@splorp

splorp Dec 22, 2011

Owner

Short answer, yes.

Owner

splorp commented Dec 22, 2011

Short answer, yes.

@cdharrison

This comment has been minimized.

Show comment
Hide comment
@cdharrison

cdharrison Dec 22, 2011

Collaborator

Rough, but work in progress: http://cdharrison.com/stuff/design/ - list of child categories is displayed below content. (Placement can be modified, obviously.) Will need to look into this further but it looks like by default parent categories are never empty if their child categories have posts assigned to them.

Case in point:

http://cdharrison.com/stuff/quotes/

Has no posts directly assigned to it. The post displayed actually belongs to a child category:

http://cdharrison.com/stuff/quotes/faith

We could exclude children from the parent pages, but it would run counter to what WP does by default.

Collaborator

cdharrison commented Dec 22, 2011

Rough, but work in progress: http://cdharrison.com/stuff/design/ - list of child categories is displayed below content. (Placement can be modified, obviously.) Will need to look into this further but it looks like by default parent categories are never empty if their child categories have posts assigned to them.

Case in point:

http://cdharrison.com/stuff/quotes/

Has no posts directly assigned to it. The post displayed actually belongs to a child category:

http://cdharrison.com/stuff/quotes/faith

We could exclude children from the parent pages, but it would run counter to what WP does by default.

@splorp

This comment has been minimized.

Show comment
Hide comment
@splorp

splorp Dec 23, 2011

Owner

It’s a great start.

The list of child categories feels like it should only appear once on the page. Specifically, in relation to the parent category name and description at the top of the page.

Owner

splorp commented Dec 23, 2011

It’s a great start.

The list of child categories feels like it should only appear once on the page. Specifically, in relation to the parent category name and description at the top of the page.

@cdharrison

This comment has been minimized.

Show comment
Hide comment
@cdharrison

cdharrison Dec 23, 2011

Collaborator

Just committed an update that should improve display considerably on Advanced. Check it out when you get a chance.

Collaborator

cdharrison commented Dec 23, 2011

Just committed an update that should improve display considerably on Advanced. Check it out when you get a chance.

@splorp

This comment has been minimized.

Show comment
Hide comment
@splorp

splorp Dec 28, 2011

Owner

I’ve found a bug with the current category views.

Pagination is missing, so the page only displays the first ten posts in the category. I haven’t tested tag archives, as I don’t currently use tags on any of my posts.

Owner

splorp commented Dec 28, 2011

I’ve found a bug with the current category views.

Pagination is missing, so the page only displays the first ten posts in the category. I haven’t tested tag archives, as I don’t currently use tags on any of my posts.

@cdharrison

This comment has been minimized.

Show comment
Hide comment
Collaborator

cdharrison commented Dec 28, 2011

@splorp

This comment has been minimized.

Show comment
Hide comment
@splorp

splorp Dec 28, 2011

Owner

Rawk.

Owner

splorp commented Dec 28, 2011

Rawk.

@splorp

This comment has been minimized.

Show comment
Hide comment
@splorp

splorp Dec 31, 2011

Owner

I’ve tidied up the look and feel to more closely match the other page views.

The only thing that’s still missing is a handler for the /category/ and /tag/ virtual subdirectories. They still 404 by default.

Owner

splorp commented Dec 31, 2011

I’ve tidied up the look and feel to more closely match the other page views.

The only thing that’s still missing is a handler for the /category/ and /tag/ virtual subdirectories. They still 404 by default.

@cdharrison

This comment has been minimized.

Show comment
Hide comment
@cdharrison

cdharrison Dec 31, 2011

Collaborator

Ah, now I understand. I'll see what I can do to fix.

Collaborator

cdharrison commented Dec 31, 2011

Ah, now I understand. I'll see what I can do to fix.

@cdharrison

This comment has been minimized.

Show comment
Hide comment
@cdharrison

cdharrison Jan 3, 2012

Collaborator

After a bit of research on this, the only way it would be able to do this is by creating a custom template and then assigning that template to a page with a slug name of category or tag. Going to try and ping a few WordPress devs for their thoughts on the matter.

Collaborator

cdharrison commented Jan 3, 2012

After a bit of research on this, the only way it would be able to do this is by creating a custom template and then assigning that template to a page with a slug name of category or tag. Going to try and ping a few WordPress devs for their thoughts on the matter.

@cdharrison

This comment has been minimized.

Show comment
Hide comment
@splorp

This comment has been minimized.

Show comment
Hide comment
@splorp

splorp Jan 5, 2012

Owner

Hrm. And where do custom rules get defined? In functions.php?

I have to admit that it’s all a bit over my phpn00b head at this point.

Owner

splorp commented Jan 5, 2012

Hrm. And where do custom rules get defined? In functions.php?

I have to admit that it’s all a bit over my phpn00b head at this point.

@cdharrison

This comment has been minimized.

Show comment
Hide comment
@cdharrison

cdharrison Jan 5, 2012

Collaborator

Good question. Probed a bit deeper and another developer suggested the following:

You could check to see if the page exists and if not, create it (and setting the page template). I think that's a better solution than touching rewrite rules to make something other than a page show up there. A warning that get_page_by_path() lacks caching which most blogs don't have anyway, so make your exists check smart.

I'm a bit lost, too. Still pursuing.

Collaborator

cdharrison commented Jan 5, 2012

Good question. Probed a bit deeper and another developer suggested the following:

You could check to see if the page exists and if not, create it (and setting the page template). I think that's a better solution than touching rewrite rules to make something other than a page show up there. A warning that get_page_by_path() lacks caching which most blogs don't have anyway, so make your exists check smart.

I'm a bit lost, too. Still pursuing.

@cdharrison

This comment has been minimized.

Show comment
Hide comment
@cdharrison

cdharrison Jan 5, 2012

Collaborator

But yeah, I believe if we went the first route, they'd likely go in functions.php and likely need to be able to write to the .htaccess file of the site...

Collaborator

cdharrison commented Jan 5, 2012

But yeah, I believe if we went the first route, they'd likely go in functions.php and likely need to be able to write to the .htaccess file of the site...

@splorp

This comment has been minimized.

Show comment
Hide comment
@splorp

splorp Jan 5, 2012

Owner

Here’s a thought.

Since hitting /category/ or /tag/ results in a 404, could we not add some logic to 404.php to display content based on the current URI?

Owner

splorp commented Jan 5, 2012

Here’s a thought.

Since hitting /category/ or /tag/ results in a 404, could we not add some logic to 404.php to display content based on the current URI?

@cdharrison

This comment has been minimized.

Show comment
Hide comment
@cdharrison

cdharrison Jan 5, 2012

Collaborator

Check out http://cdharrison.com/category/ Latest commit uses 404.php to do what you suggested. Not having luck getting it to work with tag_base :(

Collaborator

cdharrison commented Jan 5, 2012

Check out http://cdharrison.com/category/ Latest commit uses 404.php to do what you suggested. Not having luck getting it to work with tag_base :(

@cdharrison

This comment has been minimized.

Show comment
Hide comment
@cdharrison

cdharrison Jan 5, 2012

Collaborator

$category_base grabs whatever the user has set. Default is category/ but this worked for me when I changed mine to /topics

Will investigate $tag_base further. My issues may be cache-related.

Collaborator

cdharrison commented Jan 5, 2012

$category_base grabs whatever the user has set. Default is category/ but this worked for me when I changed mine to /topics

Will investigate $tag_base further. My issues may be cache-related.

@splorp

This comment has been minimized.

Show comment
Hide comment
@splorp

splorp Jan 5, 2012

Owner

WordPress might also be smart redirecting to a post that uses “tag” as part of the post slug.

Note how:

http://cdharrison.com/tag/

Redirects to:

http://cdharrison.com/2006/12/14/tag-im-it/

And:

http://cdharrison.com/tags/

Redirects to:

http://cdharrison.com/2007/09/05/tags-in-wordpress-23/

Owner

splorp commented Jan 5, 2012

WordPress might also be smart redirecting to a post that uses “tag” as part of the post slug.

Note how:

http://cdharrison.com/tag/

Redirects to:

http://cdharrison.com/2006/12/14/tag-im-it/

And:

http://cdharrison.com/tags/

Redirects to:

http://cdharrison.com/2007/09/05/tags-in-wordpress-23/

@cdharrison

This comment has been minimized.

Show comment
Hide comment
@cdharrison

cdharrison Jan 5, 2012

Collaborator

I disabled all content that mentions ‘tags’, now http://cdharrison.com/tags/ works. Only problem is WordPress doesn’t seem to make any differentiation between tags and categories. (Not sure why.) Workaround would be to simply have both types of archives listed. Work for you?

This will likely break for /tags/ if I re-enable the posts that have the word in the title.

Collaborator

cdharrison commented Jan 5, 2012

I disabled all content that mentions ‘tags’, now http://cdharrison.com/tags/ works. Only problem is WordPress doesn’t seem to make any differentiation between tags and categories. (Not sure why.) Workaround would be to simply have both types of archives listed. Work for you?

This will likely break for /tags/ if I re-enable the posts that have the word in the title.

@splorp

This comment has been minimized.

Show comment
Hide comment
@splorp

splorp Jan 7, 2012

Owner

I wonder if if including ‘category’ at the beginning of a post title would break it as well?

I’ll have to test that.

Owner

splorp commented Jan 7, 2012

I wonder if if including ‘category’ at the beginning of a post title would break it as well?

I’ll have to test that.

@cdharrison

This comment has been minimized.

Show comment
Hide comment
@cdharrison

cdharrison Jan 7, 2012

Collaborator

The likelihood is very high. :/

Collaborator

cdharrison commented Jan 7, 2012

The likelihood is very high. :/

@splorp

This comment has been minimized.

Show comment
Hide comment
@splorp

splorp Jan 8, 2012

Owner

Confirmed.

If the post slug starts with ‘category’ then the request gets redirected to the post.

Owner

splorp commented Jan 8, 2012

Confirmed.

If the post slug starts with ‘category’ then the request gets redirected to the post.

@splorp

This comment has been minimized.

Show comment
Hide comment
@splorp

splorp Jan 22, 2012

Owner

I was noodling around with this again today.

It seemed that every 404 was resulting in the category list and tag cloud appearing.

It turns out that unless you specifically set a custom category or tag base directory in the Permalink Settings, the globals return null. I’ve added some logic to check whether category_base or tag_base have been set and am now comparing them to $_SERVER['REQUEST_URI'] instead of dirname().

Now if you hit /category/ (or whatever your happen to have set as the base category directory), only the category list is displayed. Likewise, if you hit /tag/ (or the equivalent base directory), just the tag cloud is displayed.

Every other non-existing page request shows the standard 404 messaging.

Owner

splorp commented Jan 22, 2012

I was noodling around with this again today.

It seemed that every 404 was resulting in the category list and tag cloud appearing.

It turns out that unless you specifically set a custom category or tag base directory in the Permalink Settings, the globals return null. I’ve added some logic to check whether category_base or tag_base have been set and am now comparing them to $_SERVER['REQUEST_URI'] instead of dirname().

Now if you hit /category/ (or whatever your happen to have set as the base category directory), only the category list is displayed. Likewise, if you hit /tag/ (or the equivalent base directory), just the tag cloud is displayed.

Every other non-existing page request shows the standard 404 messaging.

@cdharrison

This comment has been minimized.

Show comment
Hide comment
@cdharrison

cdharrison Jan 22, 2012

Collaborator

I love you man.

Collaborator

cdharrison commented Jan 22, 2012

I love you man.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment