Submenu - short description

A place for general not CMSimple related discussions
Post Reply
baglov
Posts: 9
Joined: Tue Jan 17, 2012 8:31 pm

Submenu - short description

Post by baglov » Tue Jan 17, 2012 8:44 pm

Help make a short description for Submenu like in the picture. How to get the first line of text? [ external image ]

cmb
Posts: 13228
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Submenu - short description

Post by cmb » Tue Jan 17, 2012 9:11 pm

Hi baglov,

basically that's very simple. You have to edit cmsimple/cms.php, and edit function li() (line 459 in CMSimple 3.3). On the first line (line 460) you have to add $c, so it reads:

Code: Select all

    global $s, $l, $h, $cl, $cf, $u, $c; 
Before line 507 you have to insert:

Code: Select all

        elseif ($st == 'submenu') {
            $temp = preg_replace("/".$cf['scripting']['regexp']."/is", "", preg_replace("/.*<\/h[1-".$cf['menu']['levels']."]>/i", "", $c[$ta[$i]]));
            $t .= '&mdash;'.substr(strip_tags($temp), 0, 50); // replace 50 with the number of characters to display
        }
        else $t .= '</li>'; // this line is already there
 
It's probably not possible to display exactly the first line of the page, but this script allows you to display the first 50 characters of the page (have a look at the commented line, where you can change 50 to any number you like).

BTW: You might have a look at CMSimple_XH 1.5.1 (basically the same as CMSimple 3.3, but some improved features).

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

baglov
Posts: 9
Joined: Tue Jan 17, 2012 8:31 pm

Re: Submenu - short description

Post by baglov » Tue Jan 17, 2012 10:22 pm

Thank you very much CMB. It worked. :D I approximately thought about this. But had problems with line 507. :D
Thanks for the advice about CMSimple_XH 1.5.1 really many interesting features.

cmb
Posts: 13228
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Submenu - short description

Post by cmb » Tue Jan 17, 2012 10:34 pm

Hi baglov,
baglov wrote:I approximately thought about this. But had problems with line 507.
Some months ago I was trying to do something similar: a submenu as teasers (as know from Joomla). So I already had some code at hand. ;)

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

flukey92
Posts: 89
Joined: Thu Aug 11, 2011 9:39 am
Location: Bedford, UK
Contact:

Re: Submenu - short description

Post by flukey92 » Wed Jan 25, 2012 2:29 pm

Hey baglov/cmb

to add to this, using a similar concept would it be possible to show a small picture next to each submenu heading? (maybe have the image stored in your img/media folder with the same title as the h1/2/3/4 tag)
its not a big issue as i dont actually show the submenu on any page, but it could come in handy for future designs in my template :)

KR

flukey

edit: added h2, h3 and h4 tag as i remembered not every page is a h1 :roll:
RJS Electronics Ltd - LED Push Switches, LCD Programmable Keys, Anti Vandal Push Buttons, Relays, Custom Cable Assemblies
Visit my Web Hosting / Design website here - www.flukedesigns.co.uk

cmb
Posts: 13228
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Submenu - short description

Post by cmb » Wed Jan 25, 2012 3:53 pm

Hi flukey,
flukey92 wrote:using a similar concept would it be possible to show a small picture next to each submenu heading?
Yes, that's possible.

Code: Select all

        elseif ($st == 'submenu') {
            $temp = preg_replace("/".$cf['scripting']['regexp']."/is", "", preg_replace("/.*<\/h[1-".$cf['menu']['levels']."]>/i", "", $c[$ta[$i]]));
            $t .= tag('img src="'.$pth['folder']['images'].$h[$ta[$i]].'" alt=""');
        }
        else $t .= '</li>'; // this line is already there
 
But you have to take care, that the heading doesn't contain characters that are not allowed for the file system. Spaces will probably no problem, but slashes for example won't work.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

flukey92
Posts: 89
Joined: Thu Aug 11, 2011 9:39 am
Location: Bedford, UK
Contact:

Re: Submenu - short description

Post by flukey92 » Wed Jan 25, 2012 4:03 pm

You my friend are a legend :) cheeky question how to make it automatically have the size of say 50px?
would this be correct?

Code: Select all

        elseif ($st == 'submenu') {
            $temp = preg_replace("/".$cf['scripting']['regexp']."/is", "", preg_replace("/.*<\/h[1-".$cf['menu']['levels']."]>/i", "", $c[$ta[$i]]));
            $t .= tag('img src="'.$pth['folder']['images'].$h[$ta[$i]].'" height="50px" alt=""');
        }
else $t .= '</li>'; // this line is already there
 
also how do you make your code coloured when your posting? :)

flukey
RJS Electronics Ltd - LED Push Switches, LCD Programmable Keys, Anti Vandal Push Buttons, Relays, Custom Cable Assemblies
Visit my Web Hosting / Design website here - www.flukedesigns.co.uk

cmb
Posts: 13228
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Submenu - short description

Post by cmb » Wed Jan 25, 2012 4:16 pm

Hi flukey,
flukey92 wrote:would this be correct?
Basically yes. But I'm not sure, if the width of the image will resize automatically, so the image might be distorted without giving a widht="..." too.
flukey92 wrote:also how do you make your code coloured when your posting?
Instead of [ code ], just write [ code=php ] (without the spaces), what will only work well for PHP code.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

flukey92
Posts: 89
Joined: Thu Aug 11, 2011 9:39 am
Location: Bedford, UK
Contact:

Re: Submenu - short description

Post by flukey92 » Wed Jan 25, 2012 4:31 pm

Thanks for that,

And typically AFAIK you don't need to state either width or height for any image,
for a random picture of say 150px * 300 px these attributes should do the following
Height="50px" picture:25px * 50px
Width="50px" picture:50px * 100px
No attributes picture: original size dimensions
Width="100%" the image will fill the width of its container, and the height at a ratio equivalent to the original dimensinos
Height 100% the image will fill the height of its container, and the width at a ratio equivalent to the original dimensions

KR
flukey

p.s. the most important thing when using different sized images (using just the one code) is stating only one dimensions so that they are all either the same height or width but none of them distorted/skewed

Using the height attribute id feel would make the output of the submenu more evenly spaced.

hope i got that right :)
RJS Electronics Ltd - LED Push Switches, LCD Programmable Keys, Anti Vandal Push Buttons, Relays, Custom Cable Assemblies
Visit my Web Hosting / Design website here - www.flukedesigns.co.uk

cmb
Posts: 13228
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Submenu - short description

Post by cmb » Wed Jan 25, 2012 6:00 pm

Hi flukey,
flukey92 wrote:hope i got that right
Yes! I wasn't able to find the specification what should happen, when a width is given without a height, or vice versa, but I tested in different browsers, and all of them did scale the image proportionally.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply