Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
Putting Images for Blocks Titles
  • Posted: 31.05.2003, 23:25
     
    HeaveNGuY
    rank:
    Freshman Freshman
    registered:
     December 1969
    Status:
    offline
    last visit:
    26.10.05
    Posts:
    33
    Hello,

    I am currently upgrading my site and i came to a point where i wanted to use images for the block titles.

    Here is the solution that i came up with:

    In theme.php file for your theme i modified the themesidebox function to be something like:

    Code

    function themesidebox($block) {
    $cp = 4;
    if($block['position'] == 'c') {

        echo "<table width=\"350\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
            if (!empty($block['title'])) {
                echo "<tr>\n"
                ."<td align=\"center\" valign=\"top\">\n"
                ."<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">\n"
                ."<tr>\n"
                ."<td class=\"pn-blocktitle\">$block[title]</td>\n"
                ."</tr>\n"
                ."</table>\n"
                ."</td>\n"
                ."</tr>\n"
                ."<tr bgcolor=\"$GLOBALS[sepcolor]\">\n"
                ."<td><img src=\"themes/$GLOBALS[thename]/images/pix-t.gif\" width=\"1\" height=\"1\" alt=\"\" border=\"0\"></td>\n"
                ."</tr>\n"
                ."<tr>\n";
            }
            echo "<td align=\"left\" valign=\"top\" class=\"pn-normal\">$block[content]</td>\n"
            ."</tr>\n"
            ."</table>\n";
    }
    else {
            echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
            if (!empty($block['title'])) {
                $bimage = str_replace(" ","",$block[title]); // here we remove the white spaces
                $bimage = strtolower($bimage);
                if(is_file("images/blocks/titles/".$bimage.".gif")) { //here we check is the file exists
                    $block[title] = "<img src=\"images/blocks/titles/$bimage.gif\">"; // if it exists we tell it to use the image
                    $cp = 0; // and we set the cellpadding to 0 not to leave spaces around the image
                }
                echo "<tr>\n"
                ."<td align=\"center\" valign=\"top\">\n"
                ."<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"$cp\">\n"
                ."<tr>\n"
                ."<td class=\"pn-blocktitle\">$block[title]</td>\n"
                ."</tr>\n"
                ."</table>\n"
                ."</td>\n"
                ."</tr>\n"

                ."<tr>\n";
            }
            echo "<td align=\"left\" valign=\"top\">$block[content]</td>\n"
            ."</tr>\n"
            ."</table>\n";
    }
    }


    So basically what it does is if it is not a center blocks it checks in the images/blocks/titles/ directory to see if there is a GIF file for the block title. If there is one it prints the picture if there is none then it just prints the normal block title.

    The way to name your image file is:

    If your block title is My Block then script will remove the white spaces which will give us MyBlock and it will change everything to lower case which will give us myblock. And finally it adds the GIF extention to myblock which gives us myblock.gif.

    So in your images/blocks/titles/ directory if you have myblock.gif, it will print the image if that file does not exist then it will just print the block title.

    Some of you might have to put a @ sign before the is_file function to make it look like @is_file as it might throw error messages sometimes.

    Good luck.
  • Posted: 17.06.2003, 20:08
     
    forrie
    rank:
    Freshman Freshman
    registered:
     June 2003
    Status:
    offline
    last visit:
    31.01.04
    Posts:
    43
    Do you have a URL where we could see this in action?
  • Posted: 19.06.2003, 01:25
     
    nwsnow
    rank:
    Freshman Freshman
    registered:
     March 2003
    Status:
    offline
    last visit:
    18.06.03
    Posts:
    7
    I haven't tried this yet.. but I was planning on sitting down and writing something like this myslelf soon. Thanks for posting this, I'll try integrating it into one of my sites soon.

Extensions Moderation

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula