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

  • Cache Invalidation Strategies With Varnish Cache
    Phil Karlton once said, "There are only two hard things in Computer Science: cache invalidation and naming things." This article is about the harder of these two: cache invalidation. It’s directed at readers who already work with Varnish Cache. To learn more about it, you’ll find background information in “Speed Up Your Mobile Website With Varnish. […]
  • Rethinking Mobile Tutorials: Which Patterns Really Work?
    Pattern libraries are a great source of inspiration and education for designers. But common practice doesn’t always equal best practice. In this post, we’ll look at why many common tutorial patterns are ineffective and how you can leverage game design principles to increase user engagement. After the release of the first edition of Mobile Design Pattern Gall […]
  • After Editorially: The Search For Alternative Collaborative Online Writing Tools
    I’m going to let you in on a little secret: the best writers, be it your favorite authors or those that write for Smashing Magazine, don’t do it alone. Often, they work with an editor (or two), who will help them coalesce their words into something more compelling or easier to understand. Having worked with several editors — and having been a technical edito […]
  • What You Need To Know About WordPress 3.9
    The latest version of WordPress named "Smith" was released yesterday which brings us another round of core changes. This time, the team worked mainly on the back-end editing and admin functions, such as a big TinyMCE (visual editor) update, gallery previews, media playlists, an improved widget UI and live theme previews (only to mention a few). Her […]
  • Understanding CSS Timing Functions
    People of the world, strap yourself in and hold on tight, for you are about to experience truly hair-raising excitement as you get to grips with the intricacies of the hugely interesting CSS timing function! OK, so the subject matter of this article probably hasn’t sent your blood racing, but all jokes aside, the timing function is a bit of a hidden gem when […]

RSS DailyDesignerNews

  • iBlock tablet-holding cutting boards
    I’m always a bit surprised that we don’t see more of these kind of designs. To integrate modern tools to our daily life habits, we will need to adapt our living environment. That’s what these cutting boards do perfectly. The post iBlock tablet-holding cutting boards appeared first on Design daily news. Download the Designers essentials package now!
  • The CAT table
    Do you like cats? I like cats, and I’d be happy to have a table where cats could play. That’s exactly what LYCS Architecture thought, so they created the CAT table, a table designed with a built-in playground for cats. The post The CAT table appeared first on Design daily news. Download the Designers essentials package now!
  • Freebies wednesday
    Every wednesday, we share a few freebies that’ll make your designer toolbox a bit more useful. Cooking icon set A hand-drawn icon set downloadable for free. Pure CSS3 loaders A set of 10 pure CSS3 loading animations to use in your next projects. Coded by Johan Hanchin. Aqua A gorgeous geometric grotesque typeface. Clean animated […] The post Freebies wednesd […]
  • A 3D printed shelter for hermit crabs
    Japanese artist Aki Inomata decided it was time to give a shelter to hermit crabs. For that purpose, she designed cool transparent shells that she printed with 3D printers. The post A 3D printed shelter for hermit crabs appeared first on Design daily news. Download the Designers essentials package now!
  • Featured illustrator: Donough O’Malley
    Donough O’ Malley is an Irish Illustrator based in the UK. Since studying illustration in Bristol in Brighton he has worked as a freelance Illustrator and author, in a variety of areas from Children’s books, editorial, advertising and fashion. The post Featured illustrator: Donough O’Malley appeared first on Design daily news. Download the Designers essentia […]

RSS lifehacker

  • The Colorful, Collectible Lunchbox Workspace
    Even if you have boring white walls and nondescript furniture, you can have a vibrant, stylish home. That's the lesson from today's featured worskpace with its love of colorful accessories.Read more...
  • The Best Ways to Remove a Stripped Screw, In Video Form
    We've shared many ways to remove a stripped screw over the years, but Household Hacker has rounded some of the best up into one, easy to follow video.Read more...
  • Synchronize Your iTunes Library with Spotify with a Click
    Spotify recently introduced a new "My Music" section that allows you to save albums and tracks you find in Spotify to your own personal library. That's great, but if you want to mesh that library with your local files, you need to do that manually.Read more...
  • How to Stop Buying Clothes You Never Wear
    We all do it—buy clothes that we wear once or twice and then relegate them to the backs of our closets. It's a bad use of money and an organizational mess. But with some forethought and self-control, you can stop wasting money and start buying clothes you'll actually wear.Read more...
  • The Discovering Arduino DIY Kit Gets You Started with Electronics
    There are plenty of starter kits to choose from if you're interested in tinkering with electronics, but the Discovering Arduino DIY Kit is one of the more expansive. It gets you started both with general electronics and Arduino programming. Read more...

RSS vector tutsplus

  • Working with Type on a Path in Illustrator
    What You'll Be CreatingIn this quick tip tutorial, you will learn how to add Type on a Path in Adobe Illustrator. This is handy for logos and badges. So let's get to it!Text Around a Circular Path Let’s start with the badge scenario. The first thing you need to do is create a baseline for the text to follow. Create either a circle or part of a circ […]
  • Create a Fun Kaleidoscope Effect in Adobe Illustrator
    What You'll Be CreatingI've previously shown you how to create a mirrored effect, using the Appearance panel and the Transform effect. However it's time to kick it up a notch and learn how to create a kaleidoscope effect. Once you've learnt how to create this effect, it will be one of those tricks which you'll enjoy playing with... e […]
  • How to Use a Grid to Enlarge an Image While Drawing
    What You'll Be CreatingSometimes you have the perfect image to draw or paint but it's too small. An easy way to transfer the image to your drawing paper or canvas and increase it's size to what you want, you can use a grid. In this tutorial, I'm going to show you two easy ways to blow up an image and get it ready for the final art making […]
  • How to Create a Colorful, Sparkly Text Effect in Adobe Illustrator
    What You'll Be Creating For starters you will learn how to setup a simple grid and how to create a set of scatter brushes. Next, you will learn how to create a simple background and how to use your scatter brushes. Moving on you will learn how to take full advantage of the Appearance panel and how to ease your work using simple graphic styles. Finally, […]
  • Create an Avocado With Only One Shape in Adobe Illustrator
    What You'll Be CreatingFollow this tutorial and learn how to create an avocado using only one shape in Adobe Illustrator. You will start with a basic shape then by distorting it, you will obtain the shape of the avocado. From this point forward, you will add the appearances one by one in order to create the avocado style. You will create the peel, the p […]
  • Create a Soccer-Themed Text Effect in Photoshop
    What You'll Be CreatingIn this tutorial, I will show you how to create a soccer-themed text effect, using basic Layer Styles, brushes, and a couple of textures. Let's get started! Tutorial Assets The following assets were used during the production of this tutorial. Lobster font (Download the Lobster 1.3 version). White Texture pattern by Dmitry. G […]
  • 25 Amazing Blend Tutorials in Adobe Illustrator on Tuts+
    In this week's Round Up we've focused purely on beginner content for those who wish to get a better understanding on the Blend Tool and Blends! These aren't the only tutorials we have on Tuts+, in fact I'd like to share with you many of our others.Blend Tool and Blends Week We posted several tutorials, screen cast and written, to help eas […]
  • Vector Battle: Round One - Diamonds (Game Over)
    Over the past week, we started our first Vector Battle here on Tuts+. Two regular Instructors went head to head using the same concept... diamonds. Round One: DiamondsThe theme for the first Vector Battle was Diamonds. This was because the birthstone for the month of April is diamond/crystal. The challengers could interpret the theme how they wish.Our challe […]
  • Improve Your Artwork by Learning to See Light and Shadow
    It's very common for painting tutorials to treat light as an addition to the picture, an atmosphere-maker. We can easily get the impression that the object has a universal form, and then with proper lighting we can change the mood of the picture. The truth is without light there would be nothing to paint! Until you realize that, you're shooting bli […]
  • Create a Mustard Text Effect in Adobe Illustrator
    What You'll Be Creating You will learn how to setup a simple grid and how to create your mustard bottle using a bunch of linear gradients, some meshes, simple blending techniques and several effects. Next, you will learn how to save a simple, scatter brush. Moving to the mustard text, you will learn how to use your scatter brush along with a built-in ca […]
  • Connect the Dots With Visualize Path in Inkscape
    Before you think Inkscape doesn't have something, check the Extensions menu. You'll be surprised to see that there are a bunch of these additional dialog menus - and they're pretty helpful most of the time. Let's look at Visualize Path in this Inkscape quick tip.1. What Is It?Visualize Path is an Inkscape extension that creatively alters […]
  • 10 Things You Need to Know About Smart Objects in Photoshop
    What You'll Be CreatingWith the recent introduction of Linked Smart Objects in Photoshop CC, Smart Objects have become much more powerful, and useful. In this tutorial, I will share with you 10 things that you should know about working with smart objects in Photoshop. Let's get started! Photo CreditsEmpty Frames on Gallery WallSingapore SkylineSnow […]
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 25 pengikut lainnya.

Erwin berkata….

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

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…

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

RSS Gizmo…

  • View 85,000 Historical Newsreel Videos For Free
    From 1910 until it closed in 1970, Pathé News was one of the world's best-known news agencies. Based in Britain, and indeed originally known as British Pathé, it produced tens of thousands of filmed news reports, covering major stories and events all over the world. Last week, its entire archive of 85,000 videos was put online, on a dedicated YouTube ch […]
  • Updated: Best Free Digital Image Viewer
    Digital photography has become so widely available that most pictures these days will linger in a memory drive and never be printed, because we can see them on screens. As a consequence, hundreds of tools have been developed for the task, ranging from ones that offer just the most basic handling to others with loads of features nobody will ever use. That […]
  • Easily and Safely Eject USB Drives and Memory Cards with this Free Utility
    Sometimes you want to disconnect a USB drive or a flash memory card but Windows says it can’t be removed because it’s busy. Or maybe you just don’t like the “Safely Remove Hardware” function that sits in the notification area. If you are looking for a better way, you might try an open source alternative that will let you quickly and safely disconnect USB dri […]
  • Get Free Tips On How To Improve Your Writing
    Next time you need to write a long email message or some other document, or maybe a letter, try running the text past Hemingway before you send it. Not Ernest, of course, but the free web-based text analysis tool that shares his name. Hemingway checks your text, tells you what reading level it scores, and gives you tips on how to improve your writing. In the […]
  • Manage and Store Your Passwords Securely with Passneitor for Android
    By this time, you must be well-aware that using the same password on every single site is a terrible idea. Web servers get hacked every now and then, and your info could be easily exposed to malicious individuals. Even supposedly secure servers are vulnerable to attacks via the infamous Heartbleed bug, and chances are that you will have to change your passwo […]

Blog Stats

  • 118,789 hits
web stats
Ikuti

Get every new post delivered to your Inbox.

Bergabunglah dengan 25 pengikut lainnya.

%d bloggers like this: