Drupal6 template file not recognised - drupal

I've create a nodequeue and set the "Description / Tag" in the Defaults section to "Entertainment Highlights" and when I click to view Theme: Information it has a template suggest for style output of
views-view-list.tpl.php
views-view-list--nodequeue-91.tpl.php
views-view-list--entertainment-highlights.tpl.php
views-view-list--default.tpl.php
views-view-list--nodequeue-91--default.tpl.php
This looked great because I was hoping to make a template in my theme for views-view-list--entertainment-highlights.tpl.php which wouldn't tie it to a particular nodequeue (building on dev and when I come to put live the nodequeue ID will likely have changed) however when I create the file on the file system and click rescan it doesn't highlight that template name suggesting drupal is not finding it.
If I create a file called views-view-list--nodequeue-91.tpl.php then this works fine and if I change the "Description / Tag" to simply "Entertainment" and create a views-view-list--entertainment.tpl.php file then this is also picked up by drupal so the issue looks like it's tied to spaced in the "Description / Tag" name
Does anyone have any ideas what I need to update to get the template to work. I realise it's likely to be a core tweak but it would be really helpful if it could handle cases like these.

I found this was not related directly to Drupal6 but instead was related to the OpenPublish variation we are using.
Turns out there is a function called _views_theme_functions() in /sites/modules/views/themes/theme.inc (not to be confused with /includes/theme.inc) which is using the following to determine the name of the theme templates
$themes[] = $hook . '__' . preg_replace('/[^a-z0-9]/', '-', strtolower($view->tag));
However if you examine $themes you can see all the non a-z0-9 characters have been replaced with underscores rather than dashes so needed to amend it to
$themes[] = $hook . '__' . preg_replace('/[^a-z0-9]/', '_', strtolower($view->tag));
I realise this is a core amendment and ideally I wouldn't make this change here.

Related

From which wordpress file i can change this page's layout

I am currently using wordpress for the website development and i want to change this page's formatting which is having url
http://www.selfmadesounds.com/dev3/?catid=featured&slg=featured3
I need to change this page's formatting such that i can exclude out the extra things from this page.
you are probably looking for category.php.
If you are a beginner with templating / themes / wp in general, you can simply search for class="category" and add a small string INSIDE the div in all of the template files where the search hit, one by one , and see which one is the one you look for .
You can insert <? php echo 'This is my page'; > or simply insert XXXXXX.
but just make sure you are not doing so in header.php, sidebar.php or footer.php - those will in all likelihood will appear on ALL your pages . ( also functions.php is to be excluded , but not in all cases ..)
but like others said, you should read the codex page about template hierarchy. it can also be any other filename (custom-loops.php file, custom-category-filename.php etc. depending on theme.
Edit I
I think you are mixing a bit of concepts here .
this line :
http://www.selfmadesounds.com/dev3/?catid=featured&slg=featured3
Is not a page, it is a URL with get parameters , and it represents a query for category : Featured with Slug : featured3 .
As for itself , it is NOT a page , it is a Query ( and i suspect that it is a plugin or theme related ). The query later produces , or renders a page .
At any rate , my advice still stands , Put a dummy code inside all the template pages and see which ones is your page .
For the rest - if you will supply more info or code , people could help more .
You have to check the Wordpress Template Hierarchy, a quick guess would be single.php from the active theme, but there is no way to be sure other than actually searching in the theme

Wordpress theme name inside theme php files, what is the purpose of this?

I've been building basic themes now for nearly a year, and I'm trying to clean up my style as much as possible. But I don't know where to look to find out what this does...
In the kubrick theme php files, for example you get a php tag like this...
<?php the_content('<p class="serif">' . __('Read the rest of this entry »', 'kubrick') . '</p>'); ?>
You see the theme name 'kubrick' weaved in. What is the purpose of this?
You see it in all themes, twentyten, twentyeleven, etc.. but I never notice a difference if I leave it the same. What benefits does this have if I change it to my current theme name?
Can anyone enlighten me? or point me in the right direction?
Thanks
Josh
This is the 'theme text domain' and is typically used for localization. You can find out more by reading the gettext filter reference. One note is that the text domain is not required to be the same as your theme name. You can make it whatever you want as long as you are consistent with what you load using load_theme_textdomain. It's just convention to make it the same as your theme name. Finally, as to why you should bother including a domain here is a quote from an article called How to localize WordPress themes and plugins with GetText:
Have you noticed the 2nd argument in the GetText calls? It’s an
optional argument that tells GetText what the scope (domain) of the
texts is. If supplied, this GetText will return the translations only
from the dictionary that you supply with that domain name. Although
optional, specifying the translation domain is highly recommended.
Without it, GetText might return a different translation, if the same
string also appears in a different plugin, or in WordPress.

Drupal7: Trying to theme a specific page using a preprocess function, but...I get a blank screen instead

I've just discovered that if you want to alter a specific page (or group of pages) all you need is to add templates file to the core templates. For instance, I need to theme my /helloword page using a page--helloworld.tpl.php and node--helloworld.tpl.php template files.
Now all I get is a blank screen so I tried to write a preprocess function that adds support for custom theme files like:
<?php
/**
* Adding or modifying variables before page render.
*/
function phptemplate_preprocess_page(&$vars) {
// Page change based on node->type
// Add a new page-TYPE template to the list of templates used
if (isset($vars['node'])) {
// Add template naming suggestion. It should alway use doublehyphens in Drupal7.
$vars['template_files'][] = 'page--'. str_replace('_', '-', $vars['node']->type);
}
}
?>
I see no syntax error but I still get a blank screen. Still no luck
Is someone able to figure out what's wrong in the code/routine?
Drupal7 + Omega Sub-Theme
Kind Regards
I think there's a tiny bit of confusion here: a template file named node--type.tpl.php will automatically be called for any node which has the type type...you don't need to add the template suggestions in yourself.
There is one caveat to this, you have to copy the original node.tpl.php to your theme folder and clear your caches otherwise Drupal won't pick it up.
Also you don't want to use the phptemplate_ prefix...rather you want your function to be called MYTHEMENAME_preprocess_page.
Your code to add the page template based on the node type looks spot on, see if you still have the problem after you change your function name and clear the caches.
Hope that helps :)

How to quickly theme a view?

I've defined a view with the CCK and View 2 modules. I would like to quickly define a template specific to this view. Is there any tutorial or information on this? What are the files I need to modify?
Here are my findings: (Edited)
In fact, there are two ways to theme a view: the "field" way and the "node" way. In "edit View", you can choose "Row style: Node", or "Row style: Fields".
with the "Node" way, you can create a node-contentname.tpl.php which will be called for each node in the view. You'll have access to your cck field values with $field_name[0]['value']. (edit2) You can use node-view-viewname.tpl.php which will be only called for each node displayed from this view.
with the "Field" way, you add a views-view-field--viewname--field-name-value.tpl.php for each field you want to theme individually.
Thanks to previous responses, I've used the following tools :
In the 'Basic Settings' block, the 'Theme: Information' to see all the different templates you can modify.
The Devel module's "Theme developer" to quickly find the field variable names.
View 2 documentation, especially the "Using Theme" page.
In fact there are two ways to theme a view : the "field" way and the "node" way. In "edit View", you can choose "Row style: Node", or "Row style: Fields".
with the "Node" way, you can create a node-contentname.tpl.php wich will be called for each node in the view. You'll have access to your cck field values with $field_name[0]['value']
with the "Field" way, you add a views-view-field--viewname--field-name-value.tpl.php for each field you want to theme individually.
Thanks to previous responses, I've used the following tools :
In the 'Basic Settings' block, the 'Theme: Information' to see all the different templates you can modify.
The Devel module's "Theme developer" to quickly find the field variable names.
View 2 documentation, especially the "Using Theme" page.
A quick way to find the template files you can create and modify for a view in Views 2.0 is to:
Edit the view
Select the style (e.g. page, block, default)
In the 'Basic Settings' block click on 'Theme: Information' to see all the different templates you can modify.
The Devel module's "Theme developer" feature is handy for seeing what template files Drupal is looking for when it goes to theme something. See the screenshot on that page for an example.
You should also check out Semantic Views. For simple Views theming, it is really handy.
One tip:
You'll likely have a number of views which require similar formatting. Creating templates for each of these views and copying them creates a nightmare of code branching - if you're asked to change the whole look and feel of the site (implying changing the display of each of these views formatted in this particular way), you have to go back and edit each of these separately.
Instead of using the views interface to select new templates for views, I sometimes simply insert some code branching into a single views file. E.g. for one site in views-view-fields.tpl.php I have:
if($view->name == 'articleList' || $view->name == 'frontList'
|| $view->name == 'archiveList') {
/* field formatting code */
} else {
/* the default code running here */
}
This then modifies the fields in the way I want only for this family of Views = articleList, frontList and archiveList - and for other views using this template runs the code one normally finds in this template. If the client asks, "Hey, could you make those pages showing the archives & that list on the front page to look more like ( ... )", it's simply a matter of my opening & editing this one file, instead of three different files. Maintenance becomes much more quick & friendly.
for me block-views-myViewName-myBlockId.tpl.php works
My shortcut option.
Go to theme.inc file in YOUR_MODULE_DIR/views/theme/ folder.
In the _views_theme_functions function print the $themes variable or put a breakpoint on the last line of the function to see the content of the variable.
Just convert views_view to views-view and __ to -- and add your template extension to get desired file name.
For example if an element of the $themes array is views_view__test_view__block (where test_view is the name of your view) then the name of the template file would be views-view--test_view--block.tpl.php.
In my opinion the simplest way to decide which template file to use for theming the views is :
1) Click on admin/build/views/edit/ViewName -> Basic Settings -> Theme
Clicking this would list all the possible template files. Highlighted (File names in Bold) files indicate which template file is being used to do theme what part of the view. After incorporating the required changes in the relevant view template file RESCAN .. now you should be able to see the changed template file highlighted .
If you want to do quick Drupal development with a lot of drag-and-drop, the Display Suite module def. is a something you should use: http://drupal.org/project/ds
According to me there are two ways to do it:
Programatic Way:
Go to edit view.
Select page/block style.
Go to 'Basic Settings' and click on 'Theme: Information' to see all the different templates you can modify.
Add the html you want to theme and print the variables of the view wherever needed
Configuration Update: The Display suite provides us an option to place your labels inline or above and add even to hide them. Custom classes to each of the view's elements can be added too.
Advanced options include:
Exportables
Add your own custom fields in the backend or in your code
Add custom layouts in your theme (D7 only)
Change labels, add styles or override field settings (semantic fields).
Full integration with Views and Panels
Extend the power of your layouts by installing Field Group
Optimal performance with Object cache (D6) or Entity cache (D7) integration

How do you remove the default title and body fields in a CCK generated Drupal content-type?

When you create a new content type in Drupal using the Content Creation Kit, you automatically get Title and Body fields in the generated form. Is there a way to remove them?
If you're not a developer (or you want to shortcut the development process), another possible solution is to utilize the auto_nodetitle module. Auto nodetitle will let you create rules for generating the title of the node. These can be programmatic rules, tokens that are replaced, or simply static text. Worth a look if nothing else.
To remove the body edit the type, expand "Submission form settings" and put in blank for body field label. For title you can rename it to another text field. If you really have no need for any text fields you can create a custom module, say called foo, and create function foo_form_alter() which replaces $form['title'] with a #value when $form['type']['#value'] is your node type.
No need to install anything:
when editing the content type, press "Edit"
(on the menu of Edit | Manage fields | Display fields )
click on the Submission form settings
on the Body field label:
Leave it blank, it would remove the Body field.
If you're not a developer (or you want
to shortcut the development process),
another possible solution is to
utilize the auto_nodetitle module.
Auto nodetitle will let you create
rules for generating the title of the
node. These can be programmatic rules,
tokens that are replaced, or simply
static text. Worth a look if nothing
else.
And to add on to William OConnor's solution...
The module is poorly documented unfortunately. It's really only effective if you use PHP with it in my opinion. Check off the "Evaluate PHP in Pattern" and type into the "Pattern for the title" field something like:
<?php echo $node->field_staff_email[0]['email']; ?>
or:
<?php echo $node->field_staff_name[0]['value'] . '-' . gmdate('YmdHis'); ?>
...where I had a field with an internal name of "field_staff_email" and was using the CCK Email module -- thus the 'email' type was used. Or, I had a field with an internal name of "field_staff_name" and was just an ordinary text field -- thus the 'value' type was used. The gmdate() call on the end is to ensure uniqueness because you may have two or more staff members named the same thing.
The way I discovered all this was by first experimenting with:
<?php print_r($node); ?>
...which of course gave crazy results, but at least I was able to parse the output and figure out how to use the $node object properly here.
Just note if you use either of these PHP routines, then you end up with the Content list in Drupal Admin showing entries exactly as you coded the PHP. This is why I didn't just use gmdate() alone because then it might be hard to find my record for editing.
Note also you might be able to use Base-36 conversion on gmdate() in order to reduce the size of the output because gmdate('YmdHis') is fairly long.
The initial answers are all good. Just as another idea for the title part... how about creating a custom template file for the cck node type. You would copy node.tpl.php to node-TYPE.tpl.php, and then edit the new file and remove where the title is rendered. (Dont forget to clear your cache).
Doing it this way means that every node still has a title, so for content management you aren't left with blank titles or anything like that.
HTH!

Resources