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
Related
I'm working on a Wordpress site where I'm using the posts to create a list of tour dates for an entertainer. With ACF I have fields set up in a table and the client just enters a date, location, link to buy tickets, etc.
The table is all I need visitors to see. The actual post created by single.php is not going to be styled and should never be seen.
I want to prevent someone searching the artist and city and coming across the post.
Is there a plugin or a disallow I can put in the robot.txt file?
Any help is appreciated. Kinda funny in a time where everyone is trying to get noticed by search engines and I want to hide something from them!
Add the code below to your themes functions.php:
add_action('wp_head', 'your_prefix_noindex_nofollow');
function your_prefix_noindex_nofollow() {
if(is_single()){
echo '<meta name="robots" content="noindex,nofollow"/>';
}
}
You can also change "your_prefix" in the function name to whatever you like. It will work as is, but it's a good practice to use the same prefix in all your function names.
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
}
This should be a simple thing, however I am at a loss at calling on this meta information. I want to apply custom css to posts marked as featured, specifically I want a css stamp on the corner. I have that part good, but I can't apply the class.
http://wordpress.org/plugins/featured-item-metabox/
I tried this plug in, and it works well. I am able to pull a page with all of the articles I have set us featured but I can't for the life of me figure out how to pull the information to echo it as a class.
I've tried lots of things, this is the closest I've come to success I think:
<div class="featured"><?php echo get_post_custom_keys($post_id, '_featured'); ?></div>
Here I'm trying to just echo the contents so I can see what it is outputting, makes it easier to troubleshoot.
This seems like something that is basic but I'm at a loss. How should I call the custom meta key?
You should try with get_post_meta()
(http://codex.wordpress.org/Function_Reference/get_post_meta)
$all_meta = get_post_meta($post_id)
//dump($all_meta)
and check if your post has featured value.
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
I to allow my users to sort the list of wordpress posts by Title, Date added, Comments, Rating etc. These will all be buttons or links at the top of the list (kinda like table view sorting)
However, I have no PHP experience and only know a few basics. How would I achieve this? I currently use the following line to sort my posts by name ASC:
<?php query_posts( $query_string . "&orderby=title&order=ASC" ); ?>
I was personally thinking of the following solution: orderby=VARIABLE1&order=VARIABLE2
Where VARIABLE1 would be set to title by default and VARIABLE2 would be set ASC by default. However I don't know if this is the best solution, and I know even less on how to achieve this.
Thanks for any future help!
Swen, attach ?orderby=title or ?orderby=date to the URLs of your buttons, WordPress will do the ordering itself.
One of the easiest way is just to use the Post Types Order plugin