Hello again. First off, great module. I've created a custom theme and it's coming along really well. I'm a little green when it comes to PHP and I've been trying to figure out how to make the image clickable and the title of the slide link to the associated node like the "read more" button does.

I assume this functionality would be done in the preprocess functions.

          $slider_items[$key1]['slide_read_more'] =  l('READ MORE', 'node/' . $result->nid);
          $slider_items[$key1]['slide_node'] =  'node/' . $result->nid

I assume the second line of the above code is what creates the link to the node. But I'm not sure how to get the title and image field to link to the node as well. Does anyone have any advice? Thanks.

CommentFileSizeAuthor
#10 template.php.txt5.98 KBppblaauw

Comments

ppblaauw’s picture

I hope you use version 6.x-1.x-rc6.

The l() functions makes the link of the read more button.
First parameter is the link text, the second parameter is the URL to link to

For linking the title to the node you can use

        // add slide_title variable
        if (isset($result->node_title)) {
          $slider_items[$key1]['slide_title'] =  l($result->node_title, 'node/' . $result->nid);
        }

For linking the image to the node you can use

        if (module_exists('imagecache') && is_array(imagecache_presets()) && $vars['imgcache_slide'] <> '<none>'){
            $slider_items[$key1]['slide_image'] = 
            '<a href="node/' . $result->nid . '">' . theme('imagecache', 
                  $vars['imgcache_slide'], 
                  $filepath,
                  $result->node_title) . '</a>';
          }
          else {          
            $slider_items[$key1]['slide_image'] = 
              '<a href="node/' . $result->nid . '"><img src="' . base_path() . $filepath . 
              '" alt="' . $result->node_title . 
              '"/></a>';     
          }          
        }

Hope this helps you further, please let me know.

Anandyrh’s picture

Version: 6.x-1.x-dev » 6.x-1.0-rc6
Status: Active » Postponed (maintainer needs more info)

Take a look at this:
http://drupal.org/node/480532

dgautsch’s picture

Thank you everyone for the help. This helps immensely. ppblaauw you do a great job maintaining this module.

ppblaauw’s picture

@ logicalriot

Did you solve your issue?
If you did, can you set the status to fixed.
added tags

jsimonis’s picture

Where do you put the code to be able to link the image as well? Is it in place of something?

I've been trying to figure that out and get errors that keep the site from showing.

ppblaauw’s picture

You need to replace:

          if (module_exists('imagecache') && is_array(imagecache_presets()) && $vars['imgcache_slide'] <> '<none>'){
            $slider_items[$key1]['slide_image'] = 
            theme('imagecache', 
                  $vars['imgcache_slide'], 
                  $filepath,
                  $result->node_title);
          }
          else {          
            $slider_items[$key1]['slide_image'] = 
              '<img src="' . base_path() . $filepath . 
              '" alt="' . $result->node_title . 
              '"/>';     
          }          
        }

I copied also the last } which maybe causes the issue

jsimonis’s picture

Yea, that's the part I replaced. And I get an error.

Parse error: syntax error, unexpected T_STRING in /home/username/public_html/sites/all/themes/lininger/template.php on line 46

ppblaauw’s picture

Can you attach your template.php file?, so I can help you better.

jsimonis’s picture

<?php
/*!
 * Dynamic display block preprocess functions
 * Copyright (c) 2008 - 2009 P. Blaauw All rights reserved.
 * Version 1.3 (18-MAR-2009)
 * Licenced under GPL license
 * http://www.gnu.org/licenses/gpl.html
 */

 /**
 * Override or insert variables into the ddblock_cycle_block_content templates.
 *   Used to convert variables from view_fields to slider_items template variables
 *
 * @param $vars
 *   An array of variables to pass to the theme template.
 * 
 */
function lininger_preprocess_ddblock_cycle_block_content(&$vars) {
  if ($vars['output_type'] == 'view_fields') {
    $content = array();
    // Add slider_items for the template 
    // If you use the devel module uncomment the following line to see the theme variables
    // dsm($vars['settings']['view_name']);  
    // dsm($vars['content'][0]);
    // If you don't use the devel module uncomment the following line to see the theme variables
    // drupal_set_message('<pre>' . var_export($vars['settings']['view_name'], true) . '</pre>');
    // drupal_set_message('<pre>' . var_export($vars['content'][0], true) . '</pre>');
    if ($vars['settings']['view_name'] == 'news_items') {
      if (!empty($vars['content'])) {
        foreach ($vars['content'] as $key1 => $result) {
          // add slide_image variable 
          if (isset($result->node_data_field_pager_item_text_field_image_fid)) {
            // get image id
            $fid = $result->node_data_field_pager_item_text_field_image_fid;
            // get path to image
            $filepath = db_result(db_query("SELECT filepath FROM {files} WHERE fid = %d", $fid));
            //  use imagecache (imagecache, preset_name, file_path, alt, title, array of attributes)
          if (module_exists('imagecache') && is_array(imagecache_presets()) && $vars['imgcache_slide'] <> '<none>'){
            $slider_items[$key1]['slide_image'] =
            theme('imagecache',
                  $vars['imgcache_slide'],
                  $filepath,
                  $result->node_title);
          }
          else {         
            $slider_items[$key1]['slide_image'] =
              '<img src="' . base_path() . $filepath .
              '" alt="' . $result->node_title .
              '"/>';    
          }         
        }
          // add slide_text variable
          if (isset($result->node_data_field_pager_item_text_field_slide_text_value)) {
            $slider_items[$key1]['slide_text'] =  $result->node_data_field_pager_item_text_field_slide_text_value;
          }
          // add slide_title variable
          if (isset($result->node_title)) {
            $slider_items[$key1]['slide_title'] =  $result->node_title;
          }
          // add slide_read_more variable and slide_node variable
          if (isset($result->node_data_field_pager_item_text_field_url_value)) {
            $slider_items[$key1]['slide_read_more'] =  l('Read more...', $result->node_data_field_pager_item_text_field_url_value);
            $slider_items[$key1]['slide_node'] =  'node/' . $result->nid;
          }
        }
        $vars['slider_items'] = $slider_items;
      }
    }    
  }
}  
/**
 * Override or insert variables into the ddblock_cycle_pager_content templates.
 *   Used to convert variables from view_fields  to pager_items template variables
 *  Only used for custom pager items
 *
 * @param $vars
 *   An array of variables to pass to the theme template.
 *
 */
function lininger_preprocess_ddblock_cycle_pager_content(&$vars) {
  if (($vars['output_type'] == 'view_fields') && ($vars['pager_settings']['pager'] == 'custom-pager')){
    $content = array();
    // Add pager_items for the template 
    // If you use the devel module uncomment the following lines to see the theme variables
    // dsm($vars['pager_settings']['view_name']);     
    // dsm($vars['content'][0]);     
    // If you don't use the devel module uncomment the following lines to see the theme variables
    // drupal_set_message('<pre>' . var_export($vars['pager_settings'], true) . '</pre>');
    // drupal_set_message('<pre>' . var_export($vars['content'][0], true) . '</pre>');
    if ($vars['pager_settings']['view_name'] == 'news_items') {
      if (!empty($vars['content'])) {
        foreach ($vars['content'] as $key1 => $result) {
          // add pager_item_image variable
          if (isset($result->node_data_field_pager_item_text_field_image_fid)) {
            $fid = $result->node_data_field_pager_item_text_field_image_fid;
            $filepath = db_result(db_query("SELECT filepath FROM {files} WHERE fid = %d", $fid));
            //  use imagecache (imagecache, preset_name, file_path, alt, title, array of attributes)
            if (module_exists('imagecache') && 
                is_array(imagecache_presets()) && 
                $vars['imgcache_pager_item'] <> '<none>'){
              $pager_items[$key1]['image'] = 
                theme('imagecache', 
                      $vars['pager_settings']['imgcache_pager_item'],              
                      $filepath,
                      $result->node_data_field_pager_item_text_field_pager_item_text_value);
            }
            else {          
              $pager_items[$key1]['image'] = 
                '<img src="' . base_path() . $filepath . 
                '" alt="' . $result->node_data_field_pager_item_text_field_pager_item_text_value . 
                '"/>';     
            }          
          }
          // add pager_item _text variable
          if (isset($result->node_data_field_pager_item_text_field_pager_item_text_value)) {
            $pager_items[$key1]['text'] =  $result->node_data_field_pager_item_text_field_pager_item_text_value;
          }
        }
      }
      $vars['pager_items'] = $pager_items;
    }
  }    
} 
?>
ppblaauw’s picture

Issue tags: +Advanced slideshow, +preprocess functions
StatusFileSize
new5.98 KB

The code in #1 missed a quote (') after the end of the first <a> tag. Sorry for the mistake. Changed it in #1.

So your template.php becomes like the attached file.

Hope this helps you further, please let me know.

dgautsch’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Sinan Erdem’s picture

Status: Closed (fixed) » Active

The code for image in comment #1 works nicely. But it links to unaliased URL. Is it possible to link to an aliased path? Example:

İnstead of "node/34", I need "content/title"

Thanks...

ppblaauw’s picture

Status: Active » Postponed (maintainer needs more info)

#13

You can have a look at the issue http://drupal.org/node/513362

Hope this helps you further please let me know.

Sinan Erdem’s picture

Status: Postponed (maintainer needs more info) » Fixed

The code on the page you have given works perfect! Thanks for your generous help ppblaauw...

ppblaauw’s picture

Title: Make the title and image link to the node. » Make the title and image link to the node. (Fixed)

Welcome.

Changed issue title.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Sinan Erdem’s picture

Just a suggestion:

I already did what is told here and it works OK. But after that, I found another solution with just CSS. I just enlarged the area of the "read more" button to include the whole image area with changing the paddings, margins and positions etc. The class I wrote CSS code for is:

div.ddblock-cycle-plain-list30l div.slide-read-more-horizontal a{
}

Now the whole area on the image including the title, describtion etc. links to the node...

Hope it helps someone...

Anandyrh’s picture

Hi,

Check out the below link..., would help you out.

http://drupal.org/node/480532

Regards,
AnANd