TwentyTen wordpress child hacks

Having planned to do the work to combine my two previous blogs together, I thought I’d take the opportunity to upgrade to the very latest WordPress 3.0 version, which includes the all new default theme TwentyTen.

This is already a very nice theme – a much improvement over the last default. It’s also very easy to customise to your own preference, for instance you can change the background colour and add a picture to the background and change the header image all with a few clicks of the mouse. It also makes a very nice base theme.

I wanted to make a few improvements of my own, so – as is the (very clever) wordpress way – I made a child theme based on TwentyTen. This is incredibly easy to do. Just make an empty folder in the the themes folder and add a css file named “style.css” then add a comment at the top that points back at the parent theme:

  1. /*
  2. Theme Name: Twenty Ten Akademy
  3. Description: Akademy's Child theme of Twenty Ten
  4. Author: Matthew Wilcoxson
  5. Template: twentyten
  6. */

Once done you can overwrite styles, functions and even whole files.

My changes, amongst others, consisted of a semi transparent background for the main section, a nice border and some rounded corners, so I just appended these to the “style.css” file.

  1. #wrapper {
  2. background-color: #eee; /* Old browser */
  3. background-color: rgba( 255,255,255,0.7);/* Modern browser */
  4. border: 10px solid #fafafa;
  5. border-radius: 10px 10px 0 0;
  6. }

I also wanted the headers to change randomly so that I could show off some of my photos, to do that I just added the HungryCoders little plugin (here). This rotates around the selection of headers that come with the default theme, which isn’t quite what I wanted. To pick up a list of my own headers I create a file called functions.php that overwrites the function twentyten_setup(). This is basically identical but reads in files from a folder, see the following code that replaced the original static array.

  1. $headers = array();
  2. if ($handle = opendir( STYLESHEETPATH . '/images/headers/') )
  3. {
  4. while (false !== ($file = readdir($handle)))
  5. {
  6. $pos = strrpos( $file, '.' );
  7. if( $pos !== false && $pos > 0 )
  8. {
  9. $file_name = substr( $file, 0, $pos );
  10. if( strpos( $file_name, "-thumbnail" ) === false )
  11. {
  12. $file_ext = substr( $file, $pos+1 );
  13. $file_ext_low = strtolower( $file_ext );
  14. if( $file_ext_low == "jpg" || $file_ext_low == "jpeg" )
  15. {
  16. $headers[$file_name] = array (
  17. 'url' => '%s/images/headers/' . $file,
  18. 'thumbnail_url' => '%s/images/headers/' . $file_name . "-thumbnail." . $file_ext,
  19. 'description' => __( $file_name, 'twentyten' ) );
  20. }
  21. }
  22. }
  23. }
  24. closedir($handle);
  25. }
  26. register_default_headers( $headers );

The extra PHP code scans a folder at STYLESHEETPATH/images/headers/ . It looks for jpeg files. Once found it adds these to the header collection, with a thumbnail, the thumbnail has “-thumbail.” in (e.g. myheader.jpg and myheader-thumbnail.jpg). The name of the file will also be used as a description. Now when you go to any blog page, the plugin will pick one of your images. To use it just add your header images, in jpeg format, in to the images/headers folder of the child theme.

If you’d like to get hold of the files download the files here and unzip into your theme folder.

3 Replies to “TwentyTen wordpress child hacks”

  1. Hi I am trying to get a 20-10 rotator working and have downloaded your script but I get the following error when trying to activate the theme. I must be doing something stupid. Any suggestions

  2. Fool I am, did not paste the error:
    Fatal error: Cannot redeclare twentyten_page_menu_args() (previously declared in /var/www/vhosts/ in /var/www/vhosts/ on line 217

    1. Hi Rob,

      I’m afraid the package contains the wrong functions.php file, must have selected the wrong one.

      Replace it with the new zip file I’ve just uploaded from the same place. Thanks for catching that one!


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.