|
All over the internet you can find tutorials, help, samples on creating wordpress theme. Still, there are some topics that are not covered by many of them. I will try to focus on the solution of practical problems I had while creating Starscape theme. This first part will cover following problems and solutions:
And as always, Starscape theme contains all this, so you can check it out also. Using theme Wordpress options within CSS or JavaScript fileIf you need to have some dinamyc settings in CSS or JavaScript, you can use PHP to modify styles or JS code. But you might also need to load Wordpress options and use them. Both CSS and JS are external resources and they can’t communicate with Wordpress code directly. This is actually quite simple to accomplish. You need to created css or js file, but it has to have extension php, like this: ‘mycode.js.php’ or ‘mystyles.css.php’. On the top of this file add following code: 7876cda9506b02934d9d87ec31b67ca1000 First part of the code will go through paths backward from the folder where the file is located, until it founds Wordpress config file. This file will import Wordpress into CSS or JS file. Header line is there to ensure that created file after going through PHP is of the right type:
Now you have complete Wordpress classes and functions in your CSS or JS file as you would have them in any other PHP file in Wordpress. Adding Gravatar support to the themeWordpress from version 2.5 has few built in functions to help you getting gravatar icons. But you need to implement how this will be used by the theme. WP older then 2.5 has no gravatar support. To get gravatar image you only need email address. You can also specify few additional options. More on these options you can find on official Gravatar website: http://en.gravatar.com/site/implement. Here is the method you can use to get a gravatar image regardless of Wordpress version you use. This code will generate image URL for email: 7876cda9506b02934d9d87ec31b67ca1001 Default image is the image that will be shown if the gravatar for the email is not found on the gravatar website. Adjust this default image url based on the image you want to use. Separating trackback from commentsWordpress puts trackbacks or pingbacks into the comments table in the database, and on the regular wordpress page comments and trackbacks are displayed together. If you like to separate these two, you need to make few changes to the ‘comments.php’ (typical file for comments). If you look at the contents of this file, you will see a foreach loop: foreach ($comments as $comment) {…}. $comments is a Wordpress array with comments for the post. Each $comment is an object with actual comment contents. To separate comments and trackbacks you only need to check comment_type property of the $comment. If the property is empty, then it’s a regular comment. If the value is ‘pingback’, then you are dealing with trackback/pingback. Easiest solution is to duplicated foreach loop, and in one instance to check if the comment is pingback, and display only them, and then to repeat the loop, and check if the comment is not pingback and display only them. More complex solution can be found in my Starscape theme. Creating Post Date button |
Comments:
Great post! I did something similar in French on one of my blogs.
*thumbs up* good articles, the wp-config solution is useful for back compat.
Thanks for the Post. It was great to read and great info.
Definite bookmark! Will be coming back for more.
I recommend to subscribe to RSS place in a conspicuous place! Readers will be more! Especially at a blog, how are you! Tested - a 30% increased the number of subscribers!
great post no body write this without good knowledge
thanks
Trackbacks:
Post a Comment