I have a View that outputs a page. Under Basic Settings I set a "title". When I load the page, I see that title as the page title (at top of the browser) - all good.
How can I print this value out in the "Display output" .tpl file? The $title variable doesn't seem to hold any value here. Do I need to use a preprocess function?
Thanks
Does drupal_get_title() work?
You can get the details of the full view using
You can get the title of all the displays there
$view2=views_get_current_view();
$view2->display['default']->display_options['title'];
If you just want to print the title than no need to write the .tpl file.
In views you will find header region and there you can add the global text are and by using it , you can add the title text over there.
Related
In my content type I have fields to display the extra related links, along with the title and body part how can I print the related links in the node page ?
You can print $node->body for displaying all the custom fields with body and title.
All you need to do is give some CSS for this.
I have several custom content types and in one specific one I need to offer two fields, one for the href for a link, and one for the text of a link this way I can build and style it with minimal user involvement of the HTML/CSS. I also have a custom node.tpl for this content type. My problem is that drupal throws divs around each field I create that aren't in my template file for this content type (node-custom.tpl) and I can't put the href for a link with divs around it inside google.co.uk</div>"> See my problem. Maybe I'm doing this all wrong so any other ideas are welcome.
Please note I'm trying to create this site with minimum involvement of HTML/CSS access for the user. I'm aware I could hand code the link in the field.
The easiest way to do this would be to use a preprocess function in your template.php file and build the link up manually:
function mytheme_preprocess_node(&$vars) {
$node = $vars['node'];
if ($node->type = 'my_type') {
$uri = $node->field_name_of_link_field[LANGUAGE_NONE][0]['value'];
$text = $node->field_name_of_display_text_field[LANGUAGE_NONE][0]['value'];
$vars['my_link'] = l($text, $uri); // Using Drupal's l() function to render a link
}
}
Then in your node template file you'll have access to the variable $my_link which you can output anywhere, and will contain the correct HTML for the link. Finally, go to the "Manage Display" page for your content type and set the display of the two fields you no longer need to output to 'Hidden'.
There are other ways so if that's no good let me know
EDIT
Just to add, I think the easiest way to do this would actually be to install the Link module and use the provided field type instead of the two other fields you're currently using.
I set a template and my default template is 2 columns and i have a page that i want to have a 1 column. How can I make that in wordpress? is it a code for the functions.php?
Please suggest and thanks in advance.
You have different options and you could choose the one you prefer :)
If your theme already supports a one-column page you should have on the right side of your edit page screen a box "Page attributes" with a select box named "Templates" when you could choose a different template (in default Wordpress theme "TwentyTen" is it called "One column, no sidebar").
If your theme doesn't support a one-column page you could create a custom page template by yourself:
copy and rename "page.php" that you could find inside your theme
in the top comments add this line: * Template Name: The name you want for your template
at the bottom of page.php remove the line <?php get_sidebar(); ?>
now you should have the new template in the side panel "Page attributes".
If you don't like the "new template + select box" way you could directly add a "IF" on your "page.php" to comment-out the get_sidebar() when needed, based on $post->ID or similar checks.
After this probably you'll have to edit your .css (adjusting width) and new-page.php (like adding a class "one-column" to the div container) to fit the dimensions.
Go to the edit page area of the page you want to have single column. Under templates (in the right hand side bar) look for "single column" or "full width" page.
90% of themes have this. If yours does not, you would have to take page.php, download it. Duplicate it and rename it to fullwidth-page.php and reupload. Make sure the comment area at the top is right according to the "page template codex" in wordpress.org. Then, delete out wehre it calls the sidebar() code. Add a bit more inline CSS to the main content area to make the inline style width the full width then.
I want to add some functionality to my Drupal 6 module: I want to insert an image next to certain node titles (it involves a span and an img tag). I thought I could do this by just implementing mymodule_preprocess_node() and modifying the title. However, Drupal strips out all tags to avoid XSS attacks.
I've seen many solutions that involve the theme layer (most commonly http://drupal.org/node/28537), but I want to do this in my module, not in the theme. I don't want to modify any .tpl.php files or template.php. Can anyone give me tips on how to do this?
You mention that you've tried preprocess_node(), and are correct that, if you are storing the img tag as part of the node title, Drupal will indeed strip that out, as it runs $node->title through check_plain in template_preprocess_node().
My suggestion would be to store the actual image as an image field (using some combination of the imagefield module and imagecache for sizing), set the display of that field to be hidden on the CCK display tab for the given content type, and then attach the image to be part of the $title variable in your module's preprocess function. This solution would also allow you to display that image next to the title in any views you may need to create.
By 'certain node titles' - do you mean all nodes titles from certain node types?
If so, you can likely style the node using only CSS. By default all nodes will have a class that corresponds to the node type. Using CSS background images, you can add an image to the node title.
Your module can call drupal_add_css and add in any required CSS into the page. This way, it is theme independent.
I think the easier way is with javascript / Jquery.
You create a Jquery script which is called only in certain types of nodes and pass the number of views from drupal to the jscript.
You can call drupal_add_js() inside your module_preprocess_node and pass a variable which contains the number of views or the image link to the script. Something like this:
<?php
drupal_add_js("var mymodule_imagelink = " . drupal_to_js($imagelink) . ";", 'inline');
drupal_add_js("my_js_file.js");
?>
then in my_js_file.js just change the text. There are several ways to acomplish this. For instance, you can do a search in the document and change the title to something else or you can use a determined ID, etc...
Find text string using jQuery?
http://api.jquery.com/replaceWith/
I have two content types, book and chapter. Each chapter node contains a node reference of the book to which it belongs. I have created a view which displays the title of each chapter for a given book. Within the view, the title field has been configured to link to its node.
All works well. I am now interested in updating the view to not display a link to a chapter's node when the chapter's body is empty. Thus this view would display a list of chapter titles for a book and link only to those chapters that have a body.
Can this be accomplished using out of the box Views functionality? If not, how would something like this be accomplished?
Thanks.
I'd use the Views Custom Field module to implement your custom logic. It allows you to grab the data fetched by Views and manipulate it at will with PHP. Very handy.
I'm answering my own question because my response to ceejayoz is poorly formatted.
What I did to accomplish this was to first download and enable views_customfield. Second, I placed Title and Body fields within the view, both excluded from display. Third, within a Customfield: PHP code field I placed the following code:
<?php
if (strlen(trim($data->node_revisions_body)) == 0) {
return $data->node_title;
} else {
return l($data->node_title, drupal_get_path_alias('node/' . $data->nid));
}
?>
There's also this clever workaround which allows you to achieve this very easily:
Add 2 title fields one with link and one with no link, and make both
them exclude from display.
Add body field,
In No result behavior put title with no link replacement token to
it.
In Rewrite results behavior put title with link replacement token to
it.
Tick hide if empty.
Source