Chủ nhật, ngày 26 tháng sáu năm 2011

5 Useful WordPress Functions : Wordpress coding and design

Deep within the source code of WordPress lies an endless list of useful functions just waiting for you to use them in your theme or plugin. The problem is, most people don’t know they exist, probably because the Codex is ridiculously underdeveloped, and most people hate looking through source code. Luckily for you, reading the WordPress source code is a hobby of mine.


So, I compiled a list of some of my favorites. Some are simple and can be used by pretty much everyone; others have less common uses; but, all of them are incredibly useful.


1. wp_mail()

The wp_mail() function is essentially a super-easy function that allows you to easily send an email to anyone you want by just passing a few simple arguments. For example:

Mã: Chọn tất cả


You can also specify third and fourth parameter, $headers and $attachments. Seriously, this function takes all of the heavy lifting out of sending pretty much any kind of email you can think of.
You can check out the function reference on the Codex here, or you can check out the source code for the function here (which I highly recommend).

2. wp_loginout()


This function gives us the ability to display a “Login” link on our theme, so we can easily log in without having to manually type in the /wp-admin/ or /wp-login.php URL. But it goes beyond just that. If we’re already logged in, instead of displaying a “Login” link, it displays a “Logout” link that allows us to log out of our account without having to visit the dashboard.

This function is incredibly useful for theme authors, since it does all the logic for you. If you’re still manually adding the link to login our logout, you’re wasting your time. Do yourself a favor and use wp_loginout().
You can check out the template tag reference on the Codex here, or you can check out the source code for the function here.

3. clean_url()

UPDATE: WordPress has recently deprecated this function and replaced it with esc_url() and esc_url_raw(). Definitely stay current with the functions you use.

This function takes a URL input and tests it to make sure it is structured correctly. It can add the http:// to the front of a URL if it’s missing, it converts ampersands to their correct HTML character, and a few other things that fix poorly structured URLs.

There are use-cases a-plenty, but the one that comes to my mind is the ability to let a user enter a URL in a theme options or plugin settings page, and NOT require them to “include http://“. If the function did nothing else, that alone would make it useful to me.
You can check out the function reference on the Codex here, or you can check out the source code for the function here.

4. wpautop()

This function is converts line breaks in strings of text to
tags, and makes a double line break into a new paragraph by ending the first paragraph,

, and starting a new one,

. It also opens and closes the entire string with paragraph tags, so the whole thing is formatted correctly.
If you are ever storing strings of text in a database that you need to display on the front end, but wondered how to turn those line breaks into valid HTML during output, this is the function for you. In fact, this is the function WordPress uses to format posts when outputting the_content().
You can check out the function reference on the Codex here, or you can check out the source code for the function here.

5. wp_rss() / get_rss()

These functions can pull in data from an RSS feed, parse it, and (depending on how you handle it) can display the data in a useful format like a list with links.

UPDATE: WordPress has recently deprecated these functions and replaced them with a MUCH better function, fetch_feed(). This new function is beneficial because it uses the SimplePie RSS tool to parse the feed, and uses built-in WordPress caching mechanism (Transients) to store the data locally, which keeps things quick.

I’ve used these functions on several client sites where they wanted me to pull in stories from other news sources to be displayed in a section of their website. All you need to do is provide an RSS feed address, and the function(s) do(es) the hard work.

One caveat is that you do need to do a PHP include before you can use these functions. It’s only one extra line of code though:

Mã: Chọn tất cả


You can check out the function reference for wp_rss() here, or get_rss() here, or you can view the source code for each of the functions here.

(This post i copied From : http://www.nathanrice.net/blog/5-useful ... w-existed/ )
Live MSV - Talk MSV


Thứ tư, ngày 22 tháng sáu năm 2011

LinkTypes or all kind of rel in anchorlink : Web Design, Coding & Programming Forum

Adding “nofollow” to Category Links
PHP Quick Search Using JQuery Ajax
Advanced text searching using full-text indexes
Nhớ về tớ nhé!

Lynx browser will render [b]LINK elements with the same case as is given in the REL or REV attribute. Authors should therefore be consistent in their case, and may wish to capitalize the first letter while using lowercase for the rest.
The following link types are defined in HTML 4, though authors may use other link types. The Made link type, widely used as to provide a contact link for the document author, is notably missing from the list of link types defined in HTML 4.[list]
[*]Alternate specifies an alternate version of the document. When used with the LINK element's HREFLANG attribute, this value implies a translation of the document. When used with LINK's MEDIA attribute, a media-specific version (e.g., for printing) is implied.
[*]StyleSheet specifies an external style sheet for the document. This link type can be combined with the Alternate link type to define an alternate style sheet for the user to choose.
[*]Start specifies the first document in a collection.
[*]Next specifies the next document in a suggested sequence of reading. Browsers such as WebTV will preload documents identified as "next" to improve the perceived load time.
[*]Prev specifies the previous document in a suggested sequence of reading.
[*]Contents specifies a table of contents for the document.
[*]Index gives an index for the document.
[*]Glossary gives a glossary of terms used in the document.
[*]Copyright specifies a document with copyright information.
[*]Chapter specifies the chapter of a collection of documents.
[*]Section specifies the section of a collection of documents.
[*]Subsection specifies a subsection of a collection of documents.
[*]Appendix gives an appendix for the collection of documents.
[*]Help specifies a help document.
[*]Bookmark refers to a key related document. The TITLE attribute provides a label for the bookmark.
[*]EXTERNAL -> link to other site
[*]Nofollow -> tell the Bot to no follow this link
[*]Author -> tell that this is author of post .

That's all