| Project: | Refine by taxonomy |
| Version: | master |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
Hi
I've just found your module and I'm really impressed, it's really powerfull and easy to use. I just have one suggestion, I think the module should show clearly wich terms are you using for your query.
For example, if you go through:
taxonomy term: BLUE, refine by item: CARS
...the user should see clearly he is watching nodes with BLUE+CARS terms. If the user continue adding more terms, the new terms should be added to this string.
Another great feature could be a "remove term" minibutton (or something like that) in that string to remove each of those terms whenever the user want.
I think this two features could add more human friendly surfing to this module.
Thanks in advance and congratulations for this great module.
Comments
#1
Hi
I solved two issues using views module and some php code inside the header. Here are the steps:
1.- Create a taxonomy view to override the default one.
2.- Inside that view header include some php code to read and output current view arguments. Since Refine by Taxonomy uses term ids (tid) as arguments, we also need to convert from those tids to the real term names.
3.- For each term in the argument, use the rest terms to recall the same taxonomy view without this term (i.e. A,B,C, to remove A, simply call B,C)
And now some code, I don't know much about php so it may have some errors:
<?php
global $current_view;
$total_terms_tids_array = explode (',', $current_view->args[0] );
$total_terms_tids_array_bis = $total_terms_tids_array;
foreach ($total_terms_tids_array as $term_tid) {
$term_object = taxonomy_get_term($term_tid);
$total_noterms_tids_array = array (); //"no terms" array reset
foreach ($total_terms_tids_array_bis as $position => $noterm) {
if ($noterm != $term_tid) {
$total_noterms_tids_array[$position] = $noterm;
}
}
$total_noterms_tids = implode (',', $total_noterms_tids_array);
$output .= '<div class="term-tag">
<div class="term-tag-left">
</div>
<span class="texto-etiqueta">~ ' . $term_object->name . ' ~';
if ($total_noterms_tids) {
$output .= ' <a href="/taxonomy/term/' . $total_noterms_tids . '" title="Delete this tag from the search."><img src="/sites/all/themes/pg-v1/imagenes/etiqueta-borrar.gif" /></a>';
}
$output .= '</span>
<div class="term-tag-right">
</div>
</div>';
}
print $output;
?>
I still have to improve it, but it works...
You can see this header working here: http://pixelgordo.com/taxonomy/term/73%2C80
Seriously, sorry for this crappy code, I put it here because it could help someone and tomorrow I'm on a trip and I won't post any progress for a couple of months.
#2
Hi Macarro,
I tried to follow your instructions but I'm not able to get it to be shown.
Do you add the php in the field 'Argument Handling Code' ?
#3
Hi.
Sorry for the poor explanation, I totally forgot that.
No, you have to put this code in the header section.
#4
Ah great !
It works now. :)
Thank you.
#5
I made this small addition to prevent it to show the term name with only one term chosen for reasons of SEO keywords stuffing. If you use a standard views taxonomy_term the current term name is shown above the nodes with h1 tags like this
<h1 class="title">Term name</h1>. I believe adding an extra term name below could harm rankings. (I have blocked searchengines from accessing the refine by taxonomy listings in robots.txt).This is the small code I added:
if ($total_noterms_tids) { //Only do the following if more than one term is chosenprint $output;
}
?>
Thanks for sharing, Macarro. :)
Edit:
Change from $total_noterms_tids to $total_noterms_tids as the first one will not work for term id 1.
#6
Here is a cleaner and more user friendly version:
STEP 1: Put this code inside your template.php, you can change the "configuration" of the function easily to add the HTML markup you want. (notice the leading '< ?php' and ending '? >' should not be copied)
<?php
/****************************************************************************************************************************************************************************
Function to show deletable tags in taxonomy view. You need to have "Refine by taxonomy" and "Views" modules installed.
*****************************************************************************************************************************************************************************/
function phptemplate_deletetags ($args) {
/** Main configuration **/
$taxonomy_url = 'taxonomy/term/'; /** Do NOT put the leading /, it'll corrupt the delete link **/
$delete_link_text = 'x'; /** The text you want to use for delete link (it could be 'delete', for example) **/
$html_intro = array (
'<h1 class="title">Articles with tags</h1><p>Choose any tag at the bottom of the page to filter the results.</p>',
'<h1 class="title">Articles with the following tag ',
'<h1 class="title">Articles with the following tags ');
$html_ending = array(
'',
'</h1>',
'</h1>');
$html_tag_front = '<div class="refine-tag">'; /** Output deletable tag will look like [html_front] TAG [html_middle] DELETE_LINK [html_back] **/
$html_tag_middle = ' ('; /** So you can theme the output tags however you want using this three html fields **/
$html_tag_back = ')</div>'; /** ... **/
$delete_link_description = 'Eliminar la etiqueta "[TAG]" de la búsqueda'; /** Delete link description text wich appears on mouse over the links **/
/** Main configuration end **/
$tids = explode(',', $args[0]);
$custom_terms = array();
foreach ($tids as $key => $tid) {
$term = taxonomy_get_term($tid);
/** $notids_string creation **/
$notids = $tids; /** copy of every tid to keep the original vector untouched **/
unset($notids[$key]); /** deletion of current record in the copied vector **/
$notid_string = implode(',', $notids);
/** end of $notids_string creation **/
$custom_term = array('tid'=>$tid, 'tname'=>$term->name, 'notid'=>$notid_string);
array_push($custom_terms, $custom_term);
}
print '<pre>';
print_r ($custom_terms);
print '</pre>';
if (count($tids)==1 && $tids[0] == 'all') {$output .= $html_intro[0];}
elseif (count($tids)==1) {$output .= $html_intro[1];}
elseif (count($tids)>1) {$output .= $html_intro[2];}
if ($custom_terms[0]['tid']!='all') {
foreach ($custom_terms as $custom_term) {
$delete_link_description_variable = $delete_link_description;
$delete_link_description_variable = str_replace('[TAG]', $custom_term['tname'], $delete_link_description);
if ($custom_term['notid']=='') $custom_term['notid']='all'; /** If tid = '' then tid='all'. This fixes a "bug" with empty argument taxonomy views **/
$delete_link = l($delete_link_text, $taxonomy_url . $custom_term['notid'], array('attributes'=>array('title'=>$delete_link_description_variable, 'description'=>$delete_link_description_variable)));
$term_tag = $html_tag_front . $custom_term['tname'] . $html_tag_middle . $delete_link . $html_tag_back;
$output .= $term_tag;
}
}
$output .= $html_ending;
print $output;
}
?>
STEP 2: Edit your taxonomy view header and add this php code in the header section
<?php$view = views_get_current_view();
phptemplate_deletetags($view->args);
?>
STEP 3: Modify the argument for your taxonomy view to accept wildcard parameter 'all' (yes it have to be 'all' since this is harcoded into my code)
RESULT: You'll end with something like this in your taxonomy view header
Clicking over the X you remove the tag (Actually you reload the view using the rest arguments).
UNSOLVED BUG(S): I need to check the code because there is still a bug present. I allow to remove the last term, so every node will be listed in the taxonomy view. I like it because it helps to surf the web.
Problem 1:
...FIXED
Problem 2:
My taxonomy view URL is taxonomy/term/% and it accepts null argument but I always get a 404 error page when I try to load the view with no argument. (It seems it's impossible to create null argument taxonomy view works) => Partially solved using wildcard argument but it leads to problem 3...
...FIXED
Problem 3:
If you are viewing the taxonomy view with no arguments, taxonomy filters are not shown. I think this should be solved in the module. => It seems the line #146 at refine_by_taxo.module nees to be changed:
<?phppreg_match('/^([0-9]+[+, ]?)+$/', arg(2))) {
//url starts with taxonomy/term
//and contains a number, or a 123,1456 type combination.
?>
....let's see what happens.
#7
After an extra bit of CSS here is a screeshot of the final result...
I still have to modify the module to show filter blocks without terms and I'm going to see if I'm capable of creating a .diff patch for the module.
Regards.
UPDATE:
STUCK, STUCK, STUCK... I´ve never been able to deal with regex and there are five entries in this module:
#146 preg_match('/^([0-9]+[+, ]?)+$/', arg(2))...
#271 preg_match('/^([0-9]+[+ ])+[0-9]+$/', arg(2))
...
#276 preg_match('/^([0-9]+,)*[0-9]+$/', arg(2))
...
#296 preg_match('/^([0-9]+[+ ])+[0-9]+$/', $str_tids)
...
#299 preg_match('/^([0-9]+,)*[0-9]+$/', $str_tids)
UPDATE:
I've been turning it over in my head during dinner and I think my approach is not ok. Refine by taxonomy is mean to be a filter for related contents but if you have no terms, wich would be the related terms? So I'm going to remove the ability to remove the last term or, maybe, create an extra block with the top most popular terms in my site (using another view).
Regards.