Posted by liz315 on January 30, 2009 at 7:05pm
Jump to:
| Project: | More Like This |
| Version: | 6.x-1.1 |
| Component: | Documentation |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
The module shouldn't display sidebar blocks that don't contain content (i.e. "Recommended Reading" and "Flickr Images Like This").
Please "hide" sidebar blocks in situations where they have no real contents.
Comments
#1
Hi!
About how to hide the block completely when there is no related content: What php statement should I use?
Can you help me?
Kind regards, and thanks in advance,
Hans Lodder
#2
I solved this feature request by writing a little JavaScript program. If you have any comments, please let me know.
Regards, hans
Javascript Program RemoveEmptyTags
======================
/**
Remove empty More like this tag
php-Function in drupal-morelikethis:
function theme_morelikethis_block($items){
if(!$items)
return t('No related items were found.');
Result of the function theme_morelike this:
Situation 1: Content found
--------------------------
More Cool Content You Might Like
...
Situation 2: No content found (or just one reference)
-----------------------------
More Cool Content You Might Like
No related items were found.
Analyis:
-------
1. Find the id of block-morelikethis-taxonomy
2. Find all decendents of the unordered list
3. If there are 2 or more decendents show them, else do not display this block
Remark:
------
The way MoreLikeThis works, selecting the most significant references first,
it could have been an ORDERED list instead of an UNORDERED list.
Implementation:
--------------
I placed this Javascript module in my /sites/themes/r2m directory, and edited
the r2m.info file by adding this line:
scripts[] = RemoveEmptyText.js
Do not forget to empty yous Javascript cache, if you want to show up the
results immediately!
*/
// Create a new namespace for the new Javascript function RemoveEmptyText,
// or reuse the existing namespace
var RemoveEmptyText = RemoveEmptyText || {};
// Define the function
RemoveEmptyText = function () {
// Get the selector
var divBlockMoreLikeThis = $('#block-morelikethis-taxonomy');
// For debugging only: alert("Size=" + $(divBlockMoreLikeThis).find('li').size());
// Check the number of all decendents of the selector:
// 0 : No refences found
// 1 : Just one referefnce, too little
// 2 or more : OK, display the found refences
if ($(divBlockMoreLikeThis).find('li').size() < 2) {
divBlockMoreLikeThis.css('display', 'none');
// For debugging only: alert('There is NO more like this, or just ONE!');
}
else {
// For debugging only: alert('There are at least TWO more like this!');
}
};
// Execute the function as soon as the HTML document has loaded,
// and the DOM can be manipulated without possible side effects
$(document).ready (RemoveEmptyText);
/* End of file RemoveEmptyText */
#3