On: 2005/09/03 Viewed: 323110 times
Shorter URL for this page: http://ozh.in/ko

Suggestions

If you have ever installed and modified a theme to suit your likes, think of everything that could have been possible from within a simple admin menu, rather than having to edit template files.

Here are a few examples and ideas of additionnal features, which are easy to implement if you have some PHP knowledge.
I will detail the array part you have to edit in functions.php, as well as the PHP function you would add at the end of this file.

Set Layout Width
Giving the end user the possibility of setting his own layout width is piece of cake.

  • Admin menu :

    CODE:
    1. array(
    2.     'width' => 'Overall Width ## Set layout width'
    3. );

  • Function :
    CODE:
    1. function mytheme_width() {
    2.     global $mytheme;
    3.     if ( $mytheme->option['width'] ) {
    4.         print '#wrap { width:';
    5.         print $mytheme->option['width'];
    6.         print " ;}\n";
    7.     }
    8. }

  • Usage :
    Assuming you have a div named 'wrap' wrapping your layout, put the following in the <head> section of header.php :

    CODE:
    1. <style type="text/css">
    2. <?php mytheme_width() ?>
    3. </style>

Similarly and as easily, you could create options and functions to set anything regarding CSS and style : font color, sidebar floating left or right, location of a header background image ...

Optional Asides
Having to edit a theme's index.php to implement "Asides" is something that belongs to the past. Instead, you will just have the end user input the name of his Asides category in your admin menu :

  • Admin menu :
    CODE:
    1. array(
    2.     'asides' => 'Asides ## Name of your "Asides" category (leave empty to use none)'
    3. );

  • Function :
    CODE:
    1. function mytheme_is_asides() {
    2.     global $mytheme;
    3.     $categories = array ();
    4.     foreach((get_the_category()) as $cat) {
    5.         $categories[] = $cat->cat_name;
    6.     }
    7.     if (in_array($mytheme->option['asides'],$categories)) {
    8.         return true;
    9.     } else {
    10.         return false;
    11.     }
    12. }

  • Usage :
    You would now modify "The Loop" in your theme's index.php like this :

    CODE:
    1. <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    2.  
    3. <?php if ( mytheme_is_asides() and !is_single() ) { ?>
    4.  
    5.     <!-- This post is an aside -->
    6.     <div class="asides">
    7.     <?php echo wptexturize($post->post_content); ?>
    8.     <a href="<?php the_permalink() ?>" rel="bookmark">&laquo;</a>
    9.     </div>
    10.  
    11. <?php } else { ?>
    12.  
    13.     <!-- This post is not an asides: do things normally -->
    14.     <!-- Here goes your code to display posts -->
    15.  
    16. <?php } ?> <!-- end of aside or not -->
    17.  
    18. <?php endwhile; else: ?>
    19. <p>Sorry, no post found.</p>
    20. <?php endif; ?>

Setting default values
You can of course set default values so that when a user installs your theme, some values and options are already filled. To do so, add something like this at the end of your functions.php

CODE:
  1. // default options :
  2. /* default values upon theme install */
  3. if (!$mytheme->is_installed()) {
  4.    $set_defaults['some_option] = 'true';
  5.    $set_defaults['other_option'] = 'hello option';
  6.    $result = $mytheme->store_options($set_defaults);
  7. }

Real Live Example

Why not install and try a real theme that uses Wordpress Theme Toolkit ? Go get Minimalissimplistic !

Related posts

Page: #1 #2 #3 #4 #5

Shorter URL

Want to share or tweet this page? Please use this short URL: http://ozh.in/ko

Metastuff

This page "Wordpress Theme Toolkit" was posted on 03/09/2005 at 2:36 pm
Watch this discussion : Comments RSS 2.0.

189 Blablas

    Pages: [19] 18 17 16 15 14 13 12 11 10 91 » Show All

  1. 189
    Sherif Tunisia »
    thought, on 21/Dec/09 at 8:23 pm # :

    im a new web designer not good with php and i look for tutorials or some help of how to use wp theme toolkit.

    i understand the basics and already have done some stuff with my new theme with it but i still need to do some more things but i cant

    so any help plz ?

    Thanks

  2. 188
    kymac United States »
    wrote, on 27/Nov/09 at 6:10 pm # :

    Sorry, I forgot to include to select 'Mac McDonald' as the contact in the form mentioned in my previous post.

  3. 187
    kymac United States »
    said, on 27/Nov/09 at 6:07 pm # :

    I just realized that I am using a modified version of themetoolkit.php that was included with the Simplicity theme by Lai Zit Seng. Lai fixed a bug with an extraneous dollar sign, and corrected some HTML ending tags in version 1.12.

    If you will email me using the About->Contact Us form bluegrassmiataclub.com, I will send you this version.

  4. 186
    kymac United States »
    commented, on 27/Nov/09 at 5:26 pm # :

    This is an awesome tool for me! I have fixed a problem with checkboxes and now have it working under WP 2.8.6.

    Here is the modified read_options()

    PHP:
    1. /* Read theme options as defined by user and populate the array $this-&gt;option */
    2.         function read_options() {
    3.             $options = get_option('theme-'.$this-&gt;infos['theme_shortname'].'-options');
    4.             $options['_________junk-entry________'] = 'ozh is my god';
    5.             $this-&gt;option = array();
    6.             foreach ($options as $key=&gt;$val) {
    7.                 // is_array check needed for Multiple Choice
    8.                 if (is_array($val)) {
    9.                     foreach ($val as $key2=&gt;$val2) {
    10.                         $this-&gt;option["$key2"] = stripslashes($val2);
    11.                     }
    12.                 } else {
    13.                     $this-&gt;option["$key"] = stripslashes($val);
    14.                 }
    15.             }
    16.             array_pop($this-&gt;option);
    17.             return $this-&gt;option;
    18.             /* Curious about this "junk-entry" ? :) A few explanations then.
    19.              * The problem is that get_option always return an array, even if
    20.              * no settings has been previously saved in table wp_options. This
    21.              * junk entry is here to populate the array with at least one value,
    22.              * removed afterwards, so that the foreach loop doesn't go moo. */
    23.         }

  5. 185
    WP Folio XL « Storelicious :: Prem... United States »
    pingback on 07/Sep/09 at 2:39 pm # :

    [...] Theme ToolKit [...]

  6. 184
    Coffee Time « Storelicious :: Prem... United States »
    pingback on 07/Sep/09 at 2:39 pm # :

    [...] Theme ToolKit [...]

  7. 183
    NewsPaper « Storelicious :: Premiu... United States »
    pingback on 07/Sep/09 at 2:39 pm # :

    [...] Theme ToolKit [...]

  8. 182
    Carlos Guatemala »
    thought, on 23/Jul/09 at 7:32 am # :

    Hey Ozh,
    I known your are a busy person, but if you can bring the tool kit up to 2.8.1 compatibility will be more than great, you will make more people happy ;)

    Theres a option to pay for this compatibility? Please let me know, write to my email.

    Regards.

  9. 181
    Elpie New Zealand (Aotearoa) »
    thought, on 23/Jun/09 at 3:55 pm # :

    @Anil, the Toolkit does not use get_category but a customised one might ;)

    You may be running into a WordPress problem here. 2.8 has a known issue with category functions and this has been fixed in 2.8.1, which is currently in beta testing.
    See here for more info: http://wordpress.org/support/topic/280256?replies=26#post-1104991

    I am running 2.8.1 Beta on some production sites now because of some of the issues in 2.8. You might like to consider doing the same (or waiting a bit for the final release). Try it on a test site first and see if the problem with your Toolkit goes away.

Pages: [19] 18 17 16 15 14 13 12 11 10 91 » Show All

Leave a Reply

Comment Guidelines or Die

  • HTML: You can use these tags: <a href=""> <em> <i> <b> <strong> <blockquote>
  • Posting code: Post raw code (no <> &lt; etc) within appropriate tags : [php][/php], [css][/css], [html][/html], [js][/js], [sql][/sql], [xml][/xml], or generic [code][code]
  • Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar.
  • Spam: Various spam plugins on patrol. I'll put pins in a Voodoo doll if you spam me.
  • I will mark as Spam test comments, all comments with SEO names (ie "My Cool Online Shop" instead of "Joe") or containing forum-like signatures.

Close
E-mail It