So, I know that if I want to make the page http://www.whatever.com/blog look different, I just upload a file like page-blog.tpl.php

However, this is of little use to me because I want to have the actual blog entries maintain the separate look as well. From what I understand, I would have to create every single page file to accomplish what I want:

page-blog-1.tpl.php
page-blog-2.tpl.php
page-blog-3.tpl.php
page-blog-4.tpl.php
page-blog-5.tpl.php
etc.

Surely there must be a different way of doing this, right? I know there must be, as that would be insane to have to do over and over again. The documentation was not helpful with this... that or it is just hidden away really well.

Regardless--how can I have all blog entries maintain the same look? I've tried searching, but I am not exactly sure what to search for.

So any help is greatly appreciated.

Comments

vm’s picture

Customising blog layouts

may help

_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

JMowery’s picture

But that doesn't change the layout... It only changes the actual node settings.

I actually get a page within a page.

I want to change the actual page layout for every single blog entry.

Essentially... I want the whole blog section for my site to have a separate look.

For example:

I want the sidebar to be on the right for the blog's main page, and for all the blog entries.

On the rest of the site, I want the sidebar to be on the left.

Could you give a quick example of how I would accomplish this?

When I copied my code from the page.tpl.php to node-blog.tpl.php, it actually displayed a page within a page. Not the desired effect.

vm’s picture

not sure what you mean by a page within a page
nor why you are copying page.tpl.php to node-blog.tpl.php and this could be where you confusion lies.

you have different variables available at node then you do at page. so you would want to copy node.tpl.php to node-blog.tpl.php

conditionally showing side bars, is done in template.php I believe, not in the page.tpl.php, though I could be wrong.

I suggest biting off smaller pieces, deal with getting your blog themed, then work on your conditionals.

_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

JMowery’s picture

So, essentially, there is no way to maintain two different looks throughout a site on drupal?

That sucks.

I had plans on having my site split up into 4 different sections, all having a different look and feel throughout, and then having the blog with a different look as well.

Just disappointing to hear that it is not possible....

I actually have the layout and design created. I'm just getting ready to code it, but now I'm not sure if I can even use Drupal for what I had in mind.

vm’s picture

I far from said it wasn't possible.

what you are trying to do is show sidebars conditionally. if blog show left, else show right.

MY suggestion was to get your head around how the custom tpl.php files work, FIRST. then work on conditional sidebars.

I think the way you are going about themeing your blog area is incorrect because you are copying page.tpl.php when I don't think that is what is necessary.

example: when I theme a music site and I want my audio nodes to look different, I theme them using node-audio.tpl.php not page-audio.php

had you copied node.tpl.php to blog-node.tpl.php and from there worked in themeing how you wanted your blogs to look MINUS the side bars then you are 1/2 way there.

then you can work with getting the sidebars to conditionally show based on where you are, which actually may be easier if you use block visibility in administer -> blocks depending on exactly what blocks you want to show where and how.

Thus my suggestion was merely to work this situation in TWO parts, rather then one, which seems to be why you are trying to throw page.tpl.php into a custom tpl.php for blogs, and from my reading it doesn't work quite that way.

_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

JMowery’s picture


if ($node->type == 'blog') {/* check if it's a blog node */
    include 'page-blog.tpl.php'; /*load  page-blog.tpl.php */
    return; }

Wouldn't this code work if I just added it to the node-blog.tpl.php file?

That would load the layout for the blog page, and then it would apply it to all the nodes.... correct?

Also, I want to show a varying amount of content. I also have blocks, featured sections, and much more that I want to have be in different locations in each "zone."

The hardware section will display the latest 4 posts with the images. The software section will display the latest 2 posts with featured images. The web 2.0 section will display on 1 post with the featured image. All of them will below it then have the latest blog entries for each as well.

vm’s picture

Don't quote me here, but I believe that kind of logic would go into template.php based on the way drupal searches for matching tpl.php files.

again, I can only comment on the way I accomplish the same type of task.

I use a node-contentype.tpl.php to theme the content of that nodetype which is called after page.tpl.php, when I do that every node within that content type is themes per that tpl.php that was created.

maybe this videocast will help - http://drupaldojo.com/lesson/theming-like-a-pro
may also want to read this chapter in Pro Drupal Development - http://www.apress.com/book/downloadfile/3486

_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

JMowery’s picture

I use a node-contentype.tpl.php to theme the content of that nodetype which is called after page.tpl.php, when I do that every node within that content type is themes per that tpl.php that was created.

I don't understand though. The way Drupal works is that you are supposed to override things.

So, when I have the node-blog.tpl.php. Shouldn't my inclusion of the page-blog.tpl.php override the settings of what it would have called from the normal page.tpl.php?

The way it works now. http://www.whatever.com/blog takes what I have from the page-blog.php and then displays node-blog.php. I have both those files created.

But, when I click on the actual node, it instead loads from page.tpl.php instead of page-blog.tpl.php. I figured that since I included the code from page-blog.tpl.php that it would override the stuff on page.tpl.php, but this is not happening.

Yet the desing of Drupal is made for it to happen this way.

Am I just not understanding Drupal correctly? I mean, I read Pro Drupal Development, and that is my understanding of everything, but I just don't understand why this theory does not apply here.

JMowery’s picture

Theoretically.... I just need to have node-blog.tpl.php load up page-blog.tpl.php.

That should be the way it works. The page-blog.tpl.php would override all the other settings.

It has to be possible. That is the way Drupal is built. Someone must have an idea of how to do this for all nodes part of a particular node type.

Perhaps if I find a way to load the node first, instead of the page file first, this will be possible? How do I force the site to load the node first, and therefore override the page.tpl.php? Do you know how to do this VeryMisunderstood?

JMowery’s picture

Is the only other way to do this to include if statements to check if the node is currently that content type?

For example

if (node type == blog)
{
show right sidebar
don't show left sidebar
show featured blog articles
don't show featured hardware articles
don't show featured software articles
don't show featured web 2.0 articles
don't show featured game articles
show bottom block
show latest forum posts
}

if (node type == software zone)
{
don't show right sidebar
show left sidebar
show featured software articles
don't show featured blog articles
don't show featured hardware articles
etc.
etc.
etc.
}

This is the only way to accomplish this?

It certainly seems like a lot of excessive work. I mean, even in WordPress it only requies a few lines of code to accomplish exactly what I want, and it is supposed to be far less complex than Drupal.

Someone MUST know of a way to accomplish what I want.

I want each node to of a particular type to display a layout of a particular type.

Why must I deal with all these if statements when doing it the other way would be more practical. If it isn't this way, is there a way to hack drupal to make it so?

panis’s picture

not quite..

page.tpl.php files define page layouts.. this will work better on the page.tpl.php file - however remember that http://.../blog/1 I believe shows you the blog for user 1 so $node->type will not resolve to anything - you will need to also use arg(0) == 'blog'..

node.tpl.php files define only the layout of the content that is contained on a page - by doing the above you end up embedding a page inside a page - not what you want to achieve.

this may help in the page.tpl.php file before anything else

if(arg(0)=='blog' || $node->type == 'blog') {
include '.....';
return;
}
JMowery’s picture

http://img441.imageshack.us/img441/2902/pageinpagesc6.png

I get a page within a page. I want the sidebar to be on the right side instead for that blog entry.

vm’s picture

reread my comment, I was editing when you pasted the image.
what you are getting there makes sense because you are copying page.tpl.php to node-blog.tpl.php.

_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

JMowery’s picture

I know it makes no sense, which is why I'm searching for a way to correctly theme the layout to have a different look for each separate section.

I'm just beyond disappointed with Drupal if it can't accomplish this.

paulnem’s picture

If you want to change the whole theme of a node or nodetype, take a look at Taxonomy Theme.

http://drupal.org/project/taxonomy_theme

If you don't want to use the module, it may help with some code ideas etc.

JMowery’s picture

That is exactly what I want!

Why on earth isn't this included by default? It seems logical that this would be basic functionality.

However, it is not currently available for Drupal 6. So, I'm still kind of screwed in a way.

WorldFallz’s picture

They way I would approach this, and I think what VeryMis is getting at is, I would make 4 (or however many you need) blog content types (ie blog_whatever, blog_whatever2, blog_whatever4, etc.) and then theme those via node-blog_whatever.tpl.php, node-blog_whatever2.tpl.php, etc).

There's almost always more than one way to 'skin a cat' in drupal-- that's one of it's strengths, not a weakness. And definitely check out the dojo screencast VeryMis links above (and read the sample chapter on theming). It's the single best way I know to grok drupal theming. Even if you're using v6, it's still a good start. They also have a screencast on v6 theming: http://www.drupaldojo.com/lesson/new-stuff-in-drupal-6-theming

Time well spent.

JMowery’s picture

So, can you actually theme the page layout with only modifying the node?

I am interested in modifying the location of blocks and whatnot.

WorldFallz’s picture

So, can you actually theme the page layout with only modifying the node?

I'm not sure I understand the question-- but I've only ever modified page layouts on my sites by editing the *.tpl.php files, mostly node-<contenttype>.tpl.php, css files, and very rarely template.php. Specifically, regarding blocks-- I do that through the admin UI at admin/build/block.

panis’s picture

reset to your default template.php file
undo changes or delete your node-blog.tpl.php file

copy page.tpl.php over to page-blog.tpl.php
edit page-blog.tpl.php - locate the strings $left_sidebar and $right_sidebar switch them around...

- I think the template engine will pull up this file when you go to http://..../blog/. It does so for different content types - however the http://..../blog is strictly not a content type page so.. if it does not the fix is easy either in the template.php file or a cheaper way in the page.tpl.php file include the following (purists may flame you for doing this - but if it gets the job done...)

<?php if (arg(0) == 'blog') { include('page-blog.tpl.php'); return; } ?>
You could also just edit the page.tpl.php file and insert the check for arg(0) where the left and right sidebars are being printed and switch them around if arg(0) is set to blog.

another trick is to see if the $node variable is available and what $node->type is set to.. The http://../blog/1 is not a blog node type page - it is the blog for userid 1 so I am unsure if drupal will automatically pull up page-blog.tpl.php - but I believe it should based on phptemplate engine's template suggestion order.

hope this helps.

Anonymous’s picture

Hi, I've been trying to figure out a simple way of making the layout change depending on the node type being displayed and found this link pretty useful: (Show a block depending on node type and node id) http://drupal.org/node/115419

And also: (Overview-approach to block visibility) http://drupal.org/node/64135