On: 2005/09/03 Viewed: 244931 times

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

Metastuff

This page "Wordpress Theme Toolkit" was posted on 03/09/2005 at 2:36 pm
Watch this discussion : Comments RSS 2.0. You can trackback this post from your own site

154 Blablas

    Pages: « 1 2 3 4 5 6 7 [8] Show All

  1. 141
    Motti Israel »
    commented, on 29/Jun/08 at 11:08 am # :

    Just wanted to say thank you for that wonderful Kit.

  2. 142
    Braincast » Storelicious» Pr... United States »
    pingback on 01/Jul/08 at 11:07 am # :

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

  3. 143
    RodeWorks » WordPress Theme Toolki... United States »
    pingback on 01/Jul/08 at 1:28 pm # :

    [...] Wordpress Theme Toolkit « planetOzh [...]

  4. 144
    Nuevo Theme para mi blog | Omar Corrales... United States »
    pingback on 03/Jul/08 at 4:54 am # :

    [...] pensado liberar el theme WP-Resurrection pero como queria añadirle algunas opciones intente usar Wordpress Theme Toolkit pero tuve algunos errores con el y la verdad no soy tan experto en PHP como para arreglarlo. [...]

  5. 145
    The P! Company - iamnotagoodartist United States »
    pingback on 04/Jul/08 at 5:41 am # :

    [...] their latest sketch shoved down the throat of their visitors. With some help from planetOzh’s Theme Toolkit, I put together a YouTube embed box that can be easily changed from the admin [...]

  6. 146
    Agregar Opciones a tus themes | Omar Cor... United States »
    pingback on 09/Jul/08 at 12:32 pm # :

    [...] Theme Toolkit Puede ser el mas conocido de todos, Lo use en versiones anteriors de wordpress, pero ahora me da error. Puede ser por mi poco conocimiento de PHP, pero es muy bueno! [...]

  7. 147
    cet Sweden »
    commented, on 14/Jul/08 at 9:12 pm # :

    i cant do it.

  8. 148
    Minyx 2.0 - Theme Wordpress — Simp... United States »
    pingback on 19/Jul/08 at 8:23 pm # :

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

  9. 149
    wpblogger China »
    wrote, on 04/Aug/08 at 4:34 am # :

    That's great, I have been looking for the solution, found here finally, thanks.

  10. 150
    Author description outside the WP main l... United States »
    pingback on 12/Aug/08 at 11:27 pm # :

    [...] also seems quite interesting, and helped me in my original attempt to display this info using the Planet Ozh WordPress Theme Toolkit functions file (I may talk about the Theme Toolkit in a following article or tutorial in this [...]

  11. 151
    My Comment Count is Bigger Than Your Com... United States »
    pingback on 23/Aug/08 at 11:17 pm # :

    [...] WordPress Theme Toolkit [...]

  12. 152
    Abhishek Australia »
    said, on 25/Aug/08 at 3:45 am # :

    Thanks for the solution !!

  13. 153
    WordPress Theme Toolkit: Anything You Wa... United States »
    pingback on 28/Aug/08 at 4:51 pm # :

    [...] WordPress Theme Toolkit is a tool that allows theme authors add an admin menu as easily as editing 3 lines, and it powers [...]

  14. 154
    Andrea Panama »
    said, on 01/Sep/08 at 3:23 am # :

    Thanks man. Very useful to those of us who need to knock out lots of different blogs...

Pages: « 1 2 3 4 5 6 7 [8] 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