By cdybdahl on
I'm designing a site which will, ideally, feature three distinct blogs.
What I would like to do is give each blog a representative block on the home page containing the author's pic, the name of the blog, a teaser to their most recent entry, and a link to the full post.
So far, the best thing I've found to do this is the Views module, but it's really WAY more than seems necessary. Surely someone has done this before and can give me some pointers?
Thanks in advance!
Comments
Plain SQL queries! Faster
Plain SQL queries! Faster and more lightwieght. If you could tell us how the blogs are diffrentiated (by author, content type, categories, etc.) we could write the queries for you. :-)
Wow!
Thanks so much for the speedy response and particularly for the extremely generous offer!
I'm new to the "under the hood" portions of drupal, so I can't tell you how much of a help that would be.
The blogs will be differentiated only by author. So if I have Jim, Bob, and Mary all blogging on the site, ideally each one would have a block of content on the home page with their photo, the name of the blog, the teaser from the most recent entry, and a link to the full text.
As far as the easiest way to incorporate this on a page: would it best be included in a custom block type, or is there some other (fancier) way of doing it?
Custom Block
For one block with all authors:
If you want a separate block for each author, set $authors to the UID of just one author and remove the foreach() and corresponding curly braces.
This is probably the dumbest question ever asked here.
But how can I get this code to work? I have tried pasting it into the block as text and the code shows up in the resulting block instead of the results.
You need to change the input
You need to change the input filter to PHP. If you're User 1 or if you have permission to use the PHP filter, you'll see an expandable fieldset below the textarea where you can change the input filter. If you're using a WYSIWYG editor, you'll need to disable it in most cases.
And by the way, when I say "change $authors to the UID of just one author" I mean remove the array() part too.
Drupal 7 gives error on this script
Thank you so much for this script. It was exactly what I was looking for. But I got following error in drupal 7.. (I already fixed line 13)
Fatal error: Call to undefined function db_fetch_array() in /home/content/k/a/t/kathamitho/html/main/modules/php/php.module(75) : eval()'d code on line 8
http://drupal.org/node/1020760#comment-3924556 This link says:
"One of your blocks has PHP code in it which tries to iterate on a database result using old database functions. You'll have to update that block. Setting to normal, might become a won't fix eventually."
Please can you provide a fix for drupal 7. That would be really helpful for a beginner like me.
This is all great, but...
I am learning quite a lot about Drupal just troubleshooting this little issue, which is exactly what I wanted.
Thanks to everyone who has helped so far.
When I plug the code given above in, I get the following error:
Parse error: syntax error, unexpected T_STRING in /home/content/h/a/p/happyeyeballs/html/includes/common.inc(1537) : eval()'d code on line 13
I also have no idea how to go about finding the uid for a given user. This information does not appear to exist anywhere but in the database -- is this correct? So the only way to get a user's uid is through a query? Is there a way to pull the information based on username instead, or is that a bad idea since the user can change their name at any time?
Line 13 should read
Line 13 should read
--I forgot the "." after the span, and I forgot the time() in format_interval.
The user's UID is the number that appears after the word "user" in the URL when you're looking at a user's profile.
And, just FYI, you can get the current user's UID at any time like this:
...not that that's very useful here.
Thank you!
Replacing that line of code works beautifully. This is exactly what I needed.
What a great community this is.
I look forward to reverse-engineering this code so I can learn how it works.
Thanks again!
No problem
If you need any help or explanation of that code, feel free to ask. I can help with anything you don't understand--it certainly took me long enough to figure some things out, and it's such a pain to have to go back and change old code that you really want to get it right the first time. :D
Adding (n) of body characters to this...
How can I add a specified amount of the actual blog to the result set. For example, I would like to use this as a teaser in the right rail. I would like to show the most recent blog and say 250 characters of the content with a link the /blog page. Any feedback you can provide will be helpful.
Just to avoid confusion, I
Just to avoid confusion, I think what you're trying to do is create a block in the right sidebar? Unless you're *really* into writing your own SQL code, Views is the way to go for this.
Creating a block is exactly what I...
am trying to achieve. I am absolutely new to Drupal and PHP (C# developer by trade) for that matter so I must apologize for my ignorance. That being said I found the Views module a bit limiting and in many ways somewhat frustrating. Then again I have to assume I was doing something wrong :(. In the end I decided to write custom SQL for this. I was forced to join "node" on "node_revisions" and "url_alias" to achieve what I wanted and I couldn't seem to pull it off with the Views module. I will ultimately turn this code into a module like "Latest Blog Post" (may only fit in house needs). I really appreciate you getting back to me. The Drupal community is very encouraging and I can honestly say I will stay with it. Best.
Well I'm not a developer at
Well I'm not a developer at all, so I always go for a solution which doesn't require me to write code. If you're happy with it, good for you & good luck.