Hello,
I am trying to get the taxonomy images to display on the Views Summary page, but to no avail. Basically, it's a list of company names, and I want to replace the names with their logos. I'm not much use at programming. Could someone please tell me how I might solve this problem?

Comments

neillodwyer’s picture

Assigned: neillodwyer » Unassigned
RKopacz’s picture

Subscribing. I would also like to be able to do this. Is there any way to do this programmatically, that anyone knows? The view should be calling in the tid's, and I was thinking that it is possible with taxonomy_display_image() that comes with Taxonomy Image, but I can't seem to be able to find the right variables to call in as parameters.

RKopacz’s picture

Hey, I don't know if this is just obvious, but just in case somebody is looking for a solution to this, here's what I did to get a taxonomy image into the views summary page, when taxonomy terms are used as arguments, using the Taxonomy Image module (which must be enabled, of course).

First you need to pull out the views summary template. its in the folder for the Views module. There are two, one for unordered lists and one for unformatted fields. I used unformatted fields:

views-view-summary-unformatted.tpl.php

The inside of that template looks like this:

<?php foreach ($rows as $id => $row): ?>

  <?php print (!empty($options['inline']) ? '<span' : '<div') . ' class="views-summary views-summary-unformatted">'; ?>
    <?php if (!empty($row->separator)) { print $row->separator; } ?>
    <a href="<?php print $row->url; ?>"<?php print !empty($classes[$id]) ? ' class="'. $classes[$id] .'"' : ''; ?>><?php print $row->link; ?></a>
    <?php if (!empty($options['count'])): ?>
      (<?php print $row->count; ?>)
    <?php endif; ?>
  <?php print !empty($options['inline']) ? '</span>' : '</div>'; ?>
<?php endforeach; ?>

The function used to display the taxonomy image is taxonomy_image_display($tid). You get the relevant term id variable from within the view by pulling the variables using the devel module and the dpm() function that comes along with it, and a special preprocess function for the summary view, which you place in your template.php file (put your theme name in place of 'themename' in the function:

function themename_preprocess_views_view_summary_unformatted(&$vars) {
  
  dpm($vars);

}

It took me a while to find this, but the way to get the variable holding the relevant term id is with the following:

$row->term_node_tid.

So, within the template for the views summary, you would need to insert that variable as a parameter for the taxonomy_image_display() function to call the image into the template:

taxonomy_image_display($row->term_node_tid)

You now need to just wrap it in some PHP tags with a print function before it, and then, just for good order, wrap that in a div with a class selector, and your image should display.

<div class="image"><?php print taxonomy_image_display($row->term_node_tid); ?></div>

The code inside the views summary template will now look like this:

<?php foreach ($rows as $id => $row): ?>

  <?php print (!empty($options['inline']) ? '<span' : '<div') . ' class="views-summary views-summary-unformatted">'; ?>
    <?php if (!empty($row->separator)) { print $row->separator; } ?>
    <div class="image"><?php print taxonomy_image_display($row->term_node_tid); ?></div><a href="<?php print $row->url; ?>"<?php print !empty($classes[$id]) ? ' class="'. $classes[$id] .'"' : ''; ?>><?php print $row->link; ?></a>
    <?php if (!empty($options['count'])): ?>
      (<?php print $row->count; ?>)
    <?php endif; ?>
  <?php print !empty($options['inline']) ? '</span>' : '</div>'; ?>
<?php endforeach; ?>

Your taxonomy image will now display together with the link to the view page for that taxonomy term. You'll just need to add a few style properties to get it to look the way you want.

If anybody sees another way to do it non-programmatically, let me know. I haven't found one.

Hope this helps someone trying to do the same.

vlooivlerke’s picture

Hi this works great with taxonomy term Id as the argument.
How can I use taxonomy term name as the argument?

Taxonomy term name is better in search engine url

working url : taxonomy/term/123
need to do url like this: taxonomy/term/fruit

Thanks

vlooivlerke’s picture

Hi, I used the devel module and your steps to inspect the view.

The term name argument make use of the term_data_name table

term_node_tid (Array, 3 elements)
field (String, 3 characters ) tid
table (String, 9 characters ) term_node
alias (String, 13 characters ) term_node_tid

term_data_name (Array, 3 elements)
field (String, 4 characters ) name
table (String, 9 characters ) term_data
alias (String, 14 characters ) term_data_name

How can I add the term_node_tid field to the taxonomy name argument

vlooivlerke’s picture

After doing some inspection I noticed that the table term_data is used in every taxonomy argument but the the table term_node is only used in arguments were you use the term ID.

The table term_data has a row tid. How can I set the taxonomy image if I know the name of the term in the argument

something like

db_query("SELECT tid FROM {term_data} WHERE name ....

that can then print this

<?php print taxonomy_image_display($row->term_data_tid); ?>