Tìm Hiểu về Wordpress - part 5 - Pdf 16

27
2.3.2 HTAccess
The full name for this file is literally “.htaccess”. It begins with a period and has
no file extension. Weird, we know. Some operating systems treat files like this
differently. For example, in Mac OS X, files that begin with a period are “hidden”
from view. A default download of WordPress does not include this file. Yet, it is
this file and its contents which make all special permalink handling possible in
WordPress.
The .htaccess file should exist at the root directory of your WordPress install, but
don’t run off and create one just yet. In many server environments, WordPress can
do this automatically for you, which is the best way to go (less error-prone). Simply
go into your Settings > Permalinks area and choose any setting other than the
default and click “Save Changes.” If you received the following response message,
you are all set:
Permalink structure updated.
This means WordPress was able to create the .htaccess file and add to it the
proper code. If you did not get this message, you will instead get a box of code
Short URLs
A “short URL” is just like it sounds, a URL with
very few characters. These have become popular
because of services like Twitter which have a
strict 140-character limit on messages, including
URLs. Services like Bit.ly can create these for you
and they look like this: http://bit.ly/11q4xv
There is always controversy with short URLs,
despite their obvious usefulness. The URLs
themselves provide no useful information to
users. Worse, if the service were to close, there
would be a ton of non-resolving URLs out in
the wild. As such, rolling your own short URLs is
getting more and more popular.

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
2.3.3 Which Style of Permalinks?
WordPress enables you to choose your own permalink structure. Although the
format you pick for your permalinks is largely a matter of personal style, you
should consider carefully the context of your site when making your decision. For
example, Is your site clearly a blog with frequent postings? Perhaps a “/%year%/%mo
nthnum%/%day%/%postname%/” structure is best for you. Let’s say you are planning to
have a site full of record reviews. The date may not matter as much, so picking a
structure more like “/%category%/%postname%/” makes more sense. Planning on very
few posts with “timeless” content? Maybe “/%postname%/” is sufficient all by itself.
Examples of dierent permalink structures
On digwp.com, we use a URL structure with partially dated permalinks:
http://digwp.com/2009/01/redirect-category-search-and-tag-urls/
Obscure Bug
If you use %category%
to start your permalinks,
pagination of those actual
category pages may not work
correctly. There is a plugin x:
http://digwp.com/u/33
%postname% woes
Using ONLY the postname
in the permalink structure
apparently has some
performance issues:

enter the post title in the post-editing screen. There, you can change the post slug
Optimizing Permalinks
For more information on how
to create and optimize your
site’s permalinks, check out
Chapter 8.3.1, Optimizing
Permalink Structure and also
this comprehensive overview on
our own blog:
http://digwp.com/u/461
Cool URLs Don’t Change
Don’t believe us? Here it is
straight from the horse’s mouth:
http://digwp.com/u/383
Old Slugs
There are plugins out there
that help handle redirecting old
links to new links should the
slug of the page change or the
permalink structure change.
That's awesome, but just not
changing links is even better.
30
to anything you would like, but remember to avoid any strange characters. Stick
with lowercase letters, numbers, and dashes or underscores. Here is a much better
“slug” for our example:
Good: http://gizzards.com/how-to-cook-a-gizzard
Bad: http://bad-jokes.com/really-dumb-jokes/10/2008/your-momma-is-so-fat-she-
sat-on-a-dollar-and-made-four-quarters
But hey, even at its worst, WordPress isn’t that bad. It certainly could be worse.

mother is very good looking.
31
plan early on, just to help make sure things don’t get out of
hand later on.
In addition to categories, each post may also be assigned any
number of Tags. Tags are used to further categorize content at a
more specific level. A real world example will serve us well here,
so let’s take a look at a Post on the DigWP.com website:
Title: Custom WordPress Title Tags
As you may have guessed, the content of this post is about
how to create great titles in WordPress (see section 3.3.4). You
might think we’d categorize this as “WordPress,” but in fact our
entire site is about WordPress so that would be quite pointless.
Instead, we have categorized this post as “PHP,” since it
specifically deals with PHP functions to accomplish what we are
writing about. “PHP” is the primary subject of this article, hence
its designated category, but it isn’t the only subject that the
post talks about. Thus, we specify several Tags to indicate that
content also contains information about “headers,” “titles,”
and “tags.” Indeed, these are the Tags chosen for that article.
If that example is too specific and self-referential, think of the
example of a photograph of a tree. You would categorize this
as “Photograph,” or if your site was all photographs, “Tree.”
You then might tag the photo as “fall,” “leaves,” “sunset,” and
“beautiful” – assuming those things accurately described
the photos.
Remember that the purpose for all of this categorizing
and tagging is ultimately to assist visitors (and yourself) in
navigating your site and what is sure to be a huge amount
of content. The larger your site grows, the more difficult it

from the list of checkboxes. Don’t be fooled though, on a purely functional basis
Categories and Tags have no significant difference. The URLs that point to their
respective archives, however, are slightly different:
http://digwp.com/category/php/
http://digwp.com/tag/header/
Each of these URLs commonly use the same theme file (archive.php) to display a
list or summary of each of their included posts. These URL structures are able to
be customized (go to Settings > Permalinks), but they will by default use the same
archive.php theme file to display the posts that belong to the specific Category or
Tag. The way in which these posts are displayed on the front end depends on the
actual contents of your theme’s archive.php file. We’ll elaborate further on this
concept in the next chapter.
2.4.3 Use Only One Category Per Post
It is generally considered best practice to only categorize each of your Posts with
one category. This will serve you in two ways. First of all it is less confusing for
people browsing your content by category, as they won’t find any cross-over and
potentially confusing situations where they aren’t sure if an article they found in
two places is really the same or not. The other is potential duplicate content issues,
where search engines may find your post in several different places and think you
are trying to game the system by adding lots of similar content all over.
Function Dierences
While it’s true that tags
and categories are largely
interchangeable, there are some
functions which use them in
different ways. For example, it
is easier to exclude a category
from the loop with query_posts
than it is to exclude a tag.
query_posts('cat=-3');

34
2.4.6 You Don’t Need to Use Them At All
Keep in mind that you don’t need to categorize or tag your Posts at all. It is
very common practice and can be very useful, but it is not required. This is a
classic example of considering your audience over the technology. If you think it
would mostly be clutter and doesn’t make sense for your site, just don’t bother
categorizing or tagging at all. You can easily remove any referencing links that
might appear in your themes.
2.4.7 Custom Taxonomies
Remember how we just said categories and tags are basically the same? They
are. They are two different “taxonomies,” that is, ways to classify a post. It is
a somewhat of an advanced technique, but WordPress allows you to create
additional taxonomies for classification purposes.
A perfect example is a site that was built to review movies. Movie reviews are
classifiable in so many ways: by Date, Actors, Genre, Director, Producer, and the
list could go on and on. Categories and Tags alone
are insufficient to create the ideal navigational
structure for this site. What we could do is
create new taxonomies for all these different
classifications. Behaviorally, and interface-wise, they
behave just like tags.
Now take a practical example, a movie review for
“Sleepy Hollow.”
Here is a summary:
Post Title: Review of Sleepy Hollow
Category: Review
Tags: Ichabod Crane, New York, Gothic
Actors: Johnny Depp, Christina Ricci
ACTION!
PopCritics.com is a very

}
add_action('init', 'create_my_taxonomies', 0);
With this code in place, now you’ll see some new tagging boxes
show up to the right of the content box when creating a new Post in the Admin
area. You use them in the exact same way as tags.
What we get now, automatically, are new URLs that go along with our new
taxonomy:
http://mymoviereviews.com/actor/johnny-depp/
http://mymoviereviews.com/actor/christina-ricci/
http://mymoviereviews.com/producer/scott-rudin
NOTE
Custom taxonomies are only
available in WordPress 2.8
and above and signicantly
improved in 2.9 and 3.0
36
http://mymoviereviews.com/producer/adam-schroeder
http://mymoviereviews.com/director/tim-burton/
http://mymoviereviews.com/genre/horror-suspense/
These URLs would use the archive.php file to display all Posts that are tagged in
that way. In order to create a truly cross-referenced system like this (hey, we could
build our own IMDb!) we’ll need to know how to display this custom taxonomy
information in our themes. It’s a little different than using regular tags.
Display a custom taxonomy tag cloud in your theme
If you would like to display a “tag cloud” containing all of the items in a specific,
custom taxonomy, insert the following code anywhere in your theme files:
<?php wp_tag_cloud(array('taxonomy' => 'people', 'number' => 45)); ?>
Remember to edit the “people” term to match the name of the desired taxonomy.
You may also want to edit the “number” parameter, which specifies how many tags
are to be shown. To display all tags from the “people” taxonomy, use “0”.


Nhờ tải bản gốc
Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status