I'm new to Drupal but I am learning quick. I have been stuck for the past two evenings, however, on theming views. I know I am doing something very wrong so I need some guidance.
This is my layout in just html/css: www.davianletter.com/test (and yes, I am aware that this page needs major tweaking before it's ready for live thanks to IE). My drupal install is on my local machine. I am trying to layout the front page (because I have all of the other pages laid out correctly). I am stuck when it comes to the "Recent Articles" column. What is the best way to set that column up? I want the latest blogs (which is what is showing to the left of the "Recent Articles" column) to list in the "Recent Articles" column showing just the Title and short snippet of the Body. Is this possible?
Any advice will be very, very appreciated. As I said, I am new to drupal so don't make fun. I have read so many posts on view theming and none of it seems to make any sense. The "code" that "theme wizard" spits out doesn't really make sense to me. I've tried copy/pasting that into my template.php but then what?
Please help!
Comments
Pretty please?
Pretty please?
Have you taken a look at
Have you taken a look at views? Views is basically a query generator that allows you to manipulate output... and then panels gives you flexibility in how it's displayed. I've toyed with Views a bit and it seems pretty robust, though with a bit of a learning curve.
Also, not sure about Drupal 5 as I've only used Drupal 6, but there's a "Recent Blog Posts" block that can be set and plugged into any of the regions (under admin/build/block).
Views: http://drupal.org/project/views
Panels: http://drupal.org/node/201914
HTH.
Making progress
I have figured out how to style the view the way I want. Thank you for your help. I wasn't aware it was as easy as editing the css tags.
My last problem with this seems to be the teaser length. You see, the "recent articles" column is going to show a snippet of the blog posts. The problem is that the blog teaser is shorter than the "recent articles" teaser needs to be.
How can I go about configuring this so that the body of the view does not extend into the next blue "caption bubble" (see my site layout)?
To me, the most ideal setup, would be to use my css tags that I created to keep the content within the bubbles. To do that, however, I would need to setup 3 different views. I was unable to figure out how to setup a 3 views... 1 to show the most recent blog, 1 to show the 2nd most recent blog and 1 to show the 3rd most recent blog. Is this possible? Or even better, use the same view, but in the embed code be able to increment the output?
Thank you!
...
Either make the bubbles expandable or write a small function to trim the post to a predefined length. You only need the one view.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Thank you for your response.
Thank you for your response. Making the bubbles expandable is a GREAT idea but even in doing that, I would still need a way to trim the content.
Could you point me in the right direction for a function that does something like that? I'd really appreciate it!
I think I found my answer!
I think I found my answer! Going to try it out and report back for future reference!
http://drupal.org/node/46391
Ok, upon first look, it
Ok, upon first look, it seems that using this type of function will not work unless I specify it as separate views. Trimming to 20 words (for instance) will only show the first 20 words of the view. That means it will show me the first 20 words of the 1st article but the other 2 articles will be trimmed. Refer back to my site to see what I mean in the Recent Articles column: www.davianletter.com/test
Do I need to create multiple views or edit this function to only trim the body field of the view?
Thanks in advance!
there need only be one...
No, you only need the one view.
Use a function, such as this, which goes in your template.php file:
Then in our views-name-of-my-view.tpl.php file we use this function to process the field we want to trim, for examplere heres one I wrote recently using the above function:
You can see ther result here - the 4 articles in the left col of the front page (I omitted the image code from the above example for clarity).
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Thanks for the help. I guess
Thanks for the help. I guess now I am back to where I started. I am been unsuccessful in creating a views theme tpl file. I gave up on this last week and started just overriding all the fields with css. As you probably guessed, I am unable to use your trim_it function without a tpl file for that theme.
I setup that entire Recent Articles to be a block called "snippets". I setup my "recentarticles" view to display as a block and popped it in the "snippets" block. I have searched for literally hours and tried tons of naming conventions but no luck. When I name my file "block-views-recentarticles.tpl.php" the content disappears completely but I am not sure what that means.
I know this is a beginner question but I am really stumped. I am not sure if the views naming convention you are referring above (views-name-of-my-view.tpl.php) even works for D5.
This is the process: 1) Use
This is the process:
1) Use the Views theme wizard to generate the code (use the simple list option)
2) Copy/paste the function into template.php
3) Create a file and paste in the template code - the wizard tells you what to name this file, but its going to be something like views-list-recentarticles.tpl.php
In this file there will be a call to a CSS file also, I always comment it out or remove it, since I dont want these additional view specific stylesheets.
3) Upload it all to the server and viola.
Now you can see the default outout, and you'll want to start modding the views template HTML, such as removing the field labels, perhaps removing much of the HTML (which is the main reason I do this).
Are you by any chance using Zen theme? If so, if you place these views templates in the subtheme directory they wont work. You need to place them in the core theme's directory.
"block-views-recentarticles.tpl.php" - what code is in this file, a copy of the default block template?
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
THANK YOU! THANK YOU! THANK
THANK YOU! THANK YOU! THANK YOU!
You're right! I was using the Zen theme. You won't believe it... but when I was using the Theme Wizard, I was not selecting "Select Theme Type" but rather I was clicking "List Theme Fields". So what I was seeing was not a full function or a full tpl file. That's why I was so lost!
Man... I am not even upset that I wasted so many hours trying to figure it out. I am just glad it finally works. Thanks to you! I really appreciate it. If you need any design work in the future I will be sure to keep in mind how much you've helped me.
Thanks so much.
LAST QUESTION for this
LAST QUESTION for this issue. I would like to trim the title if it's too long as well. How can I reuse the function? I tried tweaking it but I can't get it right. I know I am pushing my limits here with questions... Sorry!
np
No need to touch the actual function, just adjust the value you are sending back to it, i.e.:
What we are doing here is setting a variable, by running the $title variable through the trim_it function, which takes the paramenter $n (the value you set, e.g 70, which means 70 characters)
This will trim the title back to around 70 characters.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
To be honest, that's what I
To be honest, that's what I tried first but it didn't seem to be able to handle two calls to the same function.
Here is the code I have in my views-list-recentarticles.tpl.php:
This causes just the body to print. The weird part is that it makes the body the link to the article (the title normally is). When I change both trim_it amounts to the same number (e.g. 80 & 80) then both the title and body display. Not only does this defeat the point, but it somehow moves the 2nd articles body into the 2nd articles title causing both the 2nd article's title & body to be links.
It's like the function can't handle two calls but I even duplicated the function in template.php and renamed it but no luck.
Thanks for all your help, again.
hmmmm
OK try this, I use this with multiple views all the time, but I never used it twice in the same view, I just tested this in node.tpl.php but not with a view in D5 (i have nothing immediatly available to test in right now).
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Nope. Same thing. :(
Nope. Same thing. :(
Ok, I see, I need to mess
Ok, I see, I need to mess about with this with Views a bit, not sure why its freaking out like this, I just tried with Views and see the problem (wtf?), hmmm, will get back to you.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Thanks for helping me out so
Thanks for helping me out so much. I really appreciate it.
...
OK, some lateral thinking later... of course this will break, its stripping the closing anchor tag etc... if you print the title but not as a link it will work fine, I need to debug this to see if can make it work with a link - I could write some regex to do this probably but dude I really struggle with regex... I'll try to think about this over the next day or two.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Heres a workaround...
This is a bit of a workaround (wheres nevets when we need him...)
You need to modify your View:
First - change the Node: Title option to "Without Link".
Add the field "Node: Link to node", and in the options field add the word "REPLACE".
Then in your views template replace
<?php print $title;>with this humdinger...Theres got to be a better way of doing this to be frank, but it will work for now.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Got it! Thanks for the
Got it! Thanks for the humdinger. :)
Now I just have to figure out why it's breaking when I upload it to the web (www.davianletter.com/tdl). That I can handle though. Thanks so much.
Your humdinger works awesome
Your humdinger works awesome on my machine. I just now uploaded my whole template (www.davianletter.com/tdl) and I am working to put everything together. For some reason, the body of my view is printing a blank div... Ever seen that before?
Any ideas?
Any ideas?
...
where are we meant to look - I mean wheres the view with the problem?
Not really sure off the top of my head.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Oh, sorry.
Oh, sorry. www.davianletter.com/tdl - the recent articles column
To quote a famous chef...
To quote a famous chef, f...k me.. what a mare this has been, and really I am quite sorry for not fully testing before posting, its not really help when its no help at all...
To clarify: The other night I tested this not with $body, but only with a CCK field, because that is a view I had immediatly availble and I made the assumption that body would work as per normal, but it does not - the trim_it function is crapping out somewhere and I dont really have time to debug it right now - but, all is not lost, I recalled seeing this function on lullabots site so I gave it a crack and to cut a very long story short, it works with $body.
so, this new word_trim function goes in template.php as per normal, and you can use in place of trim_it for both if you want.
Then in the views template, something like this:
TRUE = show ellipsis (...)
If you dont want ellipes then leave it blank (and remove the preceeding comma)or use FALSE.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
First of all, thank you
First of all, thank you again for taking so much time to help me. Sadly, this may be a perfect example of why "delayed conversations" (e.g. forums) are sometimes very frustrating and impossible to relay information correctly.
Your trim_it function worked PERFECTLY on my machine. When uploaded to my host (www.davianletter.com/tdl) the body prints a blank div. I was scared, as I read through your latest post that you may not have caught that part of my previous post. I noticed there was nothing majorly different with this code but I tried it very anxiously anyhow.
As you can see at www.davianletter.com/tdl, the Recent Articles column is still not printing the body while it works perfectly on my localhost.
Please feel free to e-mail me or chat with my on Gtalk. I am so sorry to have wasted your time.
ok, I'll give you a buzz on
ok, I'll give you a buzz on gtalk tomorrow, you can give me a log in etc and we'll get it sorted out. Don't worry about the time I or we spend messing about with this sort of thing, it kind-a fun in a very geeky sort of way.
see if you can collect some data on the differences between your local host and the live sever (and the actual Drupal installation and View), got to be something thats just not the same.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
While in development, I am
While in development, I am changing to a different theme. Please contact me via Gtalk when you're available. I will be online working on the project for the rest of the day.
Please don't take this offline
Or at least come back with your final resolution. Nice work on the theme BTW.