How to create two single.php in Wordpress? - wordpress

I want to create two single.php templates, one for English language and the other one for Persian language, because post in English is too different according the post in Persian, because of the css direction need.
For this propose I've created two single.php templates, but everytime the English one opens.
Now, how do I send the post to the other one which is Persian single.php.

I think you have to make two categories first. Sorry my English is very bad, if my answer is a little bit understandable (:D).
Create 3 files for the single page: single.php, singleEnglish.php, singlePersian.php, then add this code in single.php:
<?php
$post = $wp_query->post;
if (in_category('tag_id Persian') ) {include(TEMPLATEPATH . '/singlePersian.php');}
else {include(TEMPLATEPATH . '/singleEnglish.php');
}?>
Example can be found here. Single page is different for Products and Blog.

You can't run two single.php for the same post type. The template hierarchy doesn't allow that.
You need to look into rtl support for your site. It is extensively covered in the codex. You can also have a look at the bundled themes to get a basic idea of how to do this.
The other means might be is to use get_locale() to split you single.php
Example: (Please note, I'm using Afrikaans as the locale to check, change this to Persian)
if( 'af_AF' == get_locale()){
// Do something for Afrikaans language
}else{
// Do something else for other languages
}

Related

if condition for single.php at wordpress

Since I have a blog in blogger(it is a images blog), so I recently moved to wordpress.
After importing all posts from blogger to wordpress it is showing post thumbnail image in single post along with the post original image. So I changed the template. It good working for all imported posts.
But I posted many posts after came to wordpress using a plugin for bulk posting. That template showing thumbnail images in main page , category page etc.. But in single post it is not showing original image.
So I changed template again. Now the images are not showing in imported posts (single post).
So I decided to show separate single.php codes for each category.
So what I need is:
I gathers these 2 codes.
code 1:- (single.php of 1st template)
code 2:-(single.php of 2nd template)
Here I am copying these 2 codes.
In a template single.php code(what ever the template may be) I like to write if condition to solve my problem. I will tell you algorithm but please write the if condition code please. ............
Algorithm:
if( categeory_id=14 or 15 or 16 or 17)
Code 1 here.
else
code 2 here.
Thanks to all developers. If it is not possible please suggest me a good gallery theme.
Thanks in advance.
This should work:
<?php if (is_category( array( 14,15,16,17 ) ))
{
//Code here
}
else
{
//other code
}
?>
In the array put the id of the category. If a category isn't in that array then it will run the other code.

Wordpress: How to pass additional Content to the blog-preview page?

For each blog-post on my wordpress-blog I'd like to have Teaxtarea where i can pass additional content for that post.
In my case that would be an unordered list which contains a quick overview of the content.
That additional content should be displayed in the preview of the post on the blog-preview-page.
My problem:
I am actually not sure on how to best add this additional content and then pass it to the preview.
Do I use wordpress' custom fields for something like this?
I'm gratefull for a push in the right direction.
Thank you,
Nils
If I understand you right, I'd take a look at "custom meta boxes" functionality - it allows you to add any type of additional input into your blog post admin area, and than display its content on front-end however you like.
There's a nice tutorial series on that topic, with example code snippets:
http://wp.tutsplus.com/series/reusable-custom-meta-boxes/
And if you'd like to display the textarea content only in preview mode, you can use appropriate conditional tag in you template file:
http://codex.wordpress.org/Conditional_Tags#A_Preview
The conditional tag is_preview returns true when a single post is viewed in Draft mode. The following will append post meta to the content when a post is being previewed:
function so16799607_preview( $content )
{
if ( ! is_preview() )
return $content;
return $content . get_post_meta( get_the_ID(), 'my_post_meta', true );
}
add_filter( 'the_content', 'so16799607_preview', 10, 1 );
You should check out Advanced Custom Fields. That's a really stable plugin that lets you create custom meta boxes in posts, pages and custom post types. That plugin does exactly what your question states. Need al little PHP to get stuff from your database, but that is as easy as:
<?php the_field(field_name);?>
And the documentation is pretty good. And if you don't like a plugin, it exports the PHP as well.
Anther tool that does the same is Pods Framework. Both powerfull extensions to any WP install in my opinion.
Hope this helps.

Alternatively presentation of the archive

I'm searching for an alternativ view of the archiv output page.
So if you click on a archiv link you get a view e.g. of the Month.
And exactly this Page where i get the filtered output i want to apply some changes.
So i mean not:
wp_get_archives()
Best regards Illu
If you just want to make a few small changes, then just filter it with the wordpress function is_archive(), e.g.
<?php if (is_archive()) { ?>
Say hello to the archeologist users
<?php } ?>
...otherwise, if you want to have a completly different template for that page, then just create a file called archive.php in your theme directory. Hope I understood your question right :)
Some more resources for the is_archive() function is to be found here - well explained examples. And some more information about template files are here

Wordpress: apply_filters & add_action to the_content = EVIL?

I asked this question over in the actual tutorial, but not sure I'll get an answer anytime soon as it's almost 2 months old... so I'll take a gander here...
Tutorial is here: Build a WordPress Plugin to Add Author Biographies to your Posts
To sum up the tutorial and what the problem is, The tutorial adds an Author Bio on to the end of the content like so (the short version):
function x($content) {
return $content . "Author Bio";
}
add_action('the_content','x');
The Problem:
When someone uses:
$z = apply_filters('the_content', 'some content here');
echo $z;
The Author Bio will end up applied to $z and if $z is echoed out in the middle of some page… the Author Bio would be in the middle of some page… correct? (it's correct because I've tested it...)
Is there a better way to apply something to the end/under/below the_content hook? other than add_action(‘the_content’, ‘some_function’) because this to me seems evil...
or is apply_filters(‘the_content’, ‘some content here’) not the norm or something developers shouldn't be using inside their WordPress templates…? (which seems pretty much the norm, at least upon Google-ing formatting "the_content" outside the loop)...
Using apply_filters('the_content','some content here'), while it may not be 'the norm' (I don't know. I haven't seen it before, but if I needed formatted text, that's what I'd do), is a perfectly valid use of filters to get some text formatted like the content. Unfortunately, there's no better way to append something to content from a plugin. That is just the way these things work.
However, there's a (less than optimal) way of circumventing this. As part of the setup/install process for your plugin, have the user insert a custom function call, action, or filter into their theme. I know several plugins that do this, so it's not all that uncommon. Something like this:
do_action('my_super_awesome_bio_hook');
Would allow you to hook in without worrying about adding a bio to unexpected (and unintended) content. Even better would be inserting a filter:
echo apply_filters('my_super_awesome_bio_filter_hook','');
That would allow your plugin to modify the bio, but also allow the one using the plugin to override it if necessary (like on pages where they're just using excerpts, like search results, etc.).
Hope this helped.
Also, one minor addendum: you should be using add_filter, not add_action to append the Author Bio. add_action still works, but it's a filter you want to be using.
I bumped into a similar issue with a widget I'm dev'ing. I just found this:
http://codex.wordpress.org/Function_Reference/wpautop
Which I'm now going to use instead of add_filters('the_content'). I want the WYSIWYG formatting but I don't want things append to my content because it's not traditional content anymore.

Only date certain articles on WordPress?

I'm setting up a WordPress installation where I want some of the articles to show the date they were posted, and other articles to leave the date out. I'd like these articles to be completely dateless, if possible, so they only show in category archives and not in date archives.
I'm guessing I can tweak the templates to show the date or not based on the article's category, I was wondering if there was an easier solution to this?
Or should I start writing my own plugin to do this?
I've not got anything online at the moment, this is just an idea I'm churning over in my head for now.
Cheers,
Dan
Your theory of how to do it (have the theme files make a check for the category, then either display the date or not) is correct.
I think this code should do it:
<?php
if (is_category('CategoryThatDisplaysDates')) {
echo '<p>Date posted: '; the_date(); echo '</p>';
};
?>
If you don't want to mess up your categories (having “CategoryThatDisplaysDates” in a category listing looks a bit weird), you could try custom fields (meta-data). You add a custom field, e.g. display-date, in the write post panel and set its content to true.
Then, use ahockley's code, just change if(is_category(...)) to
if(get_post_meta($post->ID, 'display-date', true) == 'true')
i'd go with a custom field. you can read about using custom fields here: http://codex.wordpress.org/Using_Custom_Fields

Resources