Imagecache for non image CCKs? - drupal

I'm creating a view with images, videos, audio and documents (books) and I like to shown a picture of each of them in a carousel.
Everything works nicely with images and videos as far as we added a image-thumbnail (image filefield) to their CCK but we like to show a default image for audio and documents without changing the original CCK. Is it possible with imagecache (may be with imagecache_custom_code or views_custom_php) or we need to look for a different approach?
Thanks for your help,
m.

You are able to do this from two places.
First, you can go into Display Fields part of the CCK content type settings and change its default display in the teaser and node view. You will be given all the current imagecache presets as sizing options for display.
Second, you can also change the output as part of Views. Adding the image as a Field to show will give you the same set of preset options.

I'm going to say something very similar to Kevin above but I think it's the solution your looking for. To understand the problem:
you have 3 content types, two have thumbnails that you set individually
for the third you would like to have a default image displayed but not have to set it
I think you should still use a cck field.
Add a cck field for the image
Set a default image for that cck field (http://screencast.com/t/YzA0OWY4Mz)
Set your imagecache from the display tab
Hide the cck field from node edit for using http://drupal.org/project/formfilter, http://drupal.org/project/cck_field_perms, or hook_form
I might be mis-understanding your issue though.

Thanks for your both for your help.
I think you should still use a cck field.
You took a good picture of the scenario, but this is exactly the point of what I was trying to avoid. :-)
I don't want to use a cck field for books and I don't want to hide it with hook_form_alter.
I think I finally found a solution that didn't require adding extra CCK-fields to my "non-image" content types (audio and text).
There is a module called "Views custom field" (drupal.org/project/views_customfield) that allows you to add a PHP-processed-field to your view, so you can filter by content type and apply imagecache or imageapi code
$node=node_load($data->nid);
$img_path=drupal_get_path("module", "gt_medias") . "/images";
switch ($node->type) {
case "gt_video":
$img_path = $node->field_gt_thumbnail[0][filepath];
break;
case "book":
$img_path .= "/bookDefault.jpg";
break;
case "gt_audio":
$img_path .="/audioDefault.png";
break;
case "pingv_image":
$img_path = $node->field_pingv_image[0][filepath];
break;
}
$imgcache_url = imagecache_create_url('gt_medias_video_346', $img_path);
$output .= '<img src="'. $imgcache_url .'" ' />';
return ($output);
Where "gt_medias_video_346" is the name of my imagecache preset.
Once again, thanks you both for your help,
m.

Related

Display a random image from an image field

I have an image field on my content type that can accept 5 images to be uploaded. I would like for just one of them (at random) to be displayed on my page. Is there a module that can create a display formatter that will do this? Or is there a way I can accomplish this in my page.tpl.php?
Figured it out..
$imgCount = count($node->field_header_image[$node->language]) - 1;
$randomNum = rand(0,$imgCount); echo $randomNum;
echo file_create_url($node->field_header_image[$node->language][$randomNum]['uri']);
You could give Single Image Formatter a try, from its drupal project page it allows you to define which image to display. Providing an index which will never exist (6 if you can upload up to 5 images) it will choose a random image. Sounds like it could do the job.

How to hide title from page node Drupal

I'm trying to remove the title of a page node on Drupal. I have this page:
And I want it to look like this:
As you can see, I want the title to be removed, but only for taxonomy terms. If I try to erase it using CSS, I erase al page-titles, so I wanted to use this module, that allows administrators to auto-generate node titles and hide it.
I go to structure -> type content -> my type content, and edit it. I activate the module, and I want to auto-generate titles depending on the node category. I think it should look like this, but it doesn't work...
Any ideas why?
EDIT: Sorry, I forgot to say: yes, when I activate the module, use it, and select the category as the auto-generated title, it works. But it doesn't hide the title...
It also launches this mistake:
Use Exclude Node Title module.
https://drupal.org/project/exclude_node_title
Setting for this module:
Click on Module->Exclude node title->configure
Home » Administration » Configuration » Content authoring
Select All nodes from Basic Page
Check Full Content for hide title from all cms page except home page
Check Teaser for hide title from home page.
If you want to remove the title, you should look into overriding the page and node templates.
page.tpl.php and node.tpl.php
All you need to do is click "View Source" on both of those and copy them to your theme folder. From there you can modify both as required.
From what I can gather, you'll want to remove the print $title from your node.tpl.php.
Have the similar issue before, as far as I remember, I just added some if statement to the code:
<?php if (blah-blah-blah): ?>
<h2> <?php echo $title; ?> </h2>
<?php endif; ?>
Hope, it'll give you a clue.
Some other thoughts: you can make an if statement or rewrite it not only in page.tpl.php but create some specific page-node-type.tpl.php file and overwrite only its $title, or you can try to customize page's output via Views/Panels modules as well.
Also, could you please make more clear, what title do you want to remove? Page title or node title? And it should be removed only when you are looking nodes associated with some taxonomy term (in other words, when you are on /taxonomy/term/n page), am I right?
By using the Context module, you can add classes to the body so you can target just the taxonomy pages in CSS.
Using Context module to set body classes
Sorry guys, it was as easy as hide title tag on "manage presentation"...
You are all right on your responses, but they were not exactly what I needed... thanks!
Use Exclude Node Title module.
https://drupal.org/project/exclude_node_title
another nice solution for specific nodes, is to use the standard $title_prefix/suffix vars, which should be implemented by every theme. using the standard class element-invisible in page preprocess ..
like:
/**
* Implements hook_preprocess_page().
*/
function YOUR_THEME_preprocess_page(&$variables) {
if (isset($variables['node']) && $variables['node']->nid == 1) {
$variables['title_prefix'] = array('#markup' => '<div class="element-invisible">');
$variables['title_suffix'] = array('#markup' => '</div>');
}
}
Every page should contain a heading.
You should always maintain a structured hierarchy of headings within any web page. You should never have a blank heading or even hide it with display:none;. Hiding any content which isn’t viewable by your visitors but is by search engines is against Google’s guidelines as your intention is to only manipulate search engine results by including it. Restyle a H1 so it fits into your design is the best option.
If you still have to hide it then a better option would be to either create a template for that node, content type or page and simply not print the heading.
Or if you want to use CSS then use position:absolute so the heading doesn’t use any space where it is located in the page and text-indent:-9999px; so the text is moved off the screen and no longer visible but at least can be read by screen readers and search engines.
This is how I did it, Switch statement
// Get the name of node
$node_name = node_type_get_name($node);
// Then just add the content types you wish to exclude by overwriting the // $title object with an empty string
switch ($node_name) {
case 'Home page':
$title = '' ;
break;
case 'Event':
$title = '';
break;
case 'Offer':
$title = '';
break;
}

Add HTML to node title in Drupal module, not in theme layer

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/

best way to give editors ability to assign background images in drupal 6

I've got a design in drupal that calls for a different background image on different pages. I'd like to make it easy for the site editors to assign the image. My first thought was adding a cck field to the Page type where they could assign the image. That will work nicely for node pages, but won't work for views pages. I guess instead of creating the views pages directly, I could wrap them in nodes.
My other idea is to create a BGImage cck type, and then some kind of matrix page where they can assign a given BGImage node to a content node or view, but that sounds complex.
Any better ideas out there? (In a way, this is akin to controlling block visibility, I suppose.)
After creating a content type to use as a repository for background images, I think that it would be a fairly quick module to give you a block with dropdown box to choose from uploaded images.
Look up hook_block for the only hook you'll need.
if $op == view
pseudocode follows (but it should be clear enough to go on)
$res = db_query('select field_my_image_fid FROM {mycontenttype}');
while ($img = db_fetch_obj($res) {
$my_content .= $img->whatever
return array(
'subject' => '<none>',
'content' => $my_content
)
I would indeed suggest to wrap them into nodes, the Views Attach Module might help here.

How would you recommend adding an image as a custom field in WordPress?

I need to add an image to each page in WordPress.
I don't wish to insert it using the WYSIWYG editor, I just need the url as a custom field, which I later use in the template.
I tried using the CFI plugin (Custom Field Images), and I hacked my way into getting it to work with the rest of my plugins, but then I moved the site to the production server and CFI just didn't work for some reason.
I can't seem to find any other plugin that just lets you pick an image from the library and add it as a custom field.
I've downgraded to the point where I'm willing to manually enter all the URLs into each and every page. but before I do, I thought I'd check here.
Can anyone tell me what's the easiest, best way to add images as custom fields in WordPress (2.7.1 if it matters)?
In our WordPress template, each post generally only has one image 'attached', which is displayed outside the posts' (textual) content.
I simply upload the file using the edit posts' media uploader, never insert it into the post like JoshJordan above, then retrieve the image using a bit of code in the right place in my template file.
This would also work if you're using more than one image in your post, eg. in your post content. As long as you keep the image used as the 'main' post image as the first image (remember you can re-order images in your posts' image library by dragging them up and down), you're easily able to call it anywhere in your template file by using something like this:
<?php
$img_size = 'thumbnail'; // use thumbnail, medium, large, original
$img_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts where post_parent= $post->ID and (post_mime_type = 'image/jpeg' OR post_mime_type = 'image/gif') and post_type = 'attachment'");
$img_array = wp_get_attachment_image_src($img_id,$img_size,false);
echo '<img src="'.$img_array[0].'"' title="'.get_the_title().'" />';
?>
No need for copying and pasting image urls.
The template I have uses a manually-entered custom field for the splash image of each post. When I'm done writing my article, I upload an image, copy its URL from the upload tool, never insert it into my post, and then paste that URL into the "Image" custom field. Simple as pie and takes only seconds. Insignificant compared to the amount of time it takes me to write an article.
You can use the custom key value fields on posts as well. let's say you always give your images the key 'thumb'. you can then use this code to output them in your post as a thumbnail:
<?php
$values = get_post_custom_values("thumb");
echo “<img src=\”$values[0]\” class=\”thumb\”></a>”; ?>
Consider using Flutter it's a bit tricky to figure out at first, and has many really useful featured, including EIP (edit in place), and image handling.
After installing the plugin create a new "Write Panel", you'll figure it out from there. The plugin provides you with a rather intuitive GUI, which includes an image uploader. The template tags are very easy to use, I believe it's something like
<?php echo get_image('name_of_field'); ?>
I just had to build a site for a client that needed the same feature, I ended up using Flutter.

Resources