you're who you choose to be…

Self Employed Web Designer and Web Developer. Still learn to be a great Web Designer…

How to Create a WordPress Theme from Scratch: Part 2

Sep 18th in WordPress by Sam Parkinson

It’s time for the good stuff now. We’ll be adding the comments system, a sidebar with widgets and an archive for all the old posts. This will cover all that you need for a simple but well functioning WordPress theme, and hopefully you be able to apply this to all sorts of theming projects.

Author: Sam Parkinson

I live in London, the capital city of England. I enjoy it, there is always something to do. As to what I’ve done web related, I’ve created a proxy site, a blog and a club site, I’ve also havd the pleasure of creating several web designs for a few lucky people. I’ve almost learn’t PHP, HTML and CSS are my area of expertise though I’m also a good guy to have when it comes to hardware.

Overview Of The Extras

Following on from the previous article on How to Create a WordPress Theme from Scratch, we are now going to add that oh so missing sidebar, the comments system and lastly an archive page. This should get you well introduced into WordPress theming, however you could always improve so I’ll also give you a bit of recommended reading.

I hope to show you how to setup a widget ready sidebar, which should also give you an idea of how to add widgets to other areas of a template. The comments system is fairly simple, but we always like our site to look good so there will be a bit of styling involved. Lastly the archive, this is one of WordPress’s standard template files, however custom pages are very similar, killing two birds with one stone…

Step 1 – The Sidebar

Always best to tackle the hard parts first right? Well lets get started then. Create a new file in your theme’s directory called functions.php and open it up for editing. Paste in the following:

  1. <?php
  2. if ( function_exists(‘register_sidebar’) )
  3. register_sidebar(array(
  4. ‘before_widget’ => ,
  5. ‘after_widget’ => ,
  6. ‘before_title’ => ‘<h2>’,
  7. ‘after_title’ => ‘</h2>’,
  8. ));
  9. ?>

What this does is tell WordPress that there is a widget ready sidebar in our theme. This code can be expanded on to include themes with several widget ready areas. We also state that our theme’s sidebar needs different HTML from what WordPress normally outputs. What this does is stop the sidebar widgets getting wrapped in <li> tags, which wouldn’t look so good for us.

Now, lets design that sidebar, create yet another file, called sidebar.php and paste in the following.

  1. <div id=“sidebar”>
  2. <?php if ( !function_exists(‘dynamic_sidebar’)
  3. || !dynamic_sidebar() ) : ?>
  4. <h2>About</h2>
  5. <p>This is the deafult sidebar, add some widgets to change it.</p>
  6. <?php endif; ?>
  7. </div>

What this does is simply tell WordPress where the sidebar is meant to be. There’s a little default text in there in case you don’t have any widgets on the sidebar.

Finally we need to include the sidebar file in index.php, so open that up and add the following just before the <div id="content"> tag, make sure the header include tag is still at the top of the file though.

  1. <?php get_sidebar(); ?>

Congrats, you’ve just added a dynamic sidebar to the theme.

Step 2 – Comments

The WordPress comment system can be as easy or as complicated as you wish, however because this is a simple tutorial that is building a simple theme, we’re going to use the simple method of adding comments to our posts.

WordPress makes it easy by having a standard commenting system design that comes with every copy of WordPress, and it can be used by any theme. So that’s what we’ll do. Open up index.php and put the following after line 13 (I’m talking about right after the line with all the post details like the_time(), etc.)

  1. <?php comments_template(); // Get wp-comments.php template ?>

As you can see, this includes a file that we do not have in our theme folder, but actually from somewhere within the confusing depths of WordPress. Joking aside, this makes our life a whole lot easier.

Test out your theme now, you’ll notice that it’s smart enough to not show the form and all the comments on the homepage, but when you click on a post it all renders as you want. Well… except for the fact that the textarea is way to big. To fix this we do not want to go and edit the core of WordPress but simply add a line of CSS, and make it somewhat easier to read in the process. So add the following to the bottom of style.css.

  1. textarea#comment { width: 400px; padding: 5px; }
  2. .commentmetadata { font-size: 10px; }

The first line will limit the textarea’s with to a sensible size and also add a bit of padding to make it that bit easier to read. You now have a simple but ever so functional commenting system in your theme.

The meta data was also a bit small, so thats what the second line covers.

Step 3 – The Archive

Most WordPress sites have an ‘archive’, the place to look for old posts. The commonly display two lists, one with links to all the posts in the sites categories, and one with all the posts by month. This keeps the archive quick to browse through and makes it a better user experience.

archives.php is seen by WordPress as one of their standard files, you do not need to add any special header to get it seen. However if you wish to make another page template that is not standard, take a read here.

So create the new file and put in the following, and all will be explained.

  1. <?php get_header(); ?>
  2. <?php get_sidebar(); ?>
  3. <div id=“content”>
  4. <h2 class=“entry-title”><?php the_title() ?></h2>
  5. <?php the_content() ?>
  6. <ul id=“archives-page” class=“xoxo”>
  7. <li id=“category-archives”>
  8. <h3>Archives by Category</h3>
  9. <ul>
  10. <?php wp_list_categories(‘optioncount=1&title_li=&show_count=1′) ?>
  11. </ul>
  12. </li>
  13. <li id=“monthly-archives”>
  14. <h3>Archives by Month</h3>
  15. <ul>
  16. <?php wp_get_archives(‘type=monthly&show_post_count=1′) ?>
  17. </ul>
  18. </li>
  19. </ul>
  20. </div>
  21. <?php get_footer(); ?>

This may look fairly similar to index.php however you may notice that there is no WordPress loop. This is because we’re creating a page, with only one item in it. We can still use functions such as the_title() to get and display information about the page.

There is also the the_content() function, so that if you did put a little text on this page it would still display. Now the next stuff is fairly simple, its a standard list (well two actually…) with two functions in it, wp_list_categories() and wp_get_archives(). Both functions output a standard list, the first list all the sites categories and gives each a link which go to display all posts in that category. The second does just the same except it displays months not categories.

The parameters in the functions make them display the category/month with a post count for added dynamic site factor, hehe. To add this cool archive page to your site you need to create a new page and change the “Page Template” option to the new “Archives Page” one. Check it out, a cool archive page for everyone to see how much you have written.

Review – Does it work?

Yes it does, the sidebar does its job. Same goes for the comment system and the archive page. I hope this has shown you the basics of how to make a WordPress theme, even if in the simplest of forms. Check out the links below to get started with the more advanced themeing available for WordPress.

Further Reading

  • The WordPress Codex

    The WordPress Codex

    Theme development, the codex is clear and well written documentation. Coming from the creators of WordPress, you can’t go wrong following its instructions.

    Visit

  • CSS Tricks Screencast

    There was a lot of mention about CSS Tricks 3 part guide to WordPress themeing, so I though I’d put it up on this one. It goes through how to build a nice site, a fair bit more complicated that this one but should improve on those themeing skills.

    Visit


Related Posts

Check out some more great tutorials and articles that you might like

Enjoy this Post?

Your vote will help us grow this site and provide even more awesomeness

sumber dari : http://nettuts.com/tutorials/wordpress/how-to-create-a-wordpress-theme-from-scratch-part-2/

About these ads

Filed under: Blog, Komputer,

About me…

me
Quick Facts
- 24 tahun.
- Muslim, mengikuti jejak para pendahulu yang sholeh.
- Suami dari 1 orang istri.Ayah satu orang putra
- Bekerja sebagai Technical Support Computer di percetakan Rotogravure.
- Mahasiswa Kelas Karyawan Universitas Mercubuana, Jurusan Desain Grafis dan Multimedia.

Yahoo status

MacManiac

MacManiac

Social Networking

Klik untuk mengenal lebih jauh Erwin di Facebook Klik untuk mengenal lebih jauh Erwin di Twitter Klik untuk melihat image yang disimpan di Picasa RSS feed

Reference 4 Design

smashingmagazine.com webdesignerdepot.com www.davidairey.com

Freebies

iconspedia.com iconarchive.com Desktop wallpaper- www.vladstudio.com

Belajar Design di sini

http://www.smashingmagazine.com http://www.designer-daily.com

Fave Linux

	
SLAX is a Linux Live CD operating system based on Slackware. It does not need to be installed on a computer system's hard drive; it boots and runs from either a CD or USB drive. There is also an option to run SLAX from RAM. SLAX was developed by Tomáš Matějíček in Czech republic using the Linux Live scripts. debian.org ubuntu.com

My File

Klik untuk melihat file saya di 4shared Klik untuk melihat file saya di mediafire

RSS smashingmagazine.com

  • Sebuah galat telah terjadi; umpan tersebut kemungkinan sedang anjlok. Coba lagi nanti.

RSS DailyDesignerNews

  • Packaging from the past: 10 awesome vintage packages
    Nowadays packages you’ll find in your local supermarkets are commonly filled with information, legal or not. Why not take a look back and see how packages were more minimalist in [...]
  • Featured designer: Loic Bard
    Montreal based designer Loïc Bard creates gorgeous furniture to make your interior much more design friendly. He’s got some design awards and press mentions for his great work.
  • Freebies wednesday
    Every wednesday, we share a few freebies that’ll make your designer toolbox a bit more useful. Slides.js Create stylish web presentations with this JavaScript tool. Those presentations are embeddable, mobile-friendly, [...]
  • 8 awesome CSS tools for productive web design
    Recently I’ve been looking for tools to improve my web design workflow, especially to work with CSS better. In this post you can discover some of the tools I have [...]
  • Featured illustrator: Oli-B
    Colorful and playful, Oli-B’s illustrations often stare at you in a mix of eyes, hands, and other body parts and geometric shapes.

RSS lifehacker

  • Airline Upgrades, PowerAMP Crackling, and Opening Envelopes
    Readers offer their best tips for putting your laptop to sleep, keeping your gadgets in one place, and making your keyboard's number pad better.Read more...    
  • Clear, the popular to-do list app for iOS and Mac, received an update today with a top-requested fea
    Clear, the popular to-do list app for iOS and Mac, received an update today with a top-requested feature from its users. Now you can send lists via email and easily import lists you receive. Grab the update now in the iTunes App Store or Mac App Store, depending on the update you need.Read more...    
  • Make a DSLR LCD Hood Out of Old Hotel Key Cards
    The DSLR LCD screen once served as little more than a means to viewing photos you'd already taken in the comfort of indoor lighting. Now you can use it as a live monitor and capture photos and video. It still doesn't work too well outside. With some old hotel key cards, however, you can fix that problem on the cheap.Read more...    
  • Google Voice Users Can Now Answer Phone Calls in Hangouts
    Gmail users got a taste of Google's new Hangouts feature this week, but it was missing the VOIP calling feature Voice users had come to love. Starting today, it's back...sort of!Read more...    
  • Are ROMs and emulators illegal? Why?
    Great discussions are par for the course here on Lifehacker. Each day, we highlight a discussion that is particularly helpful or insightful, along with other great discussions and reader questions you may have missed. Check out these discussions and add your own thoughts to make them even more wonderful!Read more...    

RSS vector tutsplus

  • Create a Coffee Cup Mock Up in Adobe Illustrator Using the 3D Revolve Effect
    Adobe Illustrator’s 3D effects can be a used to create quick, yet realistic product mock-ups. While not a full ray-tracing 3D application, Illustrator’s 3D feature is quite sophisticated, and it has some advantages over its more expensive counterparts. For starters, vector objects and effects can be scaled to any size without loss of quality. It’s easy to re […]
  • What’s New With Adobe InDesign CC: Interface Improvements
    In this video we are going to show you the new look of Adobe InDesign CC. You can learn how to set a custom interface brightness, how to see preview of your new documents and how can 64bit and Retina Display support help you to work more effectively with Adobe InDesign CC.
  • Creating a Simple Kawaii Yeti With Basic Shapes in Adobe Illustrator
    In this tutorial, I am going to show you how to make a cute monster character in Adobe Illustrator using basic shapes, Pathfinder panel, Width Tool, and Strokes. You will be able to apply these techniques to create other characters. Let’s get started! 1. Create the Body of the YetiStep 1Start off by creating a New Document (CMD + N) and set the artboard size […]
  • Workshop: Vector Critique #34
    Vectortuts+ is all about helping people turbo charge their skills, and today we have another special community post that will help our readers take their images to the next level. The best thing is, you can be part of it too! Find out more at the jump.How to Participate:This workshop contributor has offered a piece of work that they would like help with, ple […]
  • Tuts+ Premium Cash Back Offer: 3 Days to Go
    This offer ends soon! Act now and don’t miss out on cash back when trying a monthly Tuts+ Premium subscription.At $19 a month, Tuts+ Premium is fantastic value. But it’s even better when we hand your first $19 right back to you!For a limited time we’re offering $19 cash back to new Tuts+ Premium monthly subscribers when signing up via PayPal. If you’ve been […]
  • Create a Feisty Female Vampire and Her Pet in Adobe Illustrator
    In this tutorial I’m going to show you the inspiring process of drawing a Vampiress and her Voodoo-pet in a vintage portrait illustration with grungy elements in Adobe Illustrator. We will move step-by-step from sketch to the final vector colored image using custom brushes, gradients and the Pen Tool. Ready? Let’s get started!1. Turn Your Sketch into Vector […]
  • Create a Resting Owl Scene With Brushes and Pattern in Adobe Illustrator
    In this tutorial, we will be creating a resting owl scene using basic shapes and brushes in Adobe Illustrator. We will also be utilizing the Paintbrush Tool to create different Stroke Weights for the tree and we will be discussing various techniques for shading and designing with patterns. Let’s get started!1. Plan Your Composition By Sketching Out Your Idea […]
  • How to Create a Detailed Honey Text Effect in Adobe Illustrator
    In the following steps you will learn how to create a detailed honey text effect in Adobe Illustrator. You will learn how to create a subtle honeycomb background using basic tools, effects and blending techniques. You will learn how to create some simple brushes and how to add shading and highlights using basic blending and masking techniques. Finally, using […]
  • Quick Tip: Create a Set of Neon Art and Scatter Brushes in Illustrator
    Follow this quick tip and create your own collection of Neon Brushes in Adobe Illustrator. You will create Art Brushes and also Scatter Brushes, different colors and sizes that you can use in your projects. You’ll continue to see how you can save a set of brushes for use in the future and examples of some great quick effects you can create with your brushes. […]
  • Getting Into Anime and Manga Artwork And The Tools You’ll Need
    When it comes to drawing in the anime and manga style, it’s fairly easy to start out in the medium you’re most familiar with, but as you progress in the style, you may be interested to introduce new tools or media into your portfolio. This article discusses the various media most often used by anime and manga artists today, the different brands within those […]
Klik untuk mengenal lebih jauh Erwin

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Bergabunglah dengan 9 pengikut lainnya.

Erwin berkata….

  • 80 Kavling Ahlussunnah Murah -Tahap II -di Sedayu Bantul DIY: 80 KAVLING AHLUSSUNNAH MURAH – TAHAP II di Argod... bit.ly/17DUJDG 3 days ago
  • LIVE Daurah Fiqih Nasional IV “Matan Abu Syuja’” – Makassar: Bismillah, Mari belajar fiqih Imam Asy-Syafi’iy s... bit.ly/134dBaw 2 weeks ago
erwin @twitter

Friendfeed

View my FriendFeed
buattoko.com - memiliki toko online itu mudah

Forum Mac User

Komunitas Pengguna Apple Macintosh Indonesia
Free open source Mac software

RSS Udaramaya…

  • Sebuah galat telah terjadi; umpan tersebut kemungkinan sedang anjlok. Coba lagi nanti.

RSS New-Freeware

RSS Top ten Freeware…

RSS Techrepublic…

RSS Gizmo…

  • Eight PDF Files You Don’t Want to Open
    One of the largest sources of malware infections is PDF files with scripts buried in them. The embedded JavaScripts have instructions to download and install various types of malware. The Adobe Reader and Adobe Acrobat are the major targets for this kind of attack. Although Adobe seems to issue an unending stream of updates, many PC users still get infected. […]
  • How to Customize the Windows 8 Power User Menu to Suit Yourself
    Windows 8 doesn’t have a Start menu but it does have an abbreviated menu with some commonly used functions. It is variously called the 'Power User Menu', the 'Power Tasks Menu', or sometimes the 'Quick Access Menu' (Microsoft seems to have a problem with consistency of names in Windows 8). In this tip, I’ll point out a free prog […]
  • Easier Way to Use and Manage Libraries in Windows 7 and 8
    Windows 7 introduced a new way to organize files called "Libraries", which was carried over to Windows 8. Libraries are virtual folders that can centralize related items from multiple locations and can be very handy. However, their benefits are lost on many PC users who find their organization and use to be confusing or annoying. If you would like […]
  • Best Free Windows Store Apps for Your Windows 8 PC or Mobile
    You may not have noticed but we have been quietly assembling a list of the the best free apps from the Windows store that you can run on your Windows 8 PC or mobile device. Already the list has 75 applications in 58 categories so there are plenty of free goodies for you to play with. Check it out, despite all the negative press abour Windows 8, I wouldn […]
  • Website of the Week: Feed Your Brain
    "Today I Found Out" is a site whose focus is on learning something new every day. There is a large array of quick facts, articles, infographics etc. that should satisfy the mildest to most intensely curious of souls. The Today In History category is full of interesting tidbits, while the Articles section has several categories for your enjoyment su […]

Blog Stats

  • 111,612 hits
web stats
Ikuti

Get every new post delivered to your Inbox.

%d bloggers like this: