How to create a second Similar Entries block?
solutionsphp - August 24, 2007 - 16:29
| Project: | Similar Entries |
| Version: | 5.x-1.2 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
I modified the first function of the module to enable a second block, but when configuring this second block, not all of the options are available to it.
function similar_block($op = 'list', $delta = 0, $edit = array()) {
switch($op) {
case 'list':
$blocks[0]['info'] = t('Similar entries');
$blocks[1]['info'] = t('Similar entries 2');
return $blocks;What other changes need to be made in order to enable a second Similar Entries block?
TIA!

#1
I didn't try this, but it should be what you need:
if ($node->nid > 0) {switch ($delta) {
case 0:
// The subject is displayed at the top of the block. Note that it should
// be passed through t() for translation.
$block['subject'] = t('Similar entries');
// The content of the block is typically generated by calling a custom
// function.
$block['content'] = theme('similar_content', $node);
case 1:
$block['subject'] = t('Similar entries 2');
$block['content'] = theme('similar_content', $node);
}
}
#2
Thank you for your quick reply!
Unfortunately, this doesn't quite do the trick... while I am presented with some options to configure for this second block, I am not presented with all of the options.
I also tried:
$block['content'] = theme('similar_content2', $node);but that didn't help.
Any other ideas? Thanks again!
#3
Oh, right, you did say configure.
You'll still need the part I pasted to make the second block actually display, but you'll then also have to copy the configure and save cases from the block callback and change the array elements (which hold the configuration variable names) to have the 2 on the end. If you just leave it as it is now with the duplicate view and list cases, the configure from the first block wiil apply to both blocks.
Note, the duplicate block implementation by cutting and pasting isn't really the best way to implement duplicate blocks, but it would qualify as a quick hack if that's all you really want.
#4
Thank you for your quick assistance!
This is the code block you are referring to?:
case 'configure':
$form = array();
if ($delta == 0) {
$form['similar_teaser_enabled'] = array(
'#type' => 'radios',
'#title' => t('Include teaser text'),
'#default_value' => variable_get('similar_teaser_enabled', 0),
'#options' => array(t('No'), t('Yes'))
);
$form['similar_rel_nofollow'] = array(
'#type' => 'radios',
'#title' => t('Block search engines'),
'#description' => t('Adds rel="nofollow" to the HTML source of similar links so search engines won\'t count similar links in their ranking calculations.'),
'#default_value' => variable_get('similar_rel_nofollow', 0),
'#options' => array(t('No'), t('Yes'))
);
for($i=1, $options=array(); $i < 101; $options[$i] = $i, $i+=1);
$form['similar_num_display'] = array(
'#type' => 'select',
'#title' => t('Number of similar entries to find'),
'#default_value' => variable_get('similar_num_display', 5),
'#options' => $options
);
$types = _similar_published_node_types();
$form['similar_node_types'] = array(
'#type' => 'checkboxes',
'#multiple' => true,
'#title' => t('Node types to display'),
'#default_value' => variable_get('similar_node_types', $types),
'#options' => $types
);
if (module_exists('taxonomy')) {
$names = _similar_taxonomy_names();
$form['similar_taxonomy'] = array(
'#type' => 'fieldset',
'#title' => t('Taxonomy category filter'),
'#collapsible' => true, '#collapsed' => true
);
$form['similar_taxonomy']['similar_taxonomy_filter'] = array(
'#type' => 'radios',
'#title' => t('Filter by taxonomy categories'),
'#default_value' => variable_get('similar_taxonomy_filter', 0),
'#options' => array(t('No category filtering'), t('Only show the similar nodes in the same category as the original node'), t('Use global category filtering')),
'#description' => t('By selecting global filtering, only nodes assigned to the following selected categories will display as similar nodes, regardless of the categories the original node is or is not assigned to.')
);
$form['similar_taxonomy']['similar_taxonomy_select'] = array(
'#type' => 'fieldset',
'#title' => t('Taxonomy categories to display'),
'#collapsible' => true, '#collapsed' => true
);
$form['similar_taxonomy']['similar_taxonomy_select']['similar_taxonomy_tids'] = array(
'#type' => 'select',
'#default_value' => variable_get('similar_taxonomy_tids', array_keys($names)),
'#description' => t('Hold the CTRL key to (de)select multiple options.'),
'#options' => $names, '#multiple' => true
);
}
}
return $form;
case 'save':
if ($delta == 0) {
variable_set('similar_teaser_enabled', $edit['similar_teaser_enabled']);
variable_set('similar_rel_nofollow', $edit['similar_rel_nofollow']);
variable_set('similar_num_display', $edit['similar_num_display']);
variable_set('similar_node_types', $edit['similar_node_types']);
if (module_exists('taxonomy')) {
variable_set('similar_taxonomy_filter', $edit['similar_taxonomy_filter']);
variable_set('similar_taxonomy_tids', $edit['similar_taxonomy_tids']);
}
}
return;
I tried this modification, but I must be misunderstanding you... this generates a PHP errors:
case 'configure':
$form = array();
if ($delta == 0) {
$form['similar_teaser_enabled'] = array(
'#type' => 'radios',
'#title' => t('Include teaser text'),
'#default_value' => variable_get('similar_teaser_enabled', 0),
'#options' => array(t('No'), t('Yes'))
);
$form['similar_rel_nofollow'] = array(
'#type' => 'radios',
'#title' => t('Block search engines'),
'#description' => t('Adds rel="nofollow" to the HTML source of similar links so search engines won\'t count similar links in their ranking calculations.'),
'#default_value' => variable_get('similar_rel_nofollow', 0),
'#options' => array(t('No'), t('Yes'))
);
for($i=1, $options=array(); $i < 101; $options[$i] = $i, $i+=1);
$form['similar_num_display'] = array(
'#type' => 'select',
'#title' => t('Number of similar entries to find'),
'#default_value' => variable_get('similar_num_display', 5),
'#options' => $options
);
$types = _similar_published_node_types();
$form['similar_node_types'] = array(
'#type' => 'checkboxes',
'#multiple' => true,
'#title' => t('Node types to display'),
'#default_value' => variable_get('similar_node_types', $types),
'#options' => $types
);
if (module_exists('taxonomy')) {
$names = _similar_taxonomy_names();
$form['similar_taxonomy'] = array(
'#type' => 'fieldset',
'#title' => t('Taxonomy category filter'),
'#collapsible' => true, '#collapsed' => true
);
$form['similar_taxonomy']['similar_taxonomy_filter'] = array(
'#type' => 'radios',
'#title' => t('Filter by taxonomy categories'),
'#default_value' => variable_get('similar_taxonomy_filter', 0),
'#options' => array(t('No category filtering'), t('Only show the similar nodes in the same category as the original node'), t('Use global category filtering')),
'#description' => t('By selecting global filtering, only nodes assigned to the following selected categories will display as similar nodes, regardless of the categories the original node is or is not assigned to.')
);
$form['similar_taxonomy']['similar_taxonomy_select'] = array(
'#type' => 'fieldset',
'#title' => t('Taxonomy categories to display'),
'#collapsible' => true, '#collapsed' => true
);
$form['similar_taxonomy']['similar_taxonomy_select']['similar_taxonomy_tids'] = array(
'#type' => 'select',
'#default_value' => variable_get('similar_taxonomy_tids', array_keys($names)),
'#description' => t('Hold the CTRL key to (de)select multiple options.'),
'#options' => $names, '#multiple' => true
);
// HACK
$form['similar_teaser_enabled'] = array(
'#type2' => 'radios',
'#title2' => t('Include teaser text'),
'#default_value2' => variable_get('similar_teaser_enabled', 0),
'#options2' => array(t('No'), t('Yes'))
);
$form['similar_rel_nofollow'] = array(
'#type2' => 'radios',
'#title2' => t('Block search engines'),
'#description2' => t('Adds rel="nofollow" to the HTML source of similar links so search engines won\'t count similar links in their ranking calculations.'),
'#default_value2' => variable_get('similar_rel_nofollow', 0),
'#options2' => array(t('No'), t('Yes'))
);
for($i=1, $options=array(); $i < 101; $options[$i] = $i, $i+=1);
$form['similar_num_display'] = array(
'#type2' => 'select',
'#title2' => t('Number of similar entries to find'),
'#default_value2' => variable_get('similar_num_display', 5),
'#options2' => $options
);
$types = _similar_published_node_types();
$form['similar_node_types'] = array(
'#type2' => 'checkboxes',
'#multiple2' => true,
'#title2' => t('Node types to display'),
'#default_value2' => variable_get('similar_node_types', $types),
'#options2' => $types
);
if (module_exists('taxonomy')) {
$names = _similar_taxonomy_names();
$form['similar_taxonomy'] = array(
'#type2' => 'fieldset',
'#title2' => t('Taxonomy category filter'),
'#collapsible2' => true, '#collapsed' => true
);
$form['similar_taxonomy']['similar_taxonomy_filter'] = array(
'#type2' => 'radios',
'#title2' => t('Filter by taxonomy categories'),
'#default_value2' => variable_get('similar_taxonomy_filter', 0),
'#options2' => array(t('No category filtering'), t('Only show the similar nodes in the same category as the original node'), t('Use global category filtering')),
'#description2' => t('By selecting global filtering, only nodes assigned to the following selected categories will display as similar nodes, regardless of the categories the original node is or is not assigned to.')
);
$form['similar_taxonomy']['similar_taxonomy_select'] = array(
'#type2' => 'fieldset',
'#title2' => t('Taxonomy categories to display'),
'#collapsible2' => true, '#collapsed' => true
);
$form['similar_taxonomy']['similar_taxonomy_select']['similar_taxonomy_tids'] = array(
'#type2' => 'select',
'#default_value2' => variable_get('similar_taxonomy_tids', array_keys($names)),
'#description2' => t('Hold the CTRL key to (de)select multiple options.'),
'#options2' => $names, '#multiple' => true
);
// EO Hack
}
}
return $form;
case 'save':
if ($delta == 0) {
variable_set('similar_teaser_enabled', $edit['similar_teaser_enabled']);
variable_set('similar_rel_nofollow', $edit['similar_rel_nofollow']);
variable_set('similar_num_display', $edit['similar_num_display']);
variable_set('similar_node_types', $edit['similar_node_types']);
// HACK
variable_set('similar_teaser_enabled2', $edit['similar_teaser_enabled']);
variable_set('similar_rel_nofollow2', $edit['similar_rel_nofollow']);
variable_set('similar_num_display2', $edit['similar_num_display']);
variable_set('similar_node_types2', $edit['similar_node_types']);
// EO HACK
if (module_exists('taxonomy')) {
variable_set('similar_taxonomy_filter', $edit['similar_taxonomy_filter']);
variable_set('similar_taxonomy_tids', $edit['similar_taxonomy_tids']);
// HACK
variable_set('similar_taxonomy_filter2, $edit['similar_taxonomy_filter']);
variable_set('similar_taxonomy_tids2', $edit['similar_taxonomy_tids']);
// EO HACK
}
}
return;
If you could, I'd most appreciate a little further guidance on implementing this hack!
Similar Entries is by far the best suited module for my needs out of all the "related links modules" (http://drupal.org/node/69415), and this hack would provide all the functionality I need.