مرسی نوید جان بخاطر سر ِ نخ
اینم ته نخ:
البته هنوز توی قالب وبلاگم جاش ننداختم ولی فکر می کنم همه اونچیزایی که برای دو زبانه کردن وبلاگ لازم باشه رو می شه ازش کشید بیرون.
بد نیست قالب استاندارد رو با این امکان دوباره بسازیم تا همه از وبلاگی دو زبانه کام جویند!
Solution:
Step One. Create two copies of the default single.php file. Give these two new files identifiable names, eg. single-general.php and single-reviews.php.
Step Two: Open the original default single.php file in your text editor (eg. Notepad). Delete all the code within this file and replace it with the following, then save and close the file.
$post = $wp_query->post;
if ( in_category('2') ) {
include(TEMPLATEPATH . '/single-reviews.php');
} else {
include(TEMPLATEPATH . '/single-general.php');
}
?>
What does this code do? Here's a dodgy plain english overview.
$post = $wp_query->post
When a user opens (or requests) a post, Wordpress takes a look at it, and runs a query on it (to see what it is).
if ( in_category('2') ) {
include(TEMPLATEPATH . '/single-reviews.php');
This starts the 'if' statement, and says 'if the post that has been queried is from the category with the ID '2' then use the single-reviews.php template. Obviously you'd create a 'Reviews' category in WordPress and use the 'Reviews' categories ID number. You can find the ID number by logging into your Dashboard and the selecting Manage > Categories then find the ID for the relevant category. For the sake of this exercise assume that the 'Reviews' category ID is '2'.
} else {
include(TEMPLATEPATH . '/single-general.php');
}
This section of code says that if the post is not from the category with the ID '2' then use the single-general.php template instead.
So that's pretty much all the code explained. The whole thing uses a simple 'if/else' statement. An 'if/else' statement works by testing a condition. If the condition is satisfied it does the 'if' section, if it's not satisfied it does the 'else' section of the code. In other words, you could read it as, "if I'm hungry, have lunch, else carry on as normal".
Step Three.
Style and layout your two new files, single-general.php and single-reviews.php, however you like. Now if everything has gone to plan you should be able to display posts from a specific category differently to posts from every other category
.