Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By .carey on
I'm in the process of developing a news-style site and so I wanted the "submitted by" to have a custom look based on the node type. In other words, I wanted blog posts to have a custom "submitted by" that was different from the custom "submmitted by" for news articles.
Here is what I came up with:
<?php if ($submitted) { ?>
<span class="submitted">
<?php if ($node->type == 'blog') {
print 'Posted ' . format_date($node->created, 'custom', "F jS, Y") . ' by ' . theme('username', $node);
}
else {
print 'By ' . theme('username', $node) . ' <br /> ' . format_date($node->created, 'custom', "F jS, Y") ;
}
?>
</span>
<?php } ?>
(Note: I disabled "submitted by" for 'page' in themes > configure > global settings.)
Hope this is useful to someone.
Cheers,
Carey
Comments
=-=
thanks for the tip! : )
may want to refer to the 'page' in your note as 'content type'
My first reaction was to shut that off on "page" until i went back and reread the snippet that stated blog.
Thus, this method can be used on any type of content type.
You got it right the first time.
I did mean that I shut off the "submitted by" for 'page' - that is, all pages.
On my site I use 'page' for what would normally be static html pages (I don't want a "submitted by" on them), 'story' for articles, and 'blog' for all blog posts. Articles are more formal newsy writings and blog posts are more informal opinion writings. That's how I've distinquished them, anyways.
Yes, you are right, though. This can be used for any content type. I just chose to use it this way....And with an 'elseif' statement in between, another content type can have its own custom "submitted by" too - like 'page' just displaying date.
Where did you put this code?
Perhaps it should have been clarified that this code goes in your theme's comments.tpl.php.
Quick and Simple
This works great! Instead of adding conditionals I used it inside node-blog.tpl.php in order to customize the message for blog posts.
There's a module for this
Please use:
http://drupal.org/project/submitted_by
No coding required! =)
--
https://www.codeenigma.com/
Thanks for the tip! This is
Thanks for the tip! This is awesome.