{"id":8978,"date":"2011-01-15T21:24:02","date_gmt":"2011-01-16T05:24:02","guid":{"rendered":"http:\/\/blog.wapreview.com\/?p=8978"},"modified":"2011-01-15T21:24:02","modified_gmt":"2011-01-16T05:24:02","slug":"how-to-create-a-wordpress-mobile-pack-custom-theme","status":"publish","type":"post","link":"https:\/\/wapreview.com\/8978\/","title":{"rendered":"How To Create A WordPress Mobile Pack Custom Theme"},"content":{"rendered":"
<\/p>\n
I consider WordPress Mobile Pack<\/a> (WPMP) by James Pearce & friends to be the best plug-in for creating a mobile friendly version of your WordPress Blog. It detects mobile devices and serves them a compact, fast loading version of your blog. There’s a link to the full site on every page so mobile users aren’t locked into mobile formatted version.<\/p>\n And unlike some other mobile plugins that only work with the iPhone and other high end devices, WPMP detects all mobile browsers and serves them pages that work on everything from the latest Android phone to a five year old basic flip phone. The\u00a0 main reason it’s so compatible is that unlike most of the other mobile plugins it resizes images and splits up long pages to keep page sizes small which speeds up mobile browsing and ensures compatibility with the most basic of phones.<\/p>\n The only problem with WPMP is it’s too popular.\u00a0 I think the default WPMP theme (image, top left) looks great. But there are tens of thousands of blogs using it. I wanted my mobile blog to have its own unique branding and color scheme (image top, right).\u00a0 It turns out that’s pretty easy to do provided you have a basic understanding of CSS and PHP.<\/p>\n You could just go into WPMP and start modifying files to make it do what you want. The problem with that is that every time WPMP is updated (which is often) you will have to redo all your changes. There is a better way and that’s to create a custom WPMP theme. With a custom theme you can update WPMP without overwriting your changes. Here’s how.<\/p>\n Create a new folder in your WordPress theme directory (wp-content\/themes\/).\u00a0 Give the folder a meaningful name. I called mine\u00a0mobile_pack_wapreview<\/p>\n Copy the\u00a0 style.css file from one of the WPMP child theme folders (mobile_pack_blue, mobile_pack_red or mobile_pack green)\u00a0 into to your custom theme folder.<\/p>\n Modify the style.css you copied into your custom theme folder. Start at the top. There’s a comment block at the very beginning\u00a0 that defines the theme to WordPress and WPMP.\u00a0 The only line of the comment block that you absolutely have to change is the theme name.\u00a0 Give it a unique name that you will recognize because that’s the way it will be listed in the Mobile Theme switcher in the WordPress Dashboard. You should probably also change the\u00a0 Description and Author fields as they are displayed on the Themes page of your WordPress Dashboard.\u00a0 You can also change the Theme URI, Version and Tags fields if you want.\u00a0 But don’t modify the line that says “Template: mobile_pack_base”.<\/p>\n Here’s what the comment block at the top of my custom theme’s style.css looks like.<\/p>\n \/* At this point you have created a custom theme.\u00a0 You should be able to select it as your Mobile Theme on the Mobile Switcher page of your WordPress Dashboard.\u00a0 On course, because you haven’t actually changed of any CSS or code yet your new theme will look exactly like the one you copied style.css from.<\/p>\n The way WPMP handles styles.css is that it loads the copy in the mobile_pack_base folder first and then it loads style.css from your custom theme. This means that any rule in the custom theme’s style.css overrides the corresponding rule in the default style.css.<\/p>\n The blue, red and green custom themes that come with WPMP are very simple and only contain a few additional CSS rules that change the header and footer background colors and the colors of buttons and links. You can change much more by adding more rules to your style.css, including changing the colors of any element and adding and removing borders.<\/p>\n I’m not going to tell you how to do that as I’m woefully under-qualified to teach you CSS. I had to bumble around in style.css trying this and that until I got the effect I wanted. I don’t recommend doing this on your live blog (I use a separate test blog for experimentation) but the nice thing about modifing CSS is that although you can make things look ugly real fast your not going to completely break your blog so that it doesn’t load at all like you can tweaking PHP code.<\/p>\n It wasn’t always easy for me to figure out what I need to add or change to achieve the desired effect. But I found two tools that really help;\u00a0 Opera<\/a> Dragonfly<\/em> and the Edit CSS tool that’s part of the Firefox Web Developer Plug-in<\/em>.<\/a><\/p>\n <\/a><\/p>\n Opera Dragonfly (image, above), comes with the Opera browser for all PC platforms.\u00a0 It’s a powerful JavaScript debugger and DOM and CSS analyzer.\u00a0 The feature I use and love is that it lets you click on a page element and see exactly which CSS rules apply to it, including any overwritten rules. To use it, open the mobile version of your blog in Opera on your PC and launch Dragonfly. In Opera 11, which is what I’m currently using, Dragonfly is in Menu > Page > Developer Tools. Using the default DOM tab in Dragonfly’s left hand window, click the “Find element by clicking button” (an arrow pointing up and to the left at an asterisk) so that the button turns green and then click any element on the page. The CSS rules that apply to that element will be shown in the right hand Dragonfly window complete with the name of the CSS file each is found in. Overridden rules are indicated by a strikeout font. A check box next to each rule lets you temporarily disable it.<\/p>\n <\/a><\/p>\n Once I know which rules I need to override I use the FireFox Web Developer plugin’s Edit CSS tool (image above) which lets you modify any of the current page’s CSS files on the fly and see your changes reflected immediately on the live web page. The tool changes the CSS rules in memory so they are temporary but you can save the modified CSS to a local disk file and upload it to your Web server once you are satisfied with the way it looks.<\/p>\n If you use the Nokia templates feature of WPMP you also need to copy style.css.nokia.css from mobile_pack_blue or one of the other custom themes included with WPMP and modify or add to the rules in it. If the Nokia templates are enabled and a Nokia handset or a device with a WebKit based browser like the iPhone visits you blog WPMP delivers four stylesheets; sytle.css and style.css.nokia.css from the base theme followed by the equivalent stylesheets from your custom theme. So changes you make in either of your custom theme’s CSS files overide the corresponding default ones.<\/p>\n Custom WPMP themes aren’t limited to just changing CSS. You can copy any of the base theme’s PHP files, except functions.php,\u00a0 into your custom theme and modify them. If WPMP sees a PHP file in your themes folder which the same name as one of the files in the default folder, it uses it instead of the default. For example you can modify header.php to add a logo image or insert an ad at the top of the page. Or you could modify footer.php to add a Google custom search box at the bottom.<\/p>\n A few caveats, don’t copy all of the files in the base theme into the custom theme. Only copy the ones you want to modify. And unless you are fairly proficient in PHP don’t modify or copy functions.php as it requires special handling. If you feel up to it, the rules for modifying functions.php for WPMP are the same as they are if you are creating a regular WordPress child theme. There are a number of articles on the web that deal with this topic. Start with Child Themes<\/a> in the WordPress Codex.\u00a0 Other posts I found helpful are\u00a0 Themeshaper’s How To Modify WordPress Themes The Smart Way<\/a> and Understand WordPress Child Theme<\/a> by WP Engineer.<\/p>\n And finally don’t experiment with your main blog, at least not if you have any visitors. As anyone who has done any programing will tell you, no matter how experienced you are, it’s really easy to screw things up so that nothing works. Create a separate test blog on a sub-domain and get everything working there first before copying your new custom mobile theme to your main blog.<\/p>\n","protected":false},"excerpt":{"rendered":" I consider WordPress Mobile Pack (WPMP) by James Pearce & friends to be the best plug-in for creating a mobile friendly version of your WordPress Blog. It detects mobile devices and serves them a compact, fast loading version of your blog. There’s a link to the full site on every page so mobile users aren’t locked into mobile formatted version. And unlike some other mobile plugins that only work with the iPhone and other high end devices, WPMP detects all … Continue reading
\nTheme Name: Mobile Pack WapReview
\nTheme URI: http:\/\/wapreview.mobi
\nDescription: Custom WordPress Mobile Pack theme for WapReview
\nAuthor: Dennis Bournique, hat tip to James Pearce and Andrea Trasatti for creating WPMP
\nVersion: 0.1
\nTemplate: mobile_pack_base
\nTags: none
\n*\/<\/span><\/p>\n