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 chateau_dur on
Hello all,
In Drupal 7, I have disabled/hidden author info in my theme and content type, but the author still shows in search results and the "latest content" block.
I want to get rid of it, of course I could do it in CSS but that would only be front-end. I don't know how to solve it from the root of the problem.
Could anybody help me out with it?
Thanks a lot in advance :-)
Comments
For Search Check...
chateau_dur,
You obviously know in D7 you can now remove author/date info through the specific content types settings.
This also depends on if you are using a custom theme or using one of the default themes drupal 7 provides.
Things you can search through your "Themes" Code for are:
Search any of those or other relevant items and you'll find that solution somewhere.
In the Content Blocks, you may have to dig into the Modules code...
Then of course, you can delete that specific code and it will remove it. Always suggested not to mess with core elements, but the
<?php print $submitted; ?>
snippet shouldn't and won't do to much damageWouldn't suggest it, but here is an alternative
You can go directly into the search module: modules/search
and locate search-result.tpl.php
and remove this:
$info
is what provides the meta info in that module.Make sure you make a copy of the search-result.tpl.php in case in the future it gets thrown off. There are other ways to do this.
.
It's a better practice to first copy the search-result.tpl.php file into your theme folder (in /sites/all/themes). Then you can remove that code in the copy and clear your theme registry, and it should work fine.
If you just edit that file directly, you will destroy your upgrade path. If you upgrade, those changes will be lost.
Thanks
Thank you everybody, you've been a great help.
I hope this thread will help others!
Cheers
Do not modify the php file!
If you want to hide any content wich is generated by any php code add these lines to end of your style.css file:
Thanks Schmidt - that worked
Thanks Schmidt - that worked a treat!
A clean, simple and official
A clean, simple and official way of doing it is to copy the original template file (in this case d7root/modules/search/search-result.tpl.php) into your theme and remove from that file what you don't want (in this case, the last "if" statement). Do not modify contrib themes, instead create sub-themes. Template files in the active theme have precedence over default ones.
Nice. Thanks Schmidt
Super simple... thanks, much.
Schmidt's CSS suggestion is an elegant solution
Best, easiest result Thanks!
There should be a better way
Shouldn't there be a way to do this with template.php or with a pre/postprocess? TPL edits should be a last resort and a display: none does not hide the text from search engines that read the generated html.
Yes there is a better way
Yes there is a better way using template.php if you are using your own theme. If not, you can create a sub theme.
Add this function to template.php and don't forget to change YOUR_THEME_NAME:
Thanks prossel, exactly what
Thanks prossel, exactly what I was looking for.
Drupal 7 Version working for me
In AdaptiveTheme there are several settings for this purpose!
http://www.DROWL.de || Professionelle Drupal Lösungen aus Ostwestfalen-Lippe (OWL)
http://www.webks.de || webks: websolutions kept simple - Webbasierte Lösungen die einfach überzeugen!
http://www.drupal-theming.com || Individuelle Responsive Themes
Working awesome
Thanks Prossel. Its working well great solution
All this did for me was make
All this did for me was make the author name into a link
I consider this a D7 core bug!
As suggested, you should be able to turn this off under "Display Settings / Display author and date information" for content type. However, this has no effect on whether these attributes are displayed in search results.
It is not always desirable to show user info on public websites because this info is also the login name.
As mentioned, there are several ways to hack this issue, but none of them work cleanly. Each method still leaves an unwanted horizontal line after each search result. If revision history is being used, a horizontal line for each revision will also be rendered... even if all revisions have been deleted! Some of my search results show 8 or more horizontal lines after the search result. Possibly other problems are involved?
Because this issie originates in a root module, it seems that D7 core needs repair.
Worked for me
prossel's solution was pretty simply and it worked for me!
Worked perfectly
Prossel's solution worked perfectly in my subtheme. Thank you.
prossel's solution worked for
prossel's solution worked for me too, but now I was wondering if there's a way to separate out the author and the date. That is, how would I amend prossel's code so that instead of it saying author and date posted it could say something like "This entry was posted on ."?
Is that possible? I'm assuming that it is, just not sure how to do that.
Thanks.
Josh
How to show only the publication date
You can do that by overriding the template_preprocess_search_result function in your theme's template.php file.
If you look at the code example you'll see that the function sets an array named
$info
. The array contains four key / value pairs: 'module', 'user', 'date' and 'extra'. I'm not quite sure what's stored in 'module' but the others contain the user name, date published and other info, such as the number of comments.To get the function to only show "This entry was posted on ..." you could copy the function to your theme's template.php file. Rename the function so that the first word is the name of your theme instead of 'template'. Then remove the values you don't want to use in search results and add "This entry was posted on " to $info['date'].
Here's an example. The theme I'm using is Boron; you'll need to change 'boron' to the name of your theme. Otherwise you should be able to just copy & paste...
Alter, not override
Like all preprocess hooks, hook_preprocess_search_result happens as well as template_preprocess_search_result, not instead of - it's not a theme override, it's more of a hook_alter type of a thing. That means the $variables array already includes info_split with all the values calculated here. Rather than starting from first principles you can just do this:
Note that this can also go in a module instead of a theme. That way you don't have to keep rewriting this every time you change your theme.
++Andy
Developing Drupal websites for Livelink New Media since 2008
Now with added date
Oh, and to prefix the date like that, something like this:
++Andy
Developing Drupal websites for Livelink New Media since 2008
similar to some of the
similar to some of the solutions above but less cluttered (I think)
put in your theme's template.php and change THEMENAME to your theme's name
use only one of the below
------
GiorgosK
Web Development
Tried: similar to some of the
Tried the code sample you have and it partially worked. The username is still showing up on my results.