Shortcodes:Themes

From e107 Wiki
Jump to: navigation, search

e107 Wiki: English | Русский | Deutsch | Français | Magyar | Português | Български | Česky | Nederlands | Ελληνικά | Italiano | Norske | Polska | Slovenščina | Español | Svenska | Translate: Wiki | Page

logo_wiki.png

Current Release 1.0.4 | e107.org | Download | Changelog | Forum | Plugins | Themes | RSS Feed of Latest Changes | Atom Feed of Latest Changes


e107 Shortcode Guide
Main page > I : First Aid > II : Development > III : Administration > IV : How To's > V : Plugin Writing > VI : Theming & Shortcodes



Contents

Adding or overriding shortcodes with your theme

You can now create your own shortcodes or override the existing core shortcodes from your theme. Add the following line to your theme.php file:

Code: Line to add to top of theme.php file
$register_sc[]='XXXX';

This tells e107 that this theme will be handling all requests for the {XXXX} shortcode. You will then just add a xxxx.sc file in your root theme dir. You can now use the {XXXX} shortcode in your theme; however, you must also make sure that any code that includes {XXXX} ultimately gets parsed by $tp -> parseTemplate.

For instance, you probably can include {XXXX} within $HEADER since $HEADER is parsed. You could NOT include it within theme as

Code: This won't work without parsing
echo ({XXXX});

See e107_files/shortcodes for sample files.

Example: Create a shortcode to style individual menus

Sound complex? If you're comfortable with HTML and a bit of PHP the following example should help illustrate the concepts. Here is an example of a simple shortcode that will help you customize your theme by displaying the mode and style of a table. Once you know mode and style you can customize each table differently as described in Styling individual menus.

Create the testshortcode.sc file

Create the testshortcode.sc file and store it in your root theme directory (same directory as you theme.php file).

Code: testshortcode.sc
global $globalmode, $style;
$ret='';
if (is_array($globalmode)) {
  $ret .= 'mode[0]='.$globalmode[0].'<br/>';
  $ret .= 'mode[1]='.$globalmode[1].'<br/>';

} else {
  $ret .= 'mode='.$globalmode.'<br/>';
}
$ret .= 'style='.$style.'<br/>';
return $ret;

Modify your theme.php file

Create the shortcode register at the top of your theme.

Code: Put at the top of your theme
$register_sc[] = 'TESTSHORTCODE';

Create the global variables within your function tablestyle if you do not already have them.

Code: Put inside function tablestyle($caption, $text, $mode){...}
global $style;
global $tp, $globalmode;
$globalmode = $mode;  //need a new global variable since $mode is not global
//echo $tp -> parseTemplate('{TESTSHORTCODE}');  //uncomment this line to see the mode and style of every table

What you should see

If everything is working properly AND you uncommented the //echo $tp -> .... line above, you should see something like

mode[0]=forum
mode[1]=main3
style=default

when you visit your forum.php page, and

mode=login
style=leftmenu

above your left menu.

Just for giggles, try using {TESTSHORTCODE} in other parts of your theme with and without the parsing statements to see what happens.

Mighty and armed, you're now ready to Style your individual menus.