Posted by solutionsphp on August 24, 2007 at 4:29pm
Jump to:
| Project: | Similar entries |
| Version: | 5.x-1.2 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
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!
Comments
#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.
#5
I am also looking for a second similiar entries block!
I tried the code posted above, but it didn't work out for me. I am no PHP pro so could somebody please help me?
I would really appreciate your help!
#6
hi,
i'm also looking for more than one similar entries block...anyone can help co the code above not working...
#7
@xsean (#6):
Have you had a look at similar modules like Similar By Terms or Relevant Content? They both offer different blocks, and have D5 as well as D6 releases.
Greetings, -asb
#8
i'm also looking for more than one similar entries block, this is the only module which doesn't depend on taxonomy, and the only module which returns sensible results, unless you have very specific vocabularies and careful tagging. Multiple sets of content types, and possibly showing only nodes of a specific content type (for users unfamiliar with block filters/pathauto) would certainly be a very useful feature.
Relevant Content, Similar Terms and Radioactivity should get together to produce an all in one module which allows: -
1) Multiple blocks for specific vocabs on specific content types, showing only nodes of a specific content type
2) Some way of biasing the returned results of matching terms/matching words/node energy per block
#9
This will be possible with views integration coming in the next version. You should see a development snapshot in the very near future for the 6.x branch.
#10
This issue is now considered fixed with the release of Similar entries 2.0 which has views integration.