Hack: Add optional headings for lists

Jump to: navigation, search

The following additions provide headings for any list that displays results. This can be useful since it avoids trying to test for results in a template (which is very difficult to do).

The following has been tested on the version of DPL which works with MW 1.16.

<?php
 
//etc...
        $sStartList = '<ul>';
        $sEndList = '</ul>';
        $sStartItem = '<li>';
        $sEndItem = '</li>';
 
        $sStartHead = '';
        $sEndHead = '';
        $sTextHead = '';
 
        $bUseGallery = false;
//etc....
 
                        case 'nofollow': # bug 6658
                                if ( 'false' != $sArg ) {
                                        $aLinkOptions['rel'] = 'nofollow';
                                }
                                break;
                        case 'headingtext':
                                $sTextHead = htmlspecialchars($sArg);
                                break;
                        case 'headingtag':
                                switch ($sArg)
                                {
                                case 'h2':
                                        $sStartHead = '<h2>';
                                        $sEndHead = '</h2>';
                                        break;
                                case 'h3':
                                        $sStartHead = '<h3>';
                                        $sEndHead = '</h3>';
                                        break;
                                case 'h4':
                                        $sStartHead = '<h4>';
                                        $sEndHead = '</h4>';
                                        break;
                                case 'h5':
                                        $sStartHead = '<h5>';
                                        $sEndHead = '</h5>';
                                        break;
                                case 'h6':
                                        $sStartHead = '<h6>';
                                        $sEndHead = '</h6>';
                                        break;
                                case 'br':
                                        $sStartHead = '<b>';
                                        $sEndHead = '</b><br />';
                                        break;
                                default:
                                        $sStartHead = '<b>';
                                        $sEndHead = '</b>';
                                        break;
                                }
                                break;                  
                } // end main switch()
 
//etc.....
 
        //start unordered list
        $output = $sStartHead.$sTextHead.$sEndHead.$sStartList . "\n";
 
//etc....
?>

This will provide headings for the ordinary lists, but not the gallery view.

The extra parameters are thus:

  • headingtext - Text to use as a heading if results are found.
  • headingtag - Tag to surround the heading text with. One of:
    • h2-h6 (headings 2 through 6)
    • b (bold)
    • br (bold followed by a br tag.

Example:

<DynamicPageList>
category    = Foo
headingtext = List of Foo
headingtag  = h2
</DynamicPageList>

Please note that the headings won't appear in the table of contents, regardless of which tag is used, but they will be formatted to appear laccording to the tag chosen.

Agrestis14:23, 19 September 2011
Personal tools

Variants
Actions
Navigation
Support
Download
Development
Communication
Toolbox