I'm new to drupal but learning quickly. I've got drupal 7 and I'm working on creating a theme based on Zen's starterkit sub-theme. I'm trying to find where I can customize the "Submitted by" line.
The default looks like this:
Submitted by kenny on Sun, 05/13/2012 - 18:33
I'd like to change it so it simply says the date in a nice format (no user name, no time).
Sunday, May 13th, 2012
How and where can I change this?
In your template.php file (of the Zen sub theme), put this.
function mytheme_preprocess_node(&$vars, $hook) {
$vars['submitted'] = date("l, M jS, Y", $vars['created']);
}
If you want to set "Submitted by " and change date formate for specific content type then you can also change your tpl file like
if your content type is "blog"
then create node--blog.tpl.php
<?php if ($display_submitted): ?>
<p class="submitted">
<?php $user = user_load($node->uid); ?>
<?php $username=$user->name; ?>
<?php print t("Written"); ?>
<?php print $username ?>
<time pubdate datetime="<?php print $submitted_pubdate; ?>">
<?php $date = date("d.n.Y", $node->created); ?>
<?php print "<br>".$date; ?>
</time>
</p>
<?php endif; ?>
Related
I have a the code follow to write in functions.php of WordPress theme:
<?php
if(!function_exists('mytheme_entry_meta')){
function mytheme_entry_meta(){
if(!is_page()){
?>
<div class="entry-meta">
<?php printf(__('<span class="author">Posted by %1$s</span>', 'mytheme'), get_the_author()); ?>
<?php printf(__('<span class="date-pulished">at %1$s</span>', 'mytheme'), get_the_date()); ?>
<?php printf(__('<span class="category">in %1$s</span>', 'mytheme'), get_the_category_list(',')); ?>
<?php if(comments_open()){ ?>
<span class="meta-reply">
<?php comments_popup_link(
__('Leave a comment','mytheme'),
__('One comment','mytheme'),
__('% comments','mytheme'),
__('Read all comments','mytheme')
); ?>
</span>
<?php } ?>
</div>
<?php
}
}
}
?>
After I use POEDIT application to translate to Vietnamese language. But POEDIT show
Error: a format specification for argument 1 doesn't exist in 'msgstr'
And position error in % comments. Please see 2 below images:
Image 1: The position show error
The position show error
Image 2: After I click Save button, show message error.
After I click Save button, show message error
First, you translated the string badly and omitted % from the source. Second, your PO file incorrectly marks the string as being php-format while it isn’t, which you have to fix in your code like this:
/* xgettext:no-php-format */
__('% comments','mytheme'),
Can help somebody. I spent several hours to find solution but without results
I tried to display the list of categories on homepage wordpress blog thru following code
<?php $category = Mage::registry('wordpress_category') ?>
<?php if ($category): ?>
<?php echo $category->getId() ?>: <?php echo $category->getName() ?>
<?php endif; ?>
But the method
Mage::registry('wordpress_category')
always return null.
I found that, i should probably be using the Fishpig_Wordpress_Block_Category_View. But i dont know where i should put it.
The following code will retrieve the current category when viewing a category page in your blog:
<?php Mage::registry('wordpress_category') ?>
This is not what you need. To view a list of categories, you could create a custom collection using the following:
<?php $categories = Mage::getResourceModel('wordpress/post_category_collection') ?>
A better way would be to use the category widget block:
<block type="wordpress/sidebar_widget_categories" name="wp.categories" template="wordpress/sidebar/widget/categories.phtml" />
You can create this in PHP using the following code:
<?php echo Mage::getSingleton('core/layout')
->createBlock('wordpress/sidebar_widget_categories')
->setTemplate('wordpress/sidebar/widget/categories.phtml')
->toHtml() ?>
The above code uses the default template, however, feel free to use your own custom template.
I'm using the Drupal views module to create an overview of nodes. In the view i created i configured the Title. But now when the page is rendered the title isn't shown. It is shown in the breadcrumb etc. But not in the grid template, also if i use another template it still doesn't show. Any idea what this can be? I tried looking for it, but my experience with Drupal is very limited.
I checked the drupal_get_title etc. and it is always returning the title, i think something goes wrong in the views module, but i don't know what :s
Kind regards,
Daan
The problem is most likely how you print the page title. If you want it to happen globally, you should print it in the page.tpl.php. Have you inspected the $title variable in the page template? That is what it's usually called.
i idd removed the title from page.tpl.php, but i did this because i thought it should be printed in the views template. When you check views-view-unformatted.tpl.php etc you see this:
<?php if (!empty($title)): ?>
<h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
<div class="<?php print $classes[$id]; ?>">
<?php print $row; ?>
</div>
<?php endforeach; ?>
so i thought $title would print the title, but it is fixed just by adding it in my page.tpl.php
I have an events category which is searchable by a sub-category (by city where the event is being held). I have the 'The Future is Now!' plugin to allow me to publish future dated posts but hoping that I can set up a paginated template that, when a post 'expires' it will no longer show up in the loop/archive.
I'm also wondering if you can filter out these posts from search results as well?
This is my current Events page code if this helps:
<h2>Upcoming Events</h2>
<ul class="posts">
<?php
$limit = get_option('posts_per_page');
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('showposts=' . $limit . '&paged=' . $paged .'&cat=1&order=ASC');
$wp_query->is_archive = true; $wp_query->is_home = false;
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li class="events_ticker" id="post-<?php the_ID(); ?>">
<span class="left">
<h3><?php the_time('F jS, Y') ?></h3>
<p><?php if (strlen($post->post_title) > 25) { echo substr(the_title($before = '', $after = '', FALSE), 0, 25) . '...';} else {the_title();} ?></p>
<?php global $more; $more = 0; the_excerpt(); ?>
<p>Read More</p>
</span>
<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) { the_post_thumbnail(array(143,110), array("class" => "right post_thumbnail")); } ?>
</li>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/content_breaker_wide.png" alt=" breaker" class="content_breaker" />
<?php endwhile; ?>
</ul>
<!-- end events loop -->
<div class="navigation">
<p class="alignleft"><?php next_posts_link('< Next') ?></p>
<p class="alignright"><?php previous_posts_link('Next >') ?></p>
</div>
<?php endif; ?>
I don't think there is an easy parameter to say "all posts until this date", so you should implement the posts_where_paged filter. There, you can check for !(is_archive() || is_search()), because these two can continue as normal. For the other parts, you add a " AND $wpdb->posts.post_date < NOW()" or something like that (but don't use now, since that will hide events that happen later today, and you probably don't want that).
A similar question was asked on the WordPress Answers Stack Exchange site (in private beta until Aug 20 2010, so you can't visit it unless you pre-registered). Joe Hoyle's suggestion there was simple:
If all you are wanting to do is add an
extra date for 'show times', it may be
easier to add a meta box which does
exactly that - using the Publish date
to spoof it could be potentially
problematic, as WordPress will set it
to "future" status whenever it is
updated with a future publish date (I
think), so you will have to be hooking
every time a post is updated to set it
back again. Also, that way you could
reserve "Publish Date" for what it is
intended.
I would probably just use a meta_key,
and a custom meta box. Though it
depends how complex your queries are
that show the posts.
If you set the meta_value as a
timestamp, you can order by the show
time date still, or select before /
after a certain date:
$events = get_posts('post_type=events&meta_key=show_time&meta_value='
. strtotime( '+1 week' ) .
'&meta_compare=<&orderby=meta_value');
Would get all "events" with a showtime
no later then a week from the current
date. Note: The above is untested, but
should work :)
(This answer is community wiki so I don't get rep points for just reposting what Joe said.)
I have the following code: http://pastebin.com/ng99augD
It basically spits out five posts for the five authors I have specified in the query posts in each chunk of code and then rewinds the posts prior to the next query. This is far from ideal and would like to make the code more efficient without having to repeat all the template code for the posts over and over. I also want them to be in a random order instead of coming out in the order they have been written as I don't want any particular author to be at the top. Thanks.
I'm not sure why the use of rewind_posts() is necessary. You are creating a new query using by your use of query_posts() each time. rewind_posts() rewinds the query for re-use.
If your performance isn't suffering, it may be okay to run 5 queries to get your five authors. To avoid rewriting the same template code each time you have at least two options. Create a php file with the template code in it, and include it each time you need it:
<?php include('author_posts.php');?>
Or, better yet, create a function in your functions.php or in a plugin file that accepts your query results and outputs the template.
<?php $posts = query_posts('posts_per_page=1&author=author1');
if(function_exists('my_authors')){my_authors($posts);}
?>
Then in your functions.php or plugin:
function my_authors($posts){
//template code here, using $posts->ID, $posts->post_content, etc
}
The third option, which cleans up your code and the number of queries would be to use a category to display posts assigned to it here. You are making 5 queries to display five posts. To use one query to display five posts and sort randomly like you want to, edit each of the five posts and assign them to a new category, lets say:'author sampler'. Then in your template file:
<?php $posts = get_posts('category=author sampler'&order_by=rand&order=asc');
foreach($posts as $post):?>
<?php setup_postdata($post);
//your posted template code follows:
?>
<article id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?><?php edit_post_link('Edit', ' (', ')'); ?></h2>
<p class="p-cat">In: <?php the_category('|') ?></p>
<p class="p-author">
<span class="name">
<?php the_author_posts_link(); ?></span> <span class="avatar"><?php echo get_avatar( $email, $size = '32' ); ?>
</span>
</p>
<?php //etc ?>
<?php endforeach;?>