FTP Receive Updates For This Category
June 2, 2011 Site Design and Layout 0 1
Introduction
GUsually, plugin and theme authors need to provide access to a settings (options) screen so users can customize how the plugin or theme is used. The best way to present the user with such a screen is to create an administration menu item that allows the user to access that settings screen. This article explains how plugin authors can add administration menus and screens. Note: the following information assumes a knowledge of the basics of Writing a Plugin and using the Plugin API of Actions and Filters.
Every Plot Needs a Hook
To add an administration menu, you must do three things:
- Create a function that contains the menu-building code
- Register the above function using the 8220;admin_menu8221; action hook
- Create the HTML output for the page (screen) displayed when the menu item is clicked
It is that second step that is often overlooked by new developers. You cannot simply call the menu code described; you must put it inside a function, and then register the function.
Here is a very simple example of the three steps just described. This plugin will add a sub-level menu item under the Settings top-level menu, and when selected, that menu item will cause a very basic screen to display. Note:this code should be added to a main plugin PHP file or a separate PHP include file.
In this example, the function, my_plugin_menu(), adds a new item to the Administration menu via the add_options_page function. Note: more complicated multiple menu items can be added, but that will be described later. Notice the add_action line8211;that invokes the hook which 8220;registers8221; the function, my_plugin_menu(). Without that add_action, a PHP error for 8220;undefined function8221; will be thrown when attempting to activate the plugin. Finally, the add_options_page code refers to the my_plugin_options() function which contains the actual page to be displayed (and PHP code to be processed) when someone clicks the menu item.
The actual detail of these processes is described in more detail in the sections below. Remember to enclose creation of the menu and the html page in functions, and invoke the admin_menu hook to get the whole process started!
Determining Location for New Menus
Before creating a new menu, first decide if the menu should be a top-level menu, or a sub-level menu item. A top-level menu displays as new section in the administration menus and contains sub-level menu items. A sub-level menu means the menu item is a member of an existing menu.
It is rare that a plugin would require the creation of a top-level menu. If the plugin introduces an entirely new concept or feature to WordPress, and needs many screens to do it, then that plugin may warrant a new top-level menu. Adding a top-level menu should only be considered if you really need multiple, related screens to make WordPress do something it was not originally designed to accomplish. Examples of new top-level menus might include job management or conference management. Please note with the native post type registration, WordPress automatically creates top-level menus to manage those features.
If the creation of a top-level menu is not necessary, decide under what top-level menu to place your sub-level menu item. As a point of reference, most plugins add sub-level menu items underneath existing WordPress top-level menus. For example, the Backup plugin adds a sub-level menu option to the Tools top-level menu. Please note with the taxonomy registration, WordPress automatically creates sub-level menus under the applicable top-level menu to manage those features.
June 2, 2011 Working with WordPress 0 0
Comment moderation is a feature in WordPress that allows you to prevent comments from appearing on your site without your express approval. Moderation can be very useful in addressing Comment Spam, but it has more general applications as well. If you would like to learn more about comment spam, see Fighting Comment Spam.
How Moderation Works
WordPress runs a number of tests on each new comment before posting it to your blog. If a comment fails one of these tests, it is not displayed immediately on the site but is placed in a queue for moderation, the process of manual approval or deletion by the blogs administrator.
Controlling Moderation
You can control which comments get held for moderation on your Settings Discussion SubPanel page, which is located under Settings Discussion.
If you would like every comment to be held for moderation, check the An administrator must approve the comment option, listed under Before a comment appears.
If you would like to send suspicious comments to the moderation queue, while letting innocent comments through, you will need to specify a set of rules for determining which comments are suspicious. These rules are specified in on the Settings Discussion > Comment Moderation.
The first option is to hold comments for moderation if they contain an unusually large number of hyperlinks. Most normal comments contain at most one or two links while spam comments often have a large number. Look at your own comments and set this to a value that makes sense for your audience. (Note: In version 1.5.2, and possibly others, if you do not put a number in the comment moderation links box, in other words, if this box is completely blank, all anonymous comments (and possibly others) are sent to the Manage Comments SubPanel for moderation, even if the Discussion Options Subpanel has no restrictions set.)
The second option is to specify a set of moderation keys which, if present in any part of the comment, will cause it to be held for moderation. These keys are specified one per line in the large text area, which is blank by default. Moderation keys can include Spam Words, swear words, IP addresses, and Regular Expressions.
When you add a new moderation key, its a good idea to test its validity by checking previous comments. Simply use the link entitled Check past comments against moderation list, which is located underneath the text box containing moderation keys. This asks WordPress to check previous comments and tell you which ones would be flagged for moderation under your new set of keys.
The box marked Comment blacklist works in exactly the same way as the comment moderation box, except that comments that match these words will be deleted immediately and without notification. So be careful! Genuine comments could be deleted without you ever knowing they were there.
Why Not Blacklisting?
Several weblog programs take a 8220;blacklisting8221; approach to addressing comment spam. So if you tried to leave a comment that had a word or domain that was on the blacklist, then your comment would be refused.
Why did not WordPress use this method? In formulating a way to combat the problems that people were having with comments, we made a promise at the beginning, Do no harm.
Weblogs are about communication, and anything that impedes that communication is harmful to the medium. Instead of rejecting a comment that matches a term in the moderation keys (our variation on the blacklist) we simply hold it for review. That way if it was a legitimate comment mistakenly caught by the filters, the weblog author can still see it and respond to the comment.
Of course this means that there may be a lot of comments that you do not want on your site caught in the moderation queue, and in this case we have tried to make it as easy as possible to manage large numbers of comments quickly. See the articles on Fighting Comment Spam for more information and resources.
June 2, 2011 Site Design and Layout 0 0
ynamic menu highlighting is a way to give users a reference point with which to navigate. It is like the dot on the map that says 8220;you are here8221;. WordPress.org has utilized dynamic menu highlighting.
This image illustrates that the user is currently looking
at a page under the menu 8220;DOCS8221;.
By looking at the menu list you can, due to the use of the dark thick line easily ascertain that you are currently on a page within the 8220;DOCS8221; or documentation section of the site.
This article will explain how to go about making a navigation menu that dynamically highlights the currently displayed page, however there are plugins available that can do most of the work for you.
Also note that if you use the Pages sidebar widget (that comes with wordpress) to display your menu, it already has a CSS class current_page_item, which you can use to achieve the same effect. You can access it like this in your CSS:
.widget_pages li.current_page_item a{
background-image:url(images/activelink.gif);
}
Overview
There are a number of components that make dynamically highlighted navigation work. These include :
- highlighting your current location or navigation position between page loads,
- highlighting other navigation points on mouse-over,
- showing submenus of navigation, leaving a breadcrumb trail (Not in the scope of this article).
- There are also many different possible approaches to achieve dynamically-highlighted navigation. These include for example Javascript, Flash, HTML and CSS in conjunction with PHP. This article covers the CSS/PHP method.
Basic Navigation Lists
The basic navigation list might look something like this:
And there would likely be some bit of CSS in the pages stylesheet that would specifically style list items with the 8220;current8221; ID differently from other list items.
This works fine with static HTML pages, but when dealing with dynamic pages, things become a little more complicated. Perhaps this menu is supposed to be in a sites sidebar and the sidebar is contained in a single file that is called from multiple places. Obviously, as written, only one item would ever be highlighted, no matter what page is actually being viewed. That is not what we want at all!
Making the Code Dynamic
PHP allows us to add the desired highlighting effect that reacts to whatever page is being viewed. Coupled with WordPress is_ functions, we can dynamically test what page is being viewed and then rewrite the code based on the results of that test.
There are two ways to go about this. One requires us to create a variable ($current) that will always equal the page number we are on. It also requires us to put some CSS on each page instead of keeping it all in the main CSS document. The other way means a bit more of a mess with PHP, but it means we get to keep all our styling in a single CSS document.
Method One: With CSS On Each Page
The first step in this method is to remove the one id=8221;current8221; from the list and then add a unique id attribute to each list item.
The next part is where PHP comes in.
We need to write a conditional statement that will test what page is being viewed and define a variable based on the results of that test.
This piece of code uses the is_page(); function to check the title of the current page. If the title is 8220;Page One,8221; the variable $current is assigned the value of 8220;one;8221; if it is 8220;Page Two,8221; $current becomes 8220;two;8221; etc., etc. On a WordPress template, this would go in the header.php file between the
tags.
June 2, 2011 Getting Started 0 0
Most hosting providers and personal installations on Unix/Linux systems should be able to host WordPress under very common configurations
Server requirements
WordPress server requirements for Version 3.2 (Spring 2011):
- PHP version 5.2 or greater
- MySQL version 5.0.15 or greater
(Optional (required for multi-site)) Apache mod_rewrite module (for clean URIs known as Permalinks)
WordPress server requirements for Version 2.9, 3.0, 3.1:
- PHP version 4.3 or greater
- MySQL version 4.1.2 or greater
- (Optional (required for multi-site)) Apache mod_rewrite module (for clean URIs known as Permalinks)
Recommended setup
It is recommended you use a robust platform comprised of the Linux operating system, and either the Apache web-server or the NGINX web-server. Almost any server that supports PHP and MySQL will work. If your host does not support one of these platforms, and mod_rewrite, you will probably be better off switching to one of the many hosting providers that do offer those choices.
It is also essential that your host allows remote connections, for many of the WordPress features to work. If your host blocks outgoing HTTP connections, many parts of the WordPress will not function.
Recommended server setup:
- PHP version 5.2 or greater
- MySQL version 5.0.15 or greater
Hosting providers
Hosting is a commodity these days and with a little digging its easy to find a host that supports the above. If you are looking for hosting suggestions, please try:
- WordPress Recommended Hosts 8211; these hosts support WordPress, in more ways than one.
- Searching the WordPress support forums for recommendations
June 2, 2011 Working with WordPress 0 0
WordPress can be configured to use e-mail to post to a blog. To enable this functionality, you need to:
- Create a dedicated e-mail account to be used solely for posting to your blog,
- Configure WordPress to access that account, and
- Configure WordPress to publish messages from the e-mail account
You can blog by e-mail using most standard e-mail software programs or a Weblog Client 8212; a program specifically designed to send posts via email.
Limitations: 8211; Standard characters in the object 8211; Plain text only
WP-Cron Plugin Activation
Download, install, and activate the WP-Cron Plugin. It will work in the background without user intervention to update your site about every 15 minutes.
Cron Job Activation
Set up a UNIX cron job to have your blog periodically view http://example.com/installdir/wp-mail.php using a command-line HTTP agent like wget, curl or GET. The command to execute will look like:
wget -N http://example.com/installdir/wp-mail.php
If you use a different program than wget, substitute that program and its arguments for wget in this line.
Note: Another possibility is to run 8220;php /full/path/to/wp-mail.php8221; in a cronjob. This will run the php-script using php, without the need for an extra program to run. (You are more likely authorized to run php than wget.)
For more information about setting up a cron job, see:
- Intro To Cron Jobs
- Automating tasks with cron services at USAIL
- Your hosting providers FAQ or manual pages
June 2, 2011 Working with WordPress 0 0
Using phpMyAdmin
phpMyAdmin is a program used to manipulate databases remotely through a web interface. A good hosting package will have this included. For information on backing up your WordPress database, see Backing Up Your Database.
Information here has been tested using phpMyAdmin 2.8.0.2 running on Unix.
Restore Process
- Login to phpMyAdmin.
- Click databases, and select the database that you will be importing your data into.
- You will then see either a list of tables already inside that database or a screen that says no tables exist. This depends on your setup.
- Across the top of the screen will be a row of tabs. Click the Import tab.
- On the next screen will be a Location of Text File box, and next to that a button named Browse.
- Click Browse. Locate the backup file stored on your computer.
- Make sure the SQL radio button is checked.
- Click the Go button.
- Login to phpMyAdmin.
- Click databases, and select the database that you will be importing your data into.
- You will then see either a list of tables already inside that database or a screen that says no tables exist. This depends on your setup.
- Across the top of the screen will be a row of tabs. Click the Import tab.
- On the next screen will be a Location of Text File box, and next to that a button named Browse.
- Click Browse. Locate the backup file stored on your computer.
- Make sure the SQL radio button is checked.
- Click the Go button.
Now grab a coffee. This bit takes a while. Eventually you will see a success screen.
If you get an error message, your best bet is to post to the WordPress support forums to get help.
June 2, 2011 WordPress Lessons 0 0
The Loop is used by WordPress to display each of your posts. Using The Loop, WordPress processes each of the posts to be displayed on the current page and formats them according to how they match specified criteria within The Loop tags. Any HTML or PHP code placed in the Loop will be repeated on each post. When WordPress documentation states 8220;This tag must be within The Loop8221;, such as for specific Template Tag or plugins, the tag will be repeated for each post.
For example, among the information The Loop displays by default: the Title (the_title()), Time (the_time()), and Categories (the_category()) for each post. Other information about each post can be displayed with the appropriate Template Tags or (for advanced users) by accessing the $post variable, which is set with the current posts information while The Loop is running.
Using The Loop
The Loop should be placed in index.php and in any other Templates used to display post information.
Be sure to include the call for the header Template at the top of your Themes Templates. If you are using The Loop inside your own design (and your own design is not a template), set WP_USE_THEMES to false.
The loop starts here:
and ends here:
Loop Examples
Below are three examples of using multiple loops. The key to using multiple loops is that $wp_query can only be called once. In order to get around this it is possible to re-use the query by calling rewind_posts() or by creating a new query object. This is covered in example 1. In example 2, using a variable to store the results of a query is covered. Finally, 8220;multiple loops in action8221; brings a bunch of ideas together to document one way of using multiple loops to promote posts of a certain category on your blog8221;s homepage.
June 2, 2011 Site Design and Layout 0 0
What is a Gravatar?
Gravatars are Globally Recognized Avatars. An avatar or gravatar is an icon, or representation, of a user in a shared virtual reality, such as a forum, chat, website, or any other form of online community in which the user(s) wish to have something to distinguish themselves from other users. Created by Tom Werner, gravatars make it possible for a person to have one avatar across the entire web. Avatars are usually an 80px by 80px image that the user will create themselves.
Gravatars in blog post comments
A Gravatar is essentially the same thing, but they are all hosted on a single server and are called up by encrypting the users email address via the MD5 algorithm. So instead of having one avatar on one forum you visit, and another at a blog you visit, you could have the same avatar at both.
Gravatars can easily be used within WordPress with the Gravatar WordPress Plugin or added manually in the index.php, comments.php and comments-popup.php template files.
How a Gravatar is Constructed
A Gravatar is a dynamic image resource that is requested from a server. The request URL is presented here, broken into its segments. The URL always begins with:
http://www.gravatar.com/avatar/
The next part is a hashed version of the users email address. The email address MUST be lower-cased first, then have all whitespace removed, before md5 hashing it.
279aa12c3326f87c460aa4f31d18a065
An optional rating (or r) parameter may follow with a value of [ G | PG | R | X ] which determines the highest rating (inclusive) that will be returned.
?r=R
An optional size (or s) parameter may follow that specifies the desired width and height of the Gravatar. Valid values are from 1 to 512 inclusive. Any size other than 80 will cause the original Gravatar image to be resampled using bicubic resampling before output.
038;s=120
An optional default (or d) parameter may follow that specifies the full URL, encoded URL, protocol included, of a GIF, JPEG, or PNG image that should be returned if either the requested email address has no associated gravatar, or that Gravatar has a rating higher than is allowed by the rating parameter. It may also contain one of the following options:
June 2, 2011 Site Design and Layout 0 0
What Are Smileys?
Smileys, also known as 8220;emoticons,8221; are glyphs used to convey emotions in your writing. They are a great way to brighten up posts.
Text smileys are created by typing two or more punctuation marks. Some examples are:
To learn more about emoticons and their history, see the Wikipedia entry on Emoticons.
How Does WordPress Handle Smileys?
By default, WordPress automatically converts text smileys to graphic images. When you type
in your post you see when you preview or publish your post.
To Turn off Graphic Smileys
If you turn off graphic smileys, whatever you type in plain text will remain, and be displayed, as plain text.
Go to your Admin Panel
Select Settings -> Writing
In the Formatting section, uncheck the box for 8220;Convert emoticons like
and
to graphics on display8221;
Turning off emoticons means that when you type
in a post you will see
when you preview or publish your post. So it does not stop you from using emoticons as plain text.
Troubleshooting Smileys
Why Does not it Work?
Smileys may have been disabled by your WordPress admin. Another possibility is the smiley image files have been deleted from /wp-includes/images/smilies.
Why Does not it Work for Me?
If smileys work for others at your site but not for you:
Type a space before and after your smiley text. That prevents the smiley being accidentally included in the text around it.
Make sure not to use quotes or other punctuation marks before and after the smiley text.
Where Are My Smiley Images Kept?
The smiley or emoticon image graphics are found in the /wp-includes/images/smilies directory.
Note that smileys is spelled eys in this documentation and the directory name for the smiley images is 8220;smilies, spelled ies8221;
How Can I Have Different Smiley Images Appear?
Simplest way:
Find your smiley image files in the /wp-includes/images/smilies directory and back them up to another directory
Note the names of each smiley file. Your files must match these names and should be in the same 8220;gif8221; image format.
For predictable behavior, the image sizes should be similar.
Upload your new files to the /wp-includes/images/smilies directory with an FTP program.
If you are up to hacking the code:
If you really must change the file names of the images, edit the file that refers to these images, (in WordPress 2.2, they are located in 8220;functions.php8221;), situated in the /wp-includes/ directory. Follow all precautions when 8220;hacking code8221;.
You can read a tutorial explaining all this in more detail, as well as how to avoid hacking WP code, at Ars Aranea.
There are also WordPress Plugins which allow you to customize your smilies in WordPress.
Why are my Smiley Images Blank?
If you recently uploaded the images, it could be that the images have been uploaded in ASCII format by your FTP program. Re-upload the smileys ensuring that they are transferred in BINARY format.
Some FTP programs have an auto-detect setting which will upload files in the correct format without user intervention. If you have such a setting, turn it on.
Smiley CSS
The smiley images in WordPress are automatically given a CSS class of wp-smiley when they are displayed in a post. You can use this class to style your smileys differently from other post images.
For example, its not uncommon to set up images in a post to appear on the left-hand side of the content with text flowing around the image. The CSS for that might look like this:
.post img {
float: left;
}
This would typically affect all images in a post, including your smiley images. To override this so that smileys stay inline, you could add this to your CSS:
img.wp-smiley {
float: none;
}
For more on CSS in WordPress, you might want to start here.
June 2, 2011 Getting Started 0 0
In addition to the typical installation of WordPress, there are other ways to install WordPress to consider.
Want to use WordPress in a language other than English? There are various versions, tips, sites, and support forums for the various languages of WordPress. Considering moving your old blog to WordPress? If you are working on developing WordPress Themes or Plugins, you may consider installing WordPress to your computer so you can work without connecting to the Internet. There are also tips for installing WordPress to a Linux server.
If you are new to WordPress, we recommend that you start with the introduction to installing WordPress and review the hosting requirements, working with FTP client programs, and be sure you know how to change file and folder permissions on a server.
These special installation techniques are not for the novice. Be sure you backup everything and keep extra copies of your WordPress files, Themes, and Plugins, just in case.
If you are nervous about installing WordPress, do not use these special techniques. Use the simple to use WordPress installation instructions and guide or get volunteers to help you from Install4Free WordPress, a service supported by WordPress volunteers.
Installing WordPress in Your Language
To install WordPress in a language other than English, see Installing WordPress in Your Language and WordPress in Your Language for support and files.
Moving to WordPress
If you are moving to WordPress from another blogging platform, these articles and tips may help you to import your former blog s content into your new WordPress blog.
Installing WordPress Locally
There are a variety of articles on and off the WordPress Codex to show you how to install WordPress locally 8211; on your own computer. These techniques involve installation of files and programs that turn a portion of your computer s hard drive into a server. The some of the list of softwares are mentioned below which will help you install the wordpress locally on your pc.
- XAMPP
- WAMP
- LAMP
Customizing Your WordPress Installation
There may be times when you need a custom form of installation to work WordPress into an already existing website or installing it to its own directory on your server.
Moving WordPress
ere are times when you need to move WordPress around within your server, and times when you need to move WordPress from one server to another. You don t need to reinstall. WordPress is flexible enough to handle all of these situations.
Easy answer for most installations:
- If database and URL remains the same, you can move by just copying your files and database.
- If database name or user changes, edit wp-config.php to have the correct values.
- If you want to test before you switch, you must temporarily change 8220;siteurl8221; and 8220;home8221; in the database table 8220;wp_options8221; (through phpMyAdmin or similar).
- If you had any kind of rewrites (permalinks) setup you must disable .htaccess and reconfigure permalinks when it goes live.
Moving WordPress Within Your Site
Moving the WordPress files from one location on your server to another 8211; changing its URL 8211; requires some special care.
Here are the step-by-step instructions:
- Create the new location using one of these two options:
- If you will be moving your WordPress core files to a new directory, create the new directory.
- If you want to move WordPress to your root directory, make sure all index.php, .htaccess, and other files that might be copied over are backed up and/or moved, and that the root directory is ready for the new WordPress files.
- Login to your blog.
- Go to the Administration > Settings > General panel.
- In the box for WordPress address (URI): change the address to the new location of your main WordPress core files.
- In the box for Blog address (URI): change the address to the new location, which should match the WordPress address (URI).
- Click Save Settings.
- (Do not try to open/view your blog now!)
- WordPress 2.0 only: Delete the folder wp-content/cache.
- Move your WordPress core files to the new location. This includes the files found within the original directory, such as http://example.com/wordpress, and all the sub-directories, to the new location.
- If you are using Permalinks, go to the Administration > Settings > Permalinks panel and update your Permalink structure to your .htaccess file, which should be in the same directory as the main index.php file.
- If you have problems with missing images that you have uploaded, you need to change the path to the images on every post directly on your SQL database. For this, follow the instructions on 8220;Moving your weblog inside your PC8221;.
- You must also check and edit 8220;store uploads folder8221; under Settings-Miscellaneous or all your new uploads will continue to go into the old folder.
- Existing image/media links uploaded media will refer to the old folder and must be updated with the new location.
It is important that you set the URI locations BEFORE you move the files.
If you forget to change the locations
Suppose you accidentally moved the files before you changed the URIs: you have two options.
OPTION 1.Suppose the files were originally in /path/to/old/ and you moved them to /path/to/new before changing the URIs. The way to fix this would be to make /path/to/old/ a symlink (for Windows users, 8220;symlink8221; is equivalent to 8220;shortcut8221;) to /path/to/new/,
and then follow the steps above as normal. Afterwards delete the symlink if you want.
If you have accidentally changed your WordPress site URL
Suppose you accidentally changed the URIs where you cannot move the files. (but still can access the login page, through a redirection or something)
wp-login.php can be used to (re-)set the URIs (Insert the following lines after
You are done. Test your site to make sure that it works right. If the change involves a new address for your blog, make sure you let people know the new address, and consider adding some redirection instructions in your .htaccess file to guide visitors to the new location.
Changing The Site URL also provides the details of this process!
