A few stumbles I have hit trying to build my Drupal site:
I created a few test stories and promoted them to the front page of the site. When you click on the titles of the stories, it opens the full version of the story but uses the same template as the front page to display it. I created a page-story.tpl.php & node-story.tpl.php and loaded them into the theme folder but the stories won't display on anything but the main page template. What am I not doing to make the stories use the page-story template rather than the default one? I have gotten frustrated with it because I think it is some basic step I am not doing.
Another question: Is it better to create a page-front template to use for the front page rather than use the default template? I did play with doing this but I was having trouble getting the stories that were promoted to the front page to actually appear on this alternate front page template, they seemed to only want to display on the default template. Is there a way to route the front page articles to an alternate template?
And related to this: If I wanted to have stories separated by type (like news, sports for example) is there a way to format the php content display tag to display stories by type or only display only a certain type of content. Say I want to display a list of news articles in one place and the sports articles in another on the same page. Can the php content display tag be formatted to display things in this manner? (Didn't know if it was possible to use the php content tag multiple times on a page to display different content.)
Thanks in advance for any help that can be provided!!!! I am still in the learning stage and appreciate any advice or input.
Comments
I hope I can help, at least a
I hope I can help, at least a little . . .
1. Node Type Templates -
Your file names look like they're correct (node-story.tpl.php). I'm wondering if it's possible that you're putting them in the wrong place? They should go into the root folder of the theme you're using. So, assuming you're using a theme called "foo", which you've placed in "sites/all/themes", your template files should be in that theme folder, "sites/all/themes/foo".
2. Front page template vs. a universal template
I think this is a question that has a different answer for each site, and a lot depends upon what the customer wants. Take a look at what other sites doing similar things are doing.
One thing to think about, as you consider this question, is how do you expect that your users will find their way to your site? Are they going to be just typing the URL into a browser? Will they find you through search engine results? In my opinion, having a pretty home page does you very little good if your primary marketing effort for the web site is SEO, since the pages linked by the search engines will not be your home page -- they'll be the blog page that had the terms the user was looking up. So, that initial page view the user has on your site isn't going to be that very pretty landing page you've constructed.
3. Displaying nodes of a specific type or taxonomy
What you're talking about doing here is what the views module allows you to do. Views allows you to create lists of content based on a huge variety of factors -- node type, categories/taxonomies, author, date, and so on. It will allow you to create blocks that you can display in different parts of the site, or full pages dedicated to displaying that sort of content, and a lot more.
Hello
Some quick answers to your questions:
1: You can create a content type based template based on the content type name (like you have done). So, node-story.tpl.php would go in your theme's directory (don't forget to clear the cache). Now this content type's node content will be displayed with this template. Note that only the node content and not the page content is displayed with this template.
2: I never use front page templates (personal choice). I don't like the idea of having to maintain two copies of page templates. I try to use creative theming or logic in the page template. But, I know sometimes it is best to use the front page template.
3: For displaying different content types in different places I would use the Views module to create the displays as blocks. Then you can show those Views display blocks in different block regions on your site. If you theme doesn't have enough regions, or they aren't in the right places, then you can modify your theme to add/modify the regions.
Hope this helps some.
Regarding templating, if you
Regarding templating, if you want a different template for the front page you can copy page.tpl.php to page-front.tpl.php and modify each as desired. Remember to clear the theme registry.
You can use the views module to create lists of content based on content type (and other things). You can make both page displays and block displays with views.
If you want multiple lists created by views in the content area (vs putting the blocks in the sidebars) you can use the panels module.
I am placing the files in the
I am placing the files in the appropriate theme directory. But here is what is funny...when I load the page-story & node-story files into the theme folder, the front page stops working properly. The stories that are promoted to the front page are no longer clickable and the spacing between them changes. If I remove both file from the folder, the front page reverts back and the stories are clickable again. I have read about using a template.php file to allow files like page-story be able to work. Is this needed?...I created one and found recommended code for allowing alternate files to work. This is what I have in my template.php:
<?php
function phptemplate_variables($hook, $vars) {
// Node is passed to the node when is rendered as a full page.
if ($hook == 'page' && isset($vars['node'])) {
$vars['template_file'] = 'page-'. $vars['node']->type;
}
return $vars;
}
Is this needed or should it work without having to have a template.php file?
Having said all that, I still haven't had luck getting the stories to display in the alternate template.
I downloaded the view module but I have to tell you guys, I have had to download several applications to open these .gz files. I have tried to open the file that I downloaded for the view module and it seems to be empty...or this is another bad extractor application. What is the easiest way to download & open these .gz files? Is there a good application (free that is) for extracting files from the .gz files?
Again, thanks for all the help...I am having fun doing this but it helps to have people I can run questions by that know what they are doing!!!!!!
That looks like a Drupal 5
That looks like a Drupal 5 version, I would try
replacing YOURTHEMENAME with your themes actual name.
changes made...
Ok, I inserted the new function into my template.php file and uploaded it & refreshed the cache. I am still having the issue with the front page content stopping link and respace as soon as I place the page-story & node-story templates into the theme folder...if I remove both files, the front page content goes back to normal and is clickable to display the full stories but it uses the default template.
If you just remove
If you just remove page-story.tpl.php does it work? Or if you just remove node-story.tpl.php?
...
I have to remove both files to make the front page display properly. Leaving either of the files keeps the front page stories from displaying/linking properly.
..
I downloaded the views module and the advanced help module for views. Where does the advanced help module need to be placed?...inside main modules folder in its own folder or within the views folder....does the folder need to be name "advanced help" or something else?
It should go under
It should go under sites/all/modules, if you unpack it from there is should create the correct folder.
correction...
I was wrong when I said both the node-story & page-story files had to be removed for the front page content to display properly. It is just the node-story file that I have to remove. It's like the node-story & default node files are interacting.
What does your
What does your node-story.tpl.php look like?
..
Are we talking about
Are we talking about displaying a single node or a list of nodes?
Does your theme have both a node.tpl.php and node-story.tpl.php? It needs node.tpl.php for node-story.tpl.php to work.
Have you tried clearing the theme registry?
...
There will be multiple stories listed of the front page. I do have both files, but the node-story.tpl.php file in the theme folder causes issues with the display of the content on the front page...the stories stop linking and respace when that file is present in the folder.
I have gone and cleared the cache via the "performance" option in admin.
I do appreciate all the assistance you have been giving me with this and apologize for the delay in responding.
The following <?php print
The following
should be something like
..
It was correct in the node file...but I had changed it in the node-story one. This resolved the titles actually linking but when you click on the title, it still opens using the page.tpl.php file and not the page-story.tpl.php file (which has a different layout).
You would probably benefit
You would probably benefit from the devel and Theme developer modules. The later when enable can be useful in determining which template is used for which part of the page. For the page template you will want to use the body tag.
..
Loaded modules...but not seeing how this is going to solve the issue.
I gotta tell ya...this has got me a bit peeved...I thought this was something easy that I was missing but it has turned into an issue that has me ready to pull out what little hair I have.
I keep reading about the need for a template.php file to make this work and I have seen NUMEROUS versions of functions to use....and I have tried numerous versions with no success.
_
It is actually a pretty simple thing to do and nevets template.php function above should be correct. What theme are you using? Have you tried it with garland?
..
I am using one that i created called "energy." I used that function and inserted "ENERGY" for the theme name with no results. I have tried multiple function calls and all i ever get is the story displaying on the page template rather than the page-story template.
If your theme is called
If your theme is called "energy" you want to use that in the function name and not "ENERGY".
..
Renamed the function call but it continues to ignore the node-story template....please help end this madness!!!!! What am I missing?...This has gotten way more complicated than I know it should be.
_
go back and try it with garland-- if it works, then your theme has a problem somewhere.
..
I actually cleared out all the files in the energy theme and placed all the garland ones in and created a node-story & page-story using the garland default templates. This does not work either. Here are a few file samples I am using: (maybe someone will see something wrong I am missing?..and again thanks for all the help trying to figure this out!!!!)
======================
==============
_
I actually meant to try switch over to the garland theme entirely-- then copy node.tpl.php to node-story.tpl.php, add some sample text (ie "THIS IS A STORY"), clear the cache, creat a story, and view the results.
..
I did try this first (and inserted txt into both the page-story & node-story to indicate it was using them to display the stories...with no results. I am using the Drupal Themer Info to track the pages and it is showing that it continues to use page.tpl.php & node.tpl.php to display the stories. When I check one of the articles on the front page via the viewer, it indicated the following:
Candidate template files:
node-story.tpl.php < node.tpl.php
but still uses the default templates...
..
When I pull up the front page now, it displays the text I inserted into the page-story template "viewing node-story template" but the viewer info indicates that it is using page.tpl.php which has no such text in it. When I click on the title for the full version, it displays "viewing node-story template" as well.
I am confused at this point...
...
...
Are you sure you did not put
Are you sure you did not put "viewing node-story template" in node-story.tpl.php?
...
yep....
I want to review the steps for making this work and see if I can find where I am going wrong:
I took the page.tpl.php & node.tpl.php files and saved them as page-story & node-story and moved them to my theme directory. At this point, to clarify for me, is it necessary to have a template.php file to make this work...I have read places where some say yes & some say no it will work without it. I have used a template.php that I copied from another theme and added the code you gave me for making the template hooks work. I tried using a template.php file with only the function to make the multiple template work with no results.
Is there some other file that could be the issue?...the .info file missing something...etc????
This has been where I have sat since last week. When I click on the story title and bring up the full story, it is using the page.tpl.php file not the page-story file (according to theme info)...regardless of what I have tried. I have tried to switch themes, using garland, and creating page-story & node-story files for that theme and it won't use anything but the page.tpl.php file. Is this all pointing back to the template.php file being the issue?
HELLLLLLLLLLLLP!!!!
Is there something else I am missing to make this work?...this seemingly easy issue has been a major road block for me.