<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5918658024636979890</id><updated>2024-11-06T10:53:24.291+08:00</updated><category term="Tutorial"/><category term="Tips"/><category term="jQuery"/><category term="WordPress"/><category term="Web Application"/><category term="Web Design"/><category term="jQuery Plugin"/><category term="Showcase"/><category term="Web Development"/><category term="CSS"/><category term="HTML5"/><category term="Javascript"/><category term="Tools"/><category term="PHP"/><category term="iPad Apps"/><category term="iPhone Apps"/><category term="Freelance"/><category term="Inspiration"/><category term="Freebies"/><category term="Resources"/><category term="CSS3"/><category term="Google"/><category term="Theme"/><category term="Form"/><category term="WordPress Plugins"/><category term="Facebook"/><category term="Jailbreak"/><category term="Menus"/><category term="Slideshow"/><category term="Techniques"/><category term="Web Framework"/><category term="Mac Apps"/><category term="Navigation"/><category term="API"/><category term="Articles"/><category term="CSS tools"/><category term="IOS 4.3.3"/><category term="Icon"/><category term="Portfolio"/><category term="Slider"/><category term="WordPress Themes"/><category term="michael jackson"/><category term="Buttons"/><category term="CMS"/><category term="MySQL"/><category term="Website"/><category term="iPhone"/><category term="Free Apps"/><category term="Games"/><category term="Google+"/><category term="Photo"/><category term="Plugins"/><category term="Project Management"/><category term="SEO"/><category term="Shortcodes"/><category term="Snippets"/><category term="Template"/><category term="Template Engine"/><category term="Torrents"/><category term="Twitter"/><category term="vzhai"/><category term="AJAX"/><category term="Blogging"/><category term="CodeIgniter"/><category term="Custom Post Types"/><category term="Database"/><category term="Design Patterns"/><category term="Google Map"/><category term="Layout"/><category term="Library"/><category term="Review"/><category term="Social Network"/><category term="Tooltips"/><category term="Trends"/><category term="Videos"/><category term="Wallpapers"/><category term="Web Service"/><category term="Wireframe"/><category term="eCommerce"/><category term="iOS 5"/><category term="michelle"/><category term="2011"/><category term="Android Apps"/><category term="Animation"/><category term="Auto Complete"/><category term="Best Practices"/><category term="Brainstorming"/><category term="Business"/><category term="Cheat Sheet"/><category term="Client"/><category term="CodeCanyon"/><category term="Conversion"/><category term="Custom Page Templates"/><category term="Financial"/><category term="Google APIs"/><category term="Google Apps"/><category term="HTML"/><category term="Ideals"/><category term="Images"/><category term="Mobile OS"/><category term="Open Source"/><category term="Personalized Web"/><category term="Readsn0w"/><category term="Selection"/><category term="Settings API"/><category term="Sprites"/><category term="Tagging"/><category term="Time Management"/><category term="Uploader"/><category term="WYSIWYG"/><category term="Website Tour"/><category term="Windows Application"/><category term="XML"/><category term="h1n1"/><category term="iPad 2 Jailbreak"/><category term="jQuery Mobile"/><category term="swine flu"/><category term="trip"/><category term="vacation"/><category term="40+ Top"/><category term="404"/><category term="404 Error Page"/><category term="Accordion"/><category term="Action Games"/><category term="Admin Template"/><category term="Advanced WordPress Queries"/><category term="Alternatives"/><category term="Amazon Web Services"/><category term="Analysis"/><category term="Android"/><category term="Antivirus"/><category term="Apple"/><category term="Authentication"/><category term="Auto-Refresh"/><category term="Best Apps"/><category term="Blackberry"/><category term="Bots"/><category term="Business Apps"/><category term="CAPTCHA"/><category term="CDN"/><category term="CSRF"/><category term="CSSLint"/><category term="Calendars"/><category term="Canvas"/><category term="Caption"/><category term="Cascader"/><category term="Changing Fonts"/><category term="Chart"/><category term="Chrome Apps"/><category term="Chrome Extension"/><category term="Chromebook"/><category term="Chromebooks"/><category term="Cinemagraph"/><category term="Class"/><category term="Code Editor"/><category term="Code Management"/><category term="Code Sharing"/><category term="Collection"/><category term="Coming Soon"/><category term="Comments"/><category term="Conditional Statements"/><category term="Contact Methods"/><category term="Create A Theme Options Page"/><category term="Create A Top Level Admin Menu"/><category term="Create WordPress Plugin"/><category term="Credit Cards"/><category term="Cross Hosts"/><category term="Cross-Browser"/><category term="Cross-Site Request Forgery"/><category term="Custom Loop"/><category term="Custom Meta Boxes"/><category term="Custom Post Meta Boxes"/><category term="Customer Support System"/><category term="Cydia"/><category term="DHTMLX"/><category term="DIY"/><category term="Datagrid"/><category term="Designers"/><category term="Developers"/><category term="Domain Names"/><category term="Drag n Drop"/><category term="Dreamboard"/><category term="Dropdowns"/><category term="Easing"/><category term="Education"/><category term="Email"/><category term="Envato API"/><category term="Extensions"/><category term="FTP"/><category term="Facebook Video Chat"/><category term="Features"/><category term="Files Management"/><category term="Filterable Portfolio"/><category term="Firefox Add-On"/><category term="Firefox Plugin"/><category term="Flash"/><category term="FlashFirebug"/><category term="Flip"/><category term="FloorPlanner"/><category term="Fluid Images"/><category term="Fonts"/><category term="Frameworks"/><category term="Function"/><category term="GMAP3"/><category term="GMail"/><category term="Generator"/><category term="Google Body"/><category term="Google Chart API"/><category term="Google Documents"/><category term="Google I/O"/><category term="Graph"/><category term="Guider"/><category term="HTML5 Boilerplate"/><category term="Habits"/><category term="Helper"/><category term="Hierarchy"/><category term="IOS 4.3.4"/><category term="Icon Menus"/><category term="Image Wall"/><category term="Include"/><category term="Innovative"/><category term="Interview"/><category term="JSON"/><category term="Job"/><category term="Keynote"/><category term="Launch Page"/><category term="Lightbox"/><category term="MIT"/><category term="Malware"/><category term="Media Player"/><category term="Media Queries"/><category term="Microsoft Kinect"/><category term="Migration"/><category term="Mind Mapping"/><category term="Mistakes"/><category term="Mobile Web Apps"/><category term="Mockup"/><category term="Modal"/><category term="Motion"/><category term="Mp3"/><category term="Multisite"/><category term="Music Player"/><category term="November Edition"/><category term="NowStream"/><category term="OpenJS Grid"/><category term="PDF"/><category term="PDO API"/><category term="Page Flip Effect"/><category term="Paper Images"/><category term="Parallax"/><category term="PayPal"/><category term="Payment"/><category term="Photoshop"/><category term="Placeholder Services"/><category term="Podcasts"/><category term="Popup"/><category term="Presentation"/><category term="Progress Bar"/><category term="Prototype"/><category term="Prototyping"/><category term="Questions"/><category term="QuickFlip"/><category term="Quicktime"/><category term="RESTful"/><category term="Real Player"/><category term="Real-time Data"/><category term="Reference"/><category term="Regular Expression"/><category term="Reset"/><category term="Responsive"/><category term="Resume"/><category term="SMS"/><category term="SWF"/><category term="Scanner"/><category term="Scroller"/><category term="Seamless Workflow"/><category term="Security"/><category term="Servers"/><category term="Services"/><category term="Silverlight"/><category term="Skype"/><category term="Sliding Background"/><category term="Smarty"/><category term="Sn0wbreeze"/><category term="Spine"/><category term="Strategies"/><category term="StronlyTyped"/><category term="Subtle Motion"/><category term="Swiffy"/><category term="Sync"/><category term="Syntax Highligthing"/><category term="Tactics"/><category term="Tags"/><category term="Transformer"/><category term="Transients API"/><category term="Transitions"/><category term="Travel"/><category term="Typefaces"/><category term="URL"/><category term="URLs"/><category term="Unicode"/><category term="Untethered"/><category term="User Agents"/><category term="User Profiles"/><category term="Version Control"/><category term="WTF"/><category term="Web Enhancement"/><category term="Web Files"/><category term="Web Hosting"/><category term="WebSockets"/><category term="Webkit"/><category term="Website Optimization"/><category term="Widgets"/><category term="Windows 7"/><category term="Windows Media Player"/><category term="WordPress Multisite"/><category term="WordPress Shortcodes"/><category term="YQL"/><category term="Yahoo"/><category term="YouTube"/><category term="car"/><category term="engagement day"/><category term="family"/><category term="iCloud"/><category term="iPhone 5"/><category term="including Flash"/><category term="jQuery Media Plugin"/><category term="jQuery UI"/><category term="jinsan"/><category term="langkawi"/><category term="malsup"/><category term="media"/><category term="prettyPhoto"/><category term="proposal day"/><category term="proton wira"/><category term="rehearsal"/><category term="sport car"/><category term="we"/><category term="善恶录"/><category term="订婚日"/><title type='text'>vZhai: Info Sharing Blog</title><subtitle type='html'>Sharing information about Web Technology, Web Design, Web Development, Web Apps, HTML/HTML5, CSS/CSS3, jQuery, JavaScript, PHP, MySQL, iPhone Apps, iPad Apps, and others interesting topics.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://vzhai.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>575</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-3782399001359346102</id><published>2012-11-07T11:07:00.001+08:00</published><updated>2012-11-07T11:08:07.911+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery Mobile"/><title type='text'>The Latest Updates to jQuery Mobile</title><content type='html'>Not too long ago, the jQuery team released &lt;a href=&quot;http://jquerymobile.com/&quot;&gt;jQuery Mobile 1.2&lt;/a&gt;. This new release has some fantastic changes! In this article, we&#39;re going to review some of the new widgets available to developers, take a look at changes made to existing widgets, and glance over a few impactful enhancements that could affect your jQuery Mobile application. Let&#39;s get started, shall we?&lt;br /&gt;
&lt;br /&gt;
Firstly, we&#39;ll need to download the bits and bytes. Head over to the &lt;a href=&quot;http://jquerymobile.com/download/&quot;&gt;jQuery Mobile download page&lt;/a&gt; and download the option that best meets your needs. Alternately you can just use the boilerplate code provided below.&lt;br /&gt;
Additionally, now might be a good time to quickly discuss the &lt;a href=&quot;http://jquerymobile.com/download-builder/&quot;&gt;Download Builder&lt;/a&gt; that the jQuery Mobile team is building. It&#39;s still in Alpha, but it allows you to customize your download to include only the parts of jQuery Mobile that you require, and nothing more. You can exclude specific events, transitions, form elements, or widgets that you don&#39;t care about. It&#39;s meant for the developers who are ultra-concerned with grasping the highest level of performance out of his or her application.&lt;br /&gt;
&lt;hr /&gt;
&lt;h2&gt;
Widgets&lt;/h2&gt;
The beating heart of any jQuery Mobile application are its widgets. Arguably they&#39;re the most visible part of the page, and the part that allows users to interact with the page in such an easy manner. The jQuery Mobile team has spent countless hours testing, building, and refining their widgets to make sure that they&#39;re the best they can be. In version 1.2, the team has really knocked it out of the park with a widget that developers have been asking for since the framework was first released: popup modals.&lt;br /&gt;
&lt;h3&gt;
Popups&lt;/h3&gt;
A popup modal is a small section of the page that overlays other parts of the page. They&#39;re most typically used as tooltips, or to display photos, maps, and additional content. This information is usually not important enough to warrant another page, but is still important to need displaying by itself. The way jQuery Mobile 1.2 has implemented popups is perfect. Let&#39;s learn how easy it is to add popups to a project.&lt;br /&gt;
A quick note, for the sake of brevity: all of the code samples below will use the following boilerplate HTML. The jQuery Mobile CSS and JS files (including jQuery) are hotlinked using the jQuery CDN for your convenience.&lt;br /&gt;
&lt;pre&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&amp;gt;
    &amp;lt;title&amp;gt;jQuery Mobile 1.2&amp;lt;/title&amp;gt;
    &amp;lt;link rel=&quot;stylesheet&quot;  href=&quot;http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css&quot; /&amp;gt;
    &amp;lt;script src=&quot;http://code.jquery.com/jquery-1.8.0.min.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script src=&quot;http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div data-role=&quot;content&quot;&amp;gt;
        &amp;lt;!-- your content goes here --&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;
Adding a popup to a page in your application is a two-step process. First you&#39;ll need some means of triggering the popup. This is generally a link, or button, or something the user interacts with. To trigger element, we add the following attribute:&lt;br /&gt;
&lt;pre&gt;data-rel=&quot;popup&quot;
&lt;/pre&gt;
Second, you need the content to be displayed. This could range from a single &lt;code&gt;div&lt;/code&gt; to a &lt;code&gt;menu&lt;/code&gt;, a &lt;code&gt;form&lt;/code&gt;, or even photos. The content element gets its own attribute:&lt;br /&gt;
&lt;pre&gt;data-role=&quot;popup&quot;
&lt;/pre&gt;
Finally, for simple link buttons, the &lt;code&gt;href&lt;/code&gt; attribute must correspond to the &lt;code&gt;id&lt;/code&gt; of the content to be displayed. Let&#39;s review the complete implementation.&lt;br /&gt;
&lt;pre&gt;&amp;lt;a href=&quot;#simplepopup&quot; data-rel=&quot;popup&quot;&amp;gt;Open Popup&amp;lt;/a&amp;gt;
&amp;lt;div data-role=&quot;popup&quot; id=&quot;simplepopup&quot;&amp;gt;
    &amp;lt;p&amp;gt;This is a completely basic popup, no options set.&amp;lt;p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
What you&#39;ll see on the page should look something similar to this:&lt;br /&gt;
&lt;div&gt;
&lt;img alt=&quot;Simple popup&quot; border=&quot;0&quot; src=&quot;http://d2o0t5hpnwv4c1.cloudfront.net/2150_NewInjQueryMobile/images/popup-simple.png&quot; title=&quot;&quot; /&gt;&lt;/div&gt;
&lt;h4&gt;
Tooltips&lt;/h4&gt;
Now that you know how to create a popup, let&#39;s look at other possibilities. One common use is a tooltip; help text or expanded text shown when a user clicks on a button. Set up the code the same as before:&lt;br /&gt;
&lt;pre&gt;&amp;lt;a href=&quot;#tooltip&quot; data-rel=&quot;popup&quot; data-role=&quot;button&quot;&amp;gt;Find out more&amp;lt;/a&amp;gt;
&amp;lt;div data-role=&quot;popup&quot; id=&quot;tooltip&quot; data-theme=&quot;e&quot;&amp;gt;
    &amp;lt;p&amp;gt;You found out more!.&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
This time, we&#39;re styling the resulting content using the &lt;strong&gt;e&lt;/strong&gt; swatch from jQuery Mobile to give it a more pleasant appearance. This helps us remember that popups are first class jQuery Mobile citizens, and can be treated just like anything else on the page.&lt;br /&gt;
&lt;h4&gt;
Menus&lt;/h4&gt;
Let&#39;s move on to something a bit more complicated: a menu. That&#39;s a popular approach to page navigation. Give the user the a menu right at their fingertips. So what does that look like with popups?&lt;br /&gt;
&lt;pre&gt;&amp;lt;a href=&quot;#menu&quot; data-rel=&quot;popup&quot; data-role=&quot;button&quot;&amp;gt;Menu&amp;lt;/a&amp;gt;
&amp;lt;div data-role=&quot;popup&quot; id=&quot;menu&quot; data-theme=&quot;a&quot;&amp;gt;
    &amp;lt;ul data-role=&quot;listview&quot; data-theme=&quot;c&quot; data-inset=&quot;true&quot;&amp;gt;
        &amp;lt;li data-role=&quot;divider&quot; data-theme=&quot;a&quot;&amp;gt;My Menu&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;Unlinked&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href=&quot;methods.html&quot;&amp;gt;Linked&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href=&quot;methods.html&quot;&amp;gt;With count&amp;lt;/a&amp;gt;&amp;lt;span class=&quot;ui-li-count&quot;&amp;gt;42&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
    &amp;lt;/ul&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
And the resulting output should resemble this:&lt;br /&gt;
&lt;div&gt;
&lt;img alt=&quot;Popup menu&quot; border=&quot;0&quot; src=&quot;http://d2o0t5hpnwv4c1.cloudfront.net/2150_NewInjQueryMobile/images/popups-menu.png&quot; title=&quot;&quot; /&gt;&lt;/div&gt;
You can also use 1.2&#39;s collapsible lists in popups. Here&#39;s a quick example:&lt;br /&gt;
&lt;pre&gt;&amp;lt;a href=&quot;#nestedmenu&quot; data-rel=&quot;popup&quot; data-role=&quot;button&quot;&amp;gt;Nested Menu&amp;lt;/a&amp;gt;
&amp;lt;div data-role=&quot;popup&quot; id=&quot;nestedmenu&quot; data-theme=&quot;none&quot;&amp;gt;
    &amp;lt;div data-role=&quot;collapsible-set&quot; data-theme=&quot;b&quot; data-content-theme=&quot;c&quot; data-collapsed-icon=&quot;arrow-r&quot; data-expanded-icon=&quot;arrow-d&quot; style=&quot;margin:0; width:250px;&quot;&amp;gt;
        &amp;lt;div data-role=&quot;collapsible&quot; data-inset=&quot;false&quot;&amp;gt;
            &amp;lt;h2&amp;gt;Colors&amp;lt;/h2&amp;gt;
            &amp;lt;ul data-role=&quot;listview&quot;&amp;gt;
                &amp;lt;li&amp;gt;&amp;lt;a href=&quot;#&quot;&amp;gt;Red&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
                &amp;lt;li&amp;gt;&amp;lt;a href=&quot;#&quot;&amp;gt;Blue&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
            &amp;lt;/ul&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div data-role=&quot;collapsible&quot; data-inset=&quot;false&quot;&amp;gt;
            &amp;lt;h2&amp;gt;Shapes&amp;lt;/h2&amp;gt;
            &amp;lt;ul data-role=&quot;listview&quot;&amp;gt;
                &amp;lt;li&amp;gt;&amp;lt;a href=&quot;#&quot;&amp;gt;Circle&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
                &amp;lt;li&amp;gt;&amp;lt;a href=&quot;#&quot;&amp;gt;Square&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
            &amp;lt;/ul&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
And the results:&lt;br /&gt;
&lt;div&gt;
&lt;img alt=&quot;Popup menu&quot; border=&quot;0&quot; src=&quot;http://d2o0t5hpnwv4c1.cloudfront.net/2150_NewInjQueryMobile/images/popups-nested-menu.png&quot; title=&quot;&quot; /&gt;&lt;/div&gt;
It&#39;s worth noting that &lt;strong&gt;data-inset=&quot;true&quot;&lt;/strong&gt; is required on the &lt;code&gt;listview&lt;/code&gt; or the corners of your list will show up. Try and you&#39;ll see.&lt;br /&gt;
&lt;h4&gt;
Forms&lt;/h4&gt;
Another popular UX approach is to show a login form hovering over the top of a page. That&#39;s now possible with jQuery Mobile popups. Here&#39;s a simple username/password form.&lt;br /&gt;
&lt;pre&gt;&amp;lt;a href=&quot;#login&quot; data-rel=&quot;popup&quot; data-position-to=&quot;window&quot; data-role=&quot;button&quot;&amp;gt;Login&amp;lt;/a&amp;gt;
&amp;lt;div data-role=&quot;popup&quot; id=&quot;login&quot; data-theme=&quot;a&quot;&amp;gt;
    &amp;lt;form style=&quot;padding:10px 20px;&quot;&amp;gt;
        &amp;lt;h3&amp;gt;Please sign in&amp;lt;/h3&amp;gt;
        &amp;lt;label for=&quot;un&quot; class=&quot;ui-hidden-accessible&quot;&amp;gt;Username:&amp;lt;/label&amp;gt;
        &amp;lt;input type=&quot;js&quot; name=&quot;user&quot; id=&quot;un&quot; placeholder=&quot;username&quot; /&amp;gt;
        &amp;lt;label for=&quot;pw&quot; class=&quot;ui-hidden-accessible&quot;&amp;gt;Password:&amp;lt;/label&amp;gt;
        &amp;lt;input type=&quot;password&quot; name=&quot;pass&quot; id=&quot;pw&quot; placeholder=&quot;password&quot; /&amp;gt;
        &amp;lt;button type=&quot;submit&quot; data-theme=&quot;b&quot;&amp;gt;Sign in&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
Which gives you:&lt;br /&gt;
&lt;div&gt;
&lt;img alt=&quot;Popup menu&quot; border=&quot;0&quot; src=&quot;http://d2o0t5hpnwv4c1.cloudfront.net/2150_NewInjQueryMobile/images/popup-form.png&quot; title=&quot;&quot; /&gt;&lt;/div&gt;
By default, popups center themselves over the object which triggered them. There&#39;s an optional attribute which you&#39;ll see in the next three examples. It&#39;s &lt;strong&gt;data-position-to=&quot;window&quot;&lt;/strong&gt; and you apply it to the element which triggers the popup. Try adding that to the &lt;strong&gt;Login&lt;/strong&gt; button above to see what happens.&lt;br /&gt;
&lt;h4&gt;
Dialogs&lt;/h4&gt;
A common need for web applications is the ability to interact with the user. We just reviewed one approach: a login form. But, sometimes, you need to prompt the user with questions. A dialog is a perfect solution for this; and what do you know, popups have you covered! So what does that code look like? Here&#39;s a simple example:&lt;br /&gt;
&lt;pre&gt;&amp;lt;a href=&quot;#dialog&quot; data-rel=&quot;popup&quot; data-position-to=&quot;window&quot; data-role=&quot;button&quot; data-transition=&quot;pop&quot;&amp;gt;Dialog&amp;lt;/a&amp;gt;
&amp;lt;div data-role=&quot;popup&quot; id=&quot;dialog&quot; data-overlay-theme=&quot;a&quot; data-theme=&quot;c&quot;&amp;gt;
    &amp;lt;div data-role=&quot;header&quot; data-theme=&quot;a&quot;&amp;gt;
        &amp;lt;h1&amp;gt;Delete Page?&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div data-role=&quot;content&quot; data-theme=&quot;d&quot;&amp;gt;
        &amp;lt;h3&amp;gt;Are you sure you want to delete this page?&amp;lt;/h3&amp;gt;
        &amp;lt;p&amp;gt;This action cannot be undone.&amp;lt;/p&amp;gt;
        &amp;lt;a href=&quot;#&quot; data-role=&quot;button&quot; data-inline=&quot;true&quot; data-rel=&quot;back&quot; data-theme=&quot;c&quot;&amp;gt;No&amp;lt;/a&amp;gt;
        &amp;lt;a href=&quot;#&quot; data-role=&quot;button&quot; data-inline=&quot;true&quot; data-rel=&quot;back&quot; data-theme=&quot;b&quot;&amp;gt;Yes, Delete it&amp;lt;/a&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
&lt;div&gt;
&lt;img alt=&quot;Popup menu&quot; border=&quot;0&quot; src=&quot;http://d2o0t5hpnwv4c1.cloudfront.net/2150_NewInjQueryMobile/images/popup-dialog.png&quot; title=&quot;&quot; /&gt;&lt;/div&gt;
In the popup content container, note another new attribute for your use: &lt;strong&gt;data-overlay-theme=&quot;a&quot;&lt;/strong&gt;. This attribute is what applies the shaded background to the dialog box. It&#39;s affected by your theme, so be careful when working with themes created with &lt;a href=&quot;http://jqueryui.com/themeroller/&quot;&gt;ThemeRoller&lt;/a&gt;.&lt;br /&gt;
&lt;h4&gt;
Photos&lt;/h4&gt;
I can&#39;t count the number of times I&#39;ve seen jQuery Mobile developers ask for some better way of handling image galleries. While popups aren&#39;t the perfect solution for large numbers of images, they&#39;re great for a handful of images that need to be viewed larger. Even better, it’s incredibly easy; check it out:&lt;br /&gt;
&lt;pre&gt;&amp;lt;a href=&quot;#photo&quot; data-rel=&quot;popup&quot; data-position-to=&quot;window&quot; data-role=&quot;button&quot; data-transition=&quot;fade&quot;&amp;gt;Photo&amp;lt;/a&amp;gt;
&amp;lt;div data-role=&quot;popup&quot; id=&quot;photo&quot; data-overlay-theme=&quot;a&quot; data-theme=&quot;d&quot; data-corners=&quot;false&quot;&amp;gt;
    &amp;lt;a href=&quot;#&quot; data-rel=&quot;back&quot; data-role=&quot;button&quot; data-theme=&quot;a&quot; data-icon=&quot;delete&quot; data-iconpos=&quot;nojs&quot; class=&quot;ui-btn-right&quot;&amp;gt;Close&amp;lt;/a&amp;gt;&amp;lt;img src=&quot;http://lorempixel.com/450/300/food/&quot; /&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
The above code gives you an elegant photo centered to the window, including a close window button.&lt;br /&gt;
&lt;div&gt;
&lt;img alt=&quot;Popup menu&quot; border=&quot;0&quot; src=&quot;http://d2o0t5hpnwv4c1.cloudfront.net/2150_NewInjQueryMobile/images/popup-photo.png&quot; title=&quot;&quot; /&gt;&lt;/div&gt;
How did they do that? Within the context of a popup, the &lt;code&gt;anchor&lt;/code&gt; tag has attributes which behave slightly different than when used in other locations on the page. Specifically, the &lt;strong&gt;ui-btn-right&lt;/strong&gt; class positions the image in the corner of the image rather than the side, while the &lt;strong&gt;data-icon&lt;/strong&gt; and &lt;strong&gt;data-iconpos&lt;/strong&gt; attributes allow you to style the button just as you would a regular button.&lt;br /&gt;
You can get pretty fancy with popups including, but not limited to, displaying inline video and even interactive maps. Check the &lt;a href=&quot;http://jquerymobile.com/demos/1.2.0/docs/pages/popup/popup-iframes.html&quot;&gt;jQuery Mobile documentation for popups and iframes&lt;/a&gt;.&lt;br /&gt;
&lt;h3&gt;
Collapsible List Views&lt;/h3&gt;
Another great new feature is the ability to combine collapsible sets with list views. Call &#39;em “Collapsible List Views” and you&#39;ve got a brand new widget in jQuery Mobile 1.2. How do they work? I&#39;m glad you asked. Simply create any list you like, then wrap it in a collapsible set. Collapsible List Views also support multiple lists – so get crazy!&lt;br /&gt;
&lt;pre&gt;&amp;lt;div data-role=&quot;collapsible&quot; data-theme=&quot;b&quot; data-content-theme=&quot;c&quot;&amp;gt;
    &amp;lt;h2&amp;gt;Favorite Spice Girl?&amp;lt;/h2&amp;gt;
    &amp;lt;ul data-role=&quot;listview&quot;&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href=&quot;index.html&quot;&amp;gt;Posh&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href=&quot;index.html&quot;&amp;gt;Scary&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href=&quot;index.html&quot;&amp;gt;Sporty&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href=&quot;index.html&quot;&amp;gt;Baby&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href=&quot;index.html&quot;&amp;gt;Ginger&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
    &amp;lt;/ul&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
The code above would result in this Collapsible List View:&lt;br /&gt;
&lt;div&gt;
&lt;img alt=&quot;Popup menu&quot; border=&quot;0&quot; src=&quot;http://d2o0t5hpnwv4c1.cloudfront.net/2150_NewInjQueryMobile/images/listview-collapsible.png&quot; title=&quot;&quot; /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;h2&gt;
Enhancements&lt;/h2&gt;
In addition to new widget types, jQuery Mobile 1.2 provides a number of useful enhancements to existing functionality. Let&#39;s take a look at some of the more valuable ones.&lt;br /&gt;
&lt;h3&gt;
jQuery Support Changes&lt;/h3&gt;
One of the biggest enhancements made in version 1.2 is the added support for jQuery 1.8. This brings some significant performance increases in the form of a completely rewritten Sizzle.js (the selector engine for jQuery), along with numerous other improvements.&lt;br /&gt;
The tradeoff is that the jQuery Mobile team decided that it was time to sunset support for jQuery 1.6. This may be unfortunate  for some folks out there who are still using older versions of jQuery, but it’s a fair trade.&lt;br /&gt;
&lt;h3&gt;
List View Autodividers&lt;/h3&gt;
If you&#39;ve ever had to manage a list of constantly changing people, places, or things in jQuery Mobile then, you&#39;ve probably had to write some tricky code to display dynamic listview headers. Bummer that you spent all that time, because the jQuery Mobile team made it as easy as dropping in a single attribute.&lt;br /&gt;
&lt;pre&gt;data-autodividers=&quot;true&quot;
&lt;/pre&gt;
That turns this list:&lt;br /&gt;
&lt;div&gt;
&lt;img alt=&quot;Popup menu&quot; border=&quot;0&quot; src=&quot;http://d2o0t5hpnwv4c1.cloudfront.net/2150_NewInjQueryMobile/images/listview-dividers-before.png&quot; title=&quot;&quot; /&gt;&lt;/div&gt;
Into:&lt;br /&gt;
&lt;div&gt;
&lt;img alt=&quot;Popup menu&quot; border=&quot;0&quot; src=&quot;http://d2o0t5hpnwv4c1.cloudfront.net/2150_NewInjQueryMobile/images/listview-dividers-after.png&quot; title=&quot;&quot; /&gt;&lt;/div&gt;
Note that this does not manage sorting, grouping, or filtering. For that sort of functionality, consider trying my &lt;a href=&quot;http://andymatthews.net/code/jqm-tinysort/&quot;&gt;jQuery Mobile Tinysort plugin&lt;/a&gt;.&lt;br /&gt;
&lt;h3&gt;
Read-Only Lists&lt;/h3&gt;
jQuery Mobile offers &quot;read-only&quot; list views, but it was difficult to tell that they weren&#39;t clickable. Version 1.2 removes the list gradient, making the row a flat color. This should provide a better visual cue to your users.&lt;br /&gt;
&lt;h3&gt;
Better Width adjustments on Form Elements&lt;/h3&gt;
Version 1.2 fixes a semi-annoying issue with form elements, whereby they wouldn&#39;t take up the full width of their parent element in some cases.&lt;br /&gt;
&lt;h3&gt;
Additional Devices Added&lt;/h3&gt;
You might have noticed that new devices are being added almost on a daily basis. The jQuery Mobile team does their best to test against as many of these devices as possible. Newly added to the A grade platform list are the following devices/operating systems/browsers: iOS 6, Android 4.1 (Jellybean), Tizen, Firefox for Android, and Kindle Fire HD.&lt;br /&gt;
&lt;hr /&gt;
&lt;h2&gt;
Full List of Changes&lt;/h2&gt;
You can find a complete list of the changes made for version 1.2 on the &lt;a href=&quot;http://jquerymobile.com/blog/2012/10/02/announcing-jquery-mobile-1-2-0-final/#changelog&quot;&gt;jQuery Mobile blog&lt;/a&gt;.&lt;br /&gt;
I hope that some of these improvements will help to improve your applications. Remember that the jQuery Mobile team is on your side! If you see something that you think would be valuable, ask for it: create an issue in &lt;a href=&quot;https://github.com/jquery/jquery-mobile&quot;&gt;their Github repository&lt;/a&gt;, and suggest it. Better yet, fork their repo and add some code yourself!&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
Source: &lt;a href=&quot;http://net.tutsplus.com/&quot;&gt;http://net.tutsplus.com/&lt;/a&gt;&lt;/div&gt;
&lt;img height=&quot;1&quot; src=&quot;http://feeds.feedburner.com/~r/nettuts/~4/05Uf-v1kENc&quot; width=&quot;1&quot; /&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/3782399001359346102'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/3782399001359346102'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/11/the-latest-updates-to-jquery-mobile.html' title='The Latest Updates to jQuery Mobile'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-7751051504864263591</id><published>2012-06-19T17:59:00.001+08:00</published><updated>2012-06-19T18:00:17.103+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Database"/><category scheme="http://www.blogger.com/atom/ns#" term="PDO API"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorial"/><title type='text'>PHP Database Access: Are You Doing It Correctly?</title><content type='html'>We&#39;ve covered PHP&#39;s PDO API a &lt;a href=&quot;http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/&quot;&gt;couple&lt;/a&gt; of &lt;a href=&quot;http://net.tutsplus.com/tutorials/php/pdo-vs-mysqli-which-should-you-use/&quot;&gt;times&lt;/a&gt; here on Nettuts+, but, generally, those articles focused more on the theory, and less on the application. This article will fix that!&lt;br /&gt;
To put it plainly, if you&#39;re still using PHP&#39;s old &lt;code&gt;mysql&lt;/code&gt; API to connect to your databases, read on!&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;h2&gt;
What?&lt;/h2&gt;
It&#39;s possible that, at this point, the only thought in your mind is, &quot;What the heck is PDO?&quot; Well, it&#39;s one of PHP&#39;s three available APIs for connecting to a MySQL database. &quot;Three,&quot; you say? Yes; many folks don&#39;t know it, but there are three different APIs for connecting:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;mysql&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mysqli&lt;/code&gt; – MySQL Improved&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pdo&lt;/code&gt; – PHP Data Objects&lt;/li&gt;
&lt;/ul&gt;
The traditional &lt;code&gt;mysql&lt;/code&gt; API certainly gets the job done, and has become so popular largely due to the fact that it makes the process of retrieving some records from a database as easy as possible. For example:&lt;br /&gt;
&lt;pre&gt;/*
 * Anti-Pattern
 */

# Connect
mysql_connect(&#39;localhost&#39;, &#39;username&#39;, &#39;password&#39;) or die(&#39;Could not connect: &#39; . mysql_error());

# Choose a database
mysql_select_db(&#39;someDatabase&#39;) or die(&#39;Could not select database&#39;);

# Perform database query
$query = &quot;SELECT * from someTable&quot;;
$result = mysql_query($query) or die(&#39;Query failed: &#39; . mysql_error());

# Filter through rows and echo desired information
while ($row = mysql_fetch_object($result)) {
    echo $row-&amp;gt;name;
}
&lt;/pre&gt;
Yes, the code above is fairly simple, but it does come with its significant share of downsides. &lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Deprecated: &lt;/strong&gt;Though it hasn&#39;t been officially deprecated – due to widespread use – in terms of best practice and education, it might as well be.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Escaping: &lt;/strong&gt;The process of escaping user input is left to the developer – many of which don&#39;t understand or know how to sanitize the data.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Flexibility: &lt;/strong&gt;The API isn&#39;t flexible; the code above is tailor-made for working with a MySQL database. What if you switch?&lt;/li&gt;
&lt;/ul&gt;
PDO, or PHP Data Objects, provides a more powerful API that doesn&#39;t care about the driver you use; it&#39;s database agnostic. Further, it offers the ability to use prepared statements, virtually eliminating any worry of SQL injection. &lt;br /&gt;
&lt;hr /&gt;
&lt;h2&gt;
How?&lt;/h2&gt;
When I was first learning about the PDO API, I must admit that it was slightly intimidating. This wasn&#39;t because the API was overly complicated (it&#39;s not) – it&#39;s just that the old &lt;code&gt;myqsl&lt;/code&gt; API was so dang easy to use!&lt;br /&gt;
Don&#39;t worry, though; follow these simple steps, and you&#39;ll be up and running in no time. &lt;br /&gt;
&lt;h3&gt;
Connect&lt;/h3&gt;
So you already know the legacy way of connecting to a MySQL database:&lt;br /&gt;
&lt;pre&gt;# Connect
mysql_connect(&#39;localhost&#39;, &#39;username&#39;, &#39;password&#39;) or die(&#39;Could not connect: &#39; . mysql_error());
&lt;/pre&gt;
With PDO, we create a new instance of the class, and specify the driver, database name, username, and password – like so:&lt;br /&gt;
&lt;pre&gt;$conn = new PDO(&#39;mysql:host=localhost;dbname=myDatabase&#39;, $username, $password);
&lt;/pre&gt;
Don&#39;t let that long string confuse you; it&#39;s really very simple: we specify the name of the driver (mysql, in this case), followed by the required details (connection string) for connecting to it.&lt;br /&gt;
What&#39;s nice about this approach is that, if we instead wish to use a sqlite database, we simply update the DSN, or &quot;Data Source Name,&quot; accordingly; we&#39;re not dependent upon MySQL in the way that we are when use functions, like &lt;code&gt;mysql_connect&lt;/code&gt;.&lt;br /&gt;
&lt;h4&gt;
Errors&lt;/h4&gt;
But, what if there&#39;s an error, and we can&#39;t connect to the database? Well, let&#39;s wrap everything within a &lt;code&gt;try/catch&lt;/code&gt; block:&lt;br /&gt;
&lt;pre&gt;try {
    $conn = new PDO(&#39;mysql:host=localhost;dbname=myDatabase&#39;, $username, $password);
    $conn-&amp;gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    echo &#39;ERROR: &#39; . $e-&amp;gt;getMessage();
}
&lt;/pre&gt;
That&#39;s better! Please note that, by default, the default error mode for PDO is &lt;code&gt;PDO::ERRMODE_SILENT&lt;/code&gt;. With this setting left unchanged, you&#39;ll need to manually fetch errors, after performing a query.&lt;br /&gt;
&lt;pre&gt;echo $conn-&amp;gt;errorCode();
echo $conn-&amp;gt;errorInfo();
&lt;/pre&gt;
Instead, a better choice, during development, is to update this setting to &lt;code&gt;PDO::ERRMODE_EXCEPTION&lt;/code&gt;, which will fire exceptions as they occur. This way, any uncaught exceptions will halt the script.&lt;br /&gt;
For reference, the available options are:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;PDO::ERRMODE_SILENT&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;PDO::ERRMODE_WARNING&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;PDO::ERRMODE_EXCEPTION&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
Fetch&lt;/h3&gt;
At this point, we&#39;ve created a connection to the database; let&#39;s fetch some information from it. There&#39;s two core ways to accomplish this task: &lt;code&gt;query&lt;/code&gt; and &lt;code&gt;execute&lt;/code&gt;. We&#39;ll review both.&lt;br /&gt;
&lt;h4&gt;
Query&lt;/h4&gt;
&lt;pre&gt;/*
 * The Query Method
 * Anti-Pattern
 */

$name = &#39;Joe&#39;; # user-supplied data

try {
    $conn = new PDO(&#39;mysql:host=localhost;dbname=myDatabase&#39;, $username, $password);
    $conn-&amp;gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $data = $conn-&amp;gt;query(&#39;SELECT * FROM myTable WHERE name = &#39; . $conn-&amp;gt;quote($name));

    foreach($data as $row) {
        print_r($row);
    }
} catch(PDOException $e) {
    echo &#39;ERROR: &#39; . $e-&amp;gt;getMessage();
}
&lt;/pre&gt;
Though this works, notice that we&#39;re still manually escaping the user&#39;s data with the &lt;code&gt;PDO::quote&lt;/code&gt; method. Think of this method as, more or less, the PDO equivalent to use &lt;code&gt;mysql_real_escape_string&lt;/code&gt;; it will both escape and quote the string that you pass to it. In situations, when you&#39;re binding user-supplied data to a SQL query, it&#39;s strongly advised that you instead use prepared statements. That said, if your SQL queries are not dependent upon form data, the &lt;code&gt;query&lt;/code&gt; method is a helpful choice, and makes the process of looping through the results as easy as a &lt;code&gt;foreach&lt;/code&gt; statement.&lt;br /&gt;
&lt;h4&gt;
Prepared Statements&lt;/h4&gt;
&lt;pre&gt;/*
 * The Prepared Statements Method
 * Best Practice
 */

$id = 5;
try {
    $conn = new PDO(&#39;mysql:host=localhost;dbname=myDatabase&#39;, $username, $password);
    $conn-&amp;gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);    

    $stmt = $conn-&amp;gt;prepare(&#39;SELECT * FROM myTable WHERE id = :id&#39;);
    $stmt-&amp;gt;execute(array(&#39;id&#39; =&amp;gt; $id));

    while($row = $stmt-&amp;gt;fetch()) {
        print_r($row);
    }
} catch(PDOException $e) {
    echo &#39;ERROR: &#39; . $e-&amp;gt;getMessage();
}
&lt;/pre&gt;
In this example, we&#39;re using the &lt;code&gt;prepare&lt;/code&gt; method to, literally, prepare the query, before the user&#39;s data has been attached. With this technique, SQL injection is virtually impossible, because the data doesn&#39;t ever get inserted into the SQL query, itself. Notice that, instead, we use named parameters (&lt;code&gt;:id&lt;/code&gt;) to specify placeholders. &lt;br /&gt;
&lt;blockquote&gt;
Alternatively, you could use &lt;code&gt;?&lt;/code&gt; parameters, however, it makes for a less-readable experience. Stick with named parameters.&lt;/blockquote&gt;
Next, we execute the query, while passing an array, which contains the data that should be bound to those placeholders.&lt;br /&gt;
&lt;pre&gt;$stmt-&amp;gt;execute(array(&#39;id&#39; =&amp;gt; $id));
&lt;/pre&gt;
An alternate, but perfectly acceptable, approach would be to use the &lt;code&gt;bindParam&lt;/code&gt; method, like so:&lt;br /&gt;
&lt;pre&gt;$stmt-&amp;gt;bindParam(&#39;:id&#39;, $id, PDO::PARAM_INT);
$stmt-&amp;gt;execute();
&lt;/pre&gt;
&lt;h4&gt;
Specifying the Ouput&lt;/h4&gt;
After calling the &lt;code&gt;execute&lt;/code&gt; method, there are a variety of different ways to receive the data: an array (the default), an object, etc. In the example above, the default response is used: &lt;code&gt;PDO::FETCH_ASSOC&lt;/code&gt;; this can easily be overridden, though, if necessary:&lt;br /&gt;
&lt;pre&gt;while($row = $stmt-&amp;gt;fetch(PDO::FETCH_OBJ)) {
    print_r($row);
}
&lt;/pre&gt;
Now, we&#39;ve specified that we want to interact with the result set in a more object-oriented fashion. Available choices include, but not limited to:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;PDO::FETCH_ASSOC: &lt;/strong&gt;Returns an array.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PDO::FETCH_BOTH: &lt;/strong&gt; Returns an array, indexed by both column-name, and 0-indexed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PDO::FETCH_BOUND: &lt;/strong&gt; Returns TRUE and assigns the values of the columns in your result set to the PHP variables to which they were bound.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PDO::FETCH_CLASS: &lt;/strong&gt; Returns a new instance of the specified class.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PDO::FETCH_OBJ: &lt;/strong&gt;  Returns an anonymous object, with property names that correspond to the columns.&lt;/li&gt;
&lt;/ul&gt;
One problem with the code above is that we aren&#39;t providing any feedback, if no results are returned. Let&#39;s fix that:&lt;br /&gt;
&lt;pre&gt;$stmt-&amp;gt;execute(array(&#39;id&#39; =&amp;gt; $id));

# Get array containing all of the result rows
$result = $stmt-&amp;gt;fetchAll();

# If one or more rows were returned...
if ( count($result) ) {
    foreach($result as $row) {
        print_r($row);
    }
} else {
    echo &quot;No rows returned.&quot;;
}
&lt;/pre&gt;
At this point, our full code should look like so:&lt;br /&gt;
&lt;pre&gt;$id = 5;
  try {
    $conn = new PDO(&#39;mysql:host=localhost;dbname=someDatabase&#39;, $username, $password);
    $stmt = $conn-&amp;gt;prepare(&#39;SELECT * FROM myTable WHERE id = :id&#39;);
    $stmt-&amp;gt;execute(array(&#39;id&#39; =&amp;gt; $id));

    $result = $stmt-&amp;gt;fetchAll();

    if ( count($result) ) {
      foreach($result as $row) {
        print_r($row);
      }
    } else {
      echo &quot;No rows returned.&quot;;
    }
  } catch(PDOException $e) {
      echo &#39;ERROR: &#39; . $e-&amp;gt;getMessage();
  }
&lt;/pre&gt;
&lt;h3&gt;
Multiple Executions&lt;/h3&gt;
The PDO extension becomes particularly powerful when executing the same SQL query multiple times, but with different parameters.&lt;br /&gt;
&lt;pre&gt;try {
  $conn = new PDO(&#39;mysql:host=localhost;dbname=someDatabase&#39;, $username, $password);
  $conn-&amp;gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  # Prepare the query ONCE
  $stmt = $conn-&amp;gt;prepare(&#39;INSERT INTO someTable VALUES(:name)&#39;);
  $stmt-&amp;gt;bindParam(&#39;:name&#39;, $name);

  # First insertion
  $name = &#39;Keith&#39;;
  $stmt-&amp;gt;execute();

  # Second insertion
  $name = &#39;Steven&#39;;
  $stmt-&amp;gt;execute();
} catch(PDOException $e) {
  echo $e-&amp;gt;getMessage();
}
&lt;/pre&gt;
Once the query has been prepared, it can be executed multiple times, with different parameters. The code above will insert two rows into the database: one with a name of “Kevin,” and the other, “Steven.”&lt;br /&gt;
&lt;hr /&gt;
&lt;h2&gt;
CRUD&lt;/h2&gt;
Now that you have the basic process in place, let’s quickly review the various CRUD tasks. As you’ll find, the required code for each is virtually identical.&lt;br /&gt;
&lt;h3&gt;
Create (Insert)&lt;/h3&gt;
&lt;pre&gt;try {
  $pdo = new PDO(&#39;mysql:host=localhost;dbname=someDatabase&#39;, $username, $password);
  $pdo-&amp;gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  $stmt = $pdo-&amp;gt;prepare(&#39;INSERT INTO someTable VALUES(:name)&#39;);
  $stmt-&amp;gt;execute(array(
    &#39;:name&#39; =&amp;gt; &#39;Justin Bieber&#39;
  ));

  # Affected Rows?
  echo $stmt-&amp;gt;rowCount(); // 1
} catch(PDOException $e) {
  echo &#39;Error: &#39; . $e-&amp;gt;getMessage();
&lt;/pre&gt;
&lt;h3&gt;
Update&lt;/h3&gt;
&lt;pre&gt;$id = 5;
$name = &quot;Joe the Plumber&quot;;

try {
  $pdo = new PDO(&#39;mysql:host=localhost;dbname=someDatabase&#39;, $username, $password);
  $pdo-&amp;gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  $stmt = $pdo-&amp;gt;prepare(&#39;UPDATE someTable SET name = :name WHERE id = :id&#39;);
  $stmt-&amp;gt;execute(array(
    &#39;:id&#39;   =&amp;gt; $id,
    &#39;:name&#39; =&amp;gt; $name
  ));

  echo $stmt-&amp;gt;rowCount(); // 1
} catch(PDOException $e) {
  echo &#39;Error: &#39; . $e-&amp;gt;getMessage();
}
&lt;/pre&gt;
&lt;h3&gt;
Delete&lt;/h3&gt;
&lt;pre&gt;$id = 5; // From a form or something similar

try {
  $pdo = new PDO(&#39;mysql:host=localhost;dbname=someDatabase&#39;, $username, $password);
  $pdo-&amp;gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  $stmt = $pdo-&amp;gt;prepare(&#39;DELETE FROM someTable WHERE id = :id&#39;);
  $stmt-&amp;gt;bindParam(&#39;:id&#39;, $id); // this time, we&#39;ll use the bindParam method
  $stmt-&amp;gt;execute();

  echo $stmt-&amp;gt;rowCount(); // 1
} catch(PDOException $e) {
  echo &#39;Error: &#39; . $e-&amp;gt;getMessage();
}
&lt;/pre&gt;
&lt;h3&gt;
Object Mapping&lt;/h3&gt;
One of the neatest aspects of PDO (mysqli, as well) is that it gives us the ability to map the query results to a class instance, or object. Here’s an example:&lt;br /&gt;
&lt;pre&gt;class User {
  public $first_name;
  public $last_name;

  public function full_name()
  {
    return $this-&amp;gt;first_name . &#39; &#39; . $this-&amp;gt;last_name;
  }
}

try {
  $pdo = new PDO(&#39;mysql:host=localhost;dbname=someDatabase&#39;, $username, $password);
  $pdo-&amp;gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  $result = $pdo-&amp;gt;query(&#39;SELECT * FROM someTable&#39;);

  # Map results to object
  $result-&amp;gt;setFetchMode(PDO::FETCH_CLASS, &#39;User&#39;);

  while($user = $result-&amp;gt;fetch()) {
    # Call our custom full_name method
    echo $user-&amp;gt;full_name();
  }
} catch(PDOException $e) {
  echo &#39;Error: &#39; . $e-&amp;gt;getMessage();
}
&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;
Closing Thoughts&lt;/h2&gt;
Bottom line: if you’re still using that old &lt;code&gt;mysql&lt;/code&gt; API for connecting to your databases, stop. Though it hasn’t yet been deprecated, in terms of education and &lt;a href=&quot;http://news.php.net/php.internals/53799&quot;&gt;documentation&lt;/a&gt;, it might as well be. Your code will be significantly more secure and streamlined if you adopt the PDO extension. &lt;br /&gt;
&lt;div&gt;
&lt;a href=&quot;http://feeds.feedburner.com/~ff/nettuts?a=KBQuCrPTVYo:wTsp8Zdq0h0:yIl2AUoC8zA&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://feeds.feedburner.com/~ff/nettuts?d=yIl2AUoC8zA&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.feedburner.com/~ff/nettuts?a=KBQuCrPTVYo:wTsp8Zdq0h0:F7zBnMyn0Lo&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://feeds.feedburner.com/~ff/nettuts?i=KBQuCrPTVYo:wTsp8Zdq0h0:F7zBnMyn0Lo&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.feedburner.com/~ff/nettuts?a=KBQuCrPTVYo:wTsp8Zdq0h0:V_sGLiPBpWU&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://feeds.feedburner.com/~ff/nettuts?i=KBQuCrPTVYo:wTsp8Zdq0h0:V_sGLiPBpWU&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.feedburner.com/~ff/nettuts?a=KBQuCrPTVYo:wTsp8Zdq0h0:gIN9vFwOqvQ&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://feeds.feedburner.com/~ff/nettuts?i=KBQuCrPTVYo:wTsp8Zdq0h0:gIN9vFwOqvQ&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.feedburner.com/~ff/nettuts?a=KBQuCrPTVYo:wTsp8Zdq0h0:TzevzKxY174&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://feeds.feedburner.com/~ff/nettuts?d=TzevzKxY174&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;img height=&quot;1&quot; src=&quot;http://feeds.feedburner.com/~r/nettuts/~4/KBQuCrPTVYo&quot; width=&quot;1&quot; /&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/7751051504864263591'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/7751051504864263591'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/06/php-database-access-are-you-doing-it.html' title='PHP Database Access: Are You Doing It Correctly?'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-2026788073674372378</id><published>2012-06-19T17:52:00.001+08:00</published><updated>2012-06-19T17:53:43.161+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Credit Cards"/><category scheme="http://www.blogger.com/atom/ns#" term="Payment"/><category scheme="http://www.blogger.com/atom/ns#" term="PayPal"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorial"/><title type='text'>How to Process Credit Cards with PayPal Payments Pro Using PHP</title><content type='html'>PayPal is one of the most popular payment processing platforms available today for many reasons. Its ease of use and its connection to the eBay platform are just the tip of the iceberg. While one of its most popular features is the ability to simply sign in to your PayPal account to submit payments, merchants using PayPal can also accept credit cards directly just like a traditional &lt;a href=&quot;http://www.usbswiper.com/usbswiper-low-transaction-rates.php&quot;&gt;merchant account&lt;/a&gt; solution would provide.&lt;br /&gt;
&lt;br /&gt;
PayPal calls this solution Payments Pro, and I’m going to show you exactly how you can process credit cards directly with PayPal’s API using their &lt;a href=&quot;https://www.x.com/developers/paypal/products/paypal-payments-pro&quot;&gt;Payments Pro web service API’s&lt;/a&gt;.&lt;br /&gt;
&lt;hr /&gt;
&lt;h2&gt;
Step 1: Setup the Directory Structure&lt;/h2&gt;
The first thing I like to do with any project is to create a basic structure organized for the project.&amp;nbsp; In this case, our structure is very simple as our project will consist of only 2 files:&lt;br /&gt;
&lt;div&gt;
&lt;img alt=&quot;Directory Structure&quot; height=&quot;73&quot; src=&quot;http://d2o0t5hpnwv4c1.cloudfront.net/2056_paypalpro/directory-structure.png&quot; width=&quot;197&quot; /&gt;&lt;/div&gt;
&amp;nbsp;As you might have guessed, we’ll be storing our configuration information in config.php, and we’ll actually handle the processing code in &lt;code&gt;process-credit-card.php&lt;/code&gt;.&lt;br /&gt;
&lt;hr /&gt;
&lt;h2&gt;
Step 2: Setup the Config File&lt;/h2&gt;
Our &lt;code&gt;/includes/config.php&lt;/code&gt; file will house our values for the PayPal API information we need including the end-point URL, API version, and our API username, password, and signature that we’ll be using.&amp;nbsp; &lt;br /&gt;
&lt;pre&gt;// Set sandbox (test mode) to true/false.
$sandbox = TRUE;

// Set PayPal API version and credentials.
$api_version = &#39;85.0&#39;;
$api_endpoint = $sandbox ? &#39;https://api-3t.sandbox.paypal.com/nvp&#39; : &#39;https://api-3t.paypal.com/nvp&#39;;
$api_username = $sandbox ? &#39;SANDBOX_USERNAME_GOES_HERE&#39; : &#39;LIVE_USERNAME_GOES_HERE&#39;;
$api_password = $sandbox ? &#39;SANDBOX_PASSWORD_GOES_HERE&#39; : &#39;LIVE_PASSWORD_GOES_HERE&#39;;
$api_signature = $sandbox ? &#39;SANDBOX_SIGNATURE_GOES_HERE&#39; : &#39;LIVE_SIGNATURE_GOES_HERE&#39;;
&lt;/pre&gt;
Reviewing the &lt;code&gt;config.php&lt;/code&gt; code, you can see that first we set a variable for &lt;code&gt;$sandbox&lt;/code&gt;.&amp;nbsp; For now, we’ll leave this to &lt;code&gt;TRUE&lt;/code&gt; because we want to interact with PayPal’s sandbox (test) servers for development purposes.&amp;nbsp; You’ll need to remember to change this to &lt;code&gt;FALSE&lt;/code&gt; when you’re ready to move your project to a live server.&lt;br /&gt;
Then, based on the value of &lt;code&gt;$sandbox&lt;/code&gt; we’re setting values to other variables for our API information.&amp;nbsp; You’ll just want to fill in those placeholders with your own details accordingly.&amp;nbsp; Now we’re ready to build our credit card processing script.&lt;br /&gt;
&lt;hr /&gt;
&lt;h2&gt;
Step 3: Create an API Request&lt;/h2&gt;
Now we can begin to build our &lt;code&gt;process-credit-card.php&lt;/code&gt; page.&amp;nbsp; The first thing we need to do here is include our config file.&lt;br /&gt;
&lt;pre&gt;// Include config file
require_once(&#39;includes/config.php&#39;);
&lt;/pre&gt;
Next, we need to build a name-value-pair string that includes all of the data we need to send PayPal in order to process this payment.&amp;nbsp; A name-value-pair string looks just like something you might see when passing data via URL parameters.&amp;nbsp; We just need to make sure our parameter names are in all caps.&lt;br /&gt;
&lt;pre&gt;PARAM1=value1&amp;amp;amp;PARAM2=value2&amp;amp;amp;PARAM3=value3…etc.&lt;/pre&gt;
So, you might be thinking to yourself “How do I know what to use for my variable names in my string?”&amp;nbsp; The good news is &lt;a href=&quot;https://www.x.com/developers/paypal/documentation-tools/api/dodirectpayment-api-operation-nvp&quot;&gt;PayPal provides very good documentation&lt;/a&gt; on this.&amp;nbsp; We can see all of the possible variables that we can pass PayPal including customer details, order item details, and credit card information.&amp;nbsp; Some of this information is required in order to process a payment, but many of the variables available are optional.&amp;nbsp; For demonstration purposes, we’ll keep this pretty simple and just pass the required information.&lt;br /&gt;
We’ll store all of our request parameters in an array so that we can loop through this array to easily generate our NVP string.&amp;nbsp; All requests require the following parameters by default:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;METHOD&lt;/code&gt; – The name of the API call you’re making.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;USER&lt;/code&gt; – The API username&lt;/li&gt;
&lt;li&gt;&lt;code&gt;PWD&lt;/code&gt; – The API password&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SIGNATURE&lt;/code&gt; – The API signature&lt;/li&gt;
&lt;li&gt;&lt;code&gt;VERSION&lt;/code&gt; – The API version&lt;/li&gt;
&lt;/ul&gt;
Then you can refer to the &lt;a href=&quot;https://www.x.com/developers/paypal/documentation-tools/api/dodirectpayment-api-operation-nvp&quot;&gt;PayPal documentation for any API request&lt;/a&gt; you’d like to make to see what other parameters should be included.&amp;nbsp; For the sake of this demonstration, our array will be built as follows.&lt;br /&gt;
&lt;pre&gt;// Store request params in an array
$request_params = array
     (
     &#39;METHOD&#39; =&amp;gt; &#39;DoDirectPayment&#39;,
     &#39;USER&#39; =&amp;gt; $api_username,
     &#39;PWD&#39; =&amp;gt; $api_password,
     &#39;SIGNATURE&#39; =&amp;gt; $api_signature,
     &#39;VERSION&#39; =&amp;gt; $api_version,
     &#39;PAYMENTACTION&#39; =&amp;gt; &#39;Sale&#39;,
     &#39;IPADDRESS&#39; =&amp;gt; $_SERVER[&#39;REMOTE_ADDR&#39;],
     &#39;CREDITCARDTYPE&#39; =&amp;gt; &#39;MasterCard&#39;,
     &#39;ACCT&#39; =&amp;gt; &#39;5522340006063638&#39;,
     &#39;EXPDATE&#39; =&amp;gt; &#39;022013&#39;,
     &#39;CVV2&#39; =&amp;gt; &#39;456&#39;,
     &#39;FIRSTNAME&#39; =&amp;gt; &#39;Tester&#39;,
     &#39;LASTNAME&#39; =&amp;gt; &#39;Testerson&#39;,
     &#39;STREET&#39; =&amp;gt; &#39;707 W. Bay Drive&#39;,
     &#39;CITY&#39; =&amp;gt; &#39;Largo&#39;,
     &#39;STATE&#39; =&amp;gt; &#39;FL&#39;,
     &#39;COUNTRYCODE&#39; =&amp;gt; &#39;US&#39;,
     &#39;ZIP&#39; =&amp;gt; &#39;33770&#39;,
     &#39;AMT&#39; =&amp;gt; &#39;100.00&#39;,
     &#39;CURRENCYCODE&#39; =&amp;gt; &#39;USD&#39;,
     &#39;DESC&#39; =&amp;gt; &#39;Testing Payments Pro&#39;
     );
&lt;/pre&gt;
You’ll notice we’re using our config variables from &lt;code&gt;config.php&lt;/code&gt;, and then I’m simply loading static data for the other values.&amp;nbsp; In a standard project, though, you’ll most likely be populating these values with form data, session data, or some other form of dynamic data.&lt;br /&gt;
Now we can simply loop through this array to generate our NVP string.&lt;br /&gt;
&lt;pre&gt;// Loop through $request_params array to generate the NVP string.
$nvp_string = &#39;&#39;;
foreach($request_params as $var=&amp;gt;$val)
{
 $nvp_string .= &#39;&amp;amp;&#39;.$var.&#39;=&#39;.urlencode($val);
}
&lt;/pre&gt;
The value of &lt;code&gt;$nvp_string&lt;/code&gt; is now:&lt;br /&gt;
&lt;pre&gt;METHOD=DoDirectPayment&amp;amp;amp;amp;USER=sandbo*****e.com&amp;amp;amp;amp;PWD=12***74&amp;amp;amp;amp;SIGNATURE=AiKZ******6W18v&amp;amp;amp;amp;VERSION=85.0&amp;amp;amp;amp;PAYMENTACTION=Sale&amp;amp;amp;amp;IPADDRESS=72.135.111.9&amp;amp;amp;amp;CREDITCARDTYPE=MasterCard&amp;amp;amp;amp;ACCT=5522340006063638&amp;amp;amp;amp;EXPDATE=022013&amp;amp;amp;amp;CVV2=456&amp;amp;amp;amp;FIRSTNAME=Tester&amp;amp;amp;amp;LASTNAME=Testerson&amp;amp;amp;amp;STREET=707+W.+Bay+Drive&amp;amp;amp;amp;CITY=Largo&amp;amp;amp;amp;STATE=FL&amp;amp;amp;amp;COUNTRYCODE=US&amp;amp;amp;amp;ZIP=33770&amp;amp;amp;amp;AMT=100.00&amp;amp;amp;amp;CURRENCYCODE=USD&amp;amp;amp;amp;DESC=Testing+Payments+Pro&lt;/pre&gt;
This string is what we’ll send to PayPal for our request.&lt;br /&gt;
&lt;hr /&gt;
&lt;h2&gt;
Step 4: Send the HTTP Request to PayPal&lt;/h2&gt;
Now that our NVP string is ready to go we need to send this to the PayPal server to be processed accordingly.&amp;nbsp; To do this, we’ll use PHP’s CURL methods.&lt;br /&gt;
&lt;pre&gt;// Send NVP string to PayPal and store response
$curl = curl_init();
  curl_setopt($curl, CURLOPT_VERBOSE, 1);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($curl, CURLOPT_TIMEOUT, 30);
  curl_setopt($curl, CURLOPT_URL, $api_endpoint);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);

$result = curl_exec($curl);
curl_close($curl);
&lt;/pre&gt;
Here you can see that we’ve setup CURL with a few simple options and we’re using our &lt;code&gt;$api_endpoint &lt;/code&gt;and &lt;code&gt;$nvp_string&lt;/code&gt; variables accordingly.&lt;br /&gt;
This data will be sent over to PayPal and we will receive the API response back in our &lt;code&gt;$result&lt;/code&gt; variable so that we can see the result and send the user to a successful or failure page based on whether or not the call succeeded or not.&lt;br /&gt;
&lt;hr /&gt;
&lt;h2&gt;
Step 5: Parse the API Response&lt;/h2&gt;
The value that we get back in &lt;code&gt;$result &lt;/code&gt;from the previous step will be an NVP string just like the one we generated and sent to PayPal.&amp;nbsp; When we run our current script we get a successful response back that looks like this:&lt;br /&gt;
&lt;pre&gt;TIMESTAMP=2012%2d04%2d16T07%3a59%3a36Z&amp;amp;amp;CORRELATIONID=9eb40cd84a7d3&amp;amp;amp;ACK=Success&amp;amp;amp;VERSION=85%2e0&amp;amp;amp;BUILD=2764190&amp;amp;amp;AMT=100%2e00&amp;amp;amp;CURRENCYCODE=USD&amp;amp;amp;AVSCODE=X&amp;amp;amp;CVV2MATCH=M&amp;amp;amp;TRANSACTIONID=160896645A8111040&lt;/pre&gt;
One very simple way to parse this result is to use PHP’s &lt;code&gt;parse_str() &lt;/code&gt;function.&amp;nbsp; This will load all of the response data into PHP variables matching the names and values returned in the response.&amp;nbsp; For example, if we do the following:&lt;br /&gt;
&lt;pre&gt;// Parse the API response
  $nvp_response_array = parse_str($result);
  &lt;/pre&gt;
We would end up with access to the following PHP variables:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$TIMESTAMP&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$CORRELATIONID&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$ACK&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$VERSION&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$BUILD&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$AMT&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$CURRENCYCODE&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$AVSCODE&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$CVV2MATCH&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$TRANSACTIONID &lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
We can then proceed to use these variables to present information back to our customer, populate values in email receipts we’d like to generate, update database information, or anything else we need to do once an order is completed.&lt;br /&gt;
The &lt;code&gt;$ACK&lt;/code&gt; value is what will tell us whether or not the API call was successful or not.&amp;nbsp; Values for &lt;code&gt;$ACK&lt;/code&gt; can be: &lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Success&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SuccessWithWarning&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Failure &lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;FailureWithWarning&lt;/code&gt;&lt;/li&gt;
&amp;nbsp; 
You can simply redirect your user where they need to go and show them information based on this value.
A failing API call will result in additional parameters that provide information about why the transaction failed.&amp;nbsp; If I run this test again with an invalid credit card number, for example, I get the following response back from PayPal:
&lt;pre&gt;TIMESTAMP=2012%2d04%2d16T08%3a08%3a52Z&amp;amp;amp;CORRELATIONID=590d41dbb31e0&amp;amp;amp;ACK=Failure&amp;amp;amp;VERSION=85%2e0&amp;amp;amp;BUILD=2764190&amp;amp;amp;L_ERRORCODE0=10527&amp;amp;amp;L_SHORTMESSAGE0=Invalid%20Data&amp;amp;amp;L_LONGMESSAGE0=This%20transaction%20cannot%20be%20processed%2e%20Please%20enter%20a%20valid%20credit%20card%20number%20and%20type%2e&amp;amp;amp;L_SEVERITYCODE0=Error&amp;amp;amp;AMT=100%2e00&amp;amp;amp;CURRENCYCODE=USD&lt;/pre&gt;
Now, when we use &lt;code&gt;parse_str()&lt;/code&gt; we end up with the following PHP variables available to us:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$TIMESTAMP&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$CORRELATIONID&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$ACK&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$VERSION&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$BUILD&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$L_ERRORCODE0&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$L_SHORTMESSAGE0&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$L_LONGMESSAGE0&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$L_SEVERITYCODE0&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$AMT&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$CURRENCYCODE&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
In this case, &lt;code&gt;$ACK&lt;/code&gt; shows a Failure so we know the call did not succeed and we can check the error parameters for more details about what went wrong.
&lt;h3&gt;
Additional Data Parsing Option&lt;/h3&gt;
While the previous method of parsing the response works just fine, I personally prefer to work with data arrays.&amp;nbsp; As such, I use the following function to convert the PayPal response into an array.
&lt;pre&gt;// Function to convert NTP string to an array
function NVPToArray($NVPString)
{
 $proArray = array();
 while(strlen($NVPString))
 {
  // name
  $keypos= strpos($NVPString,&#39;=&#39;);
  $keyval = substr($NVPString,0,$keypos);
  // value
  $valuepos = strpos($NVPString,&#39;&amp;amp;&#39;) ? strpos($NVPString,&#39;&amp;amp;&#39;): strlen($NVPString);
  $valval = substr($NVPString,$keypos+1,$valuepos-$keypos-1);
  // decoding the respose
  $proArray[$keyval] = urldecode($valval);
  $NVPString = substr($NVPString,$valuepos+1,strlen($NVPString));
 }
 return $proArray;
}
&lt;/pre&gt;
This allows me to see all of the response data available by simply looking at the contents of the array:
If I run my script again now I get the following result on screen:
&lt;pre&gt;Array
(
&amp;nbsp;&amp;nbsp;&amp;nbsp; [TIMESTAMP] =&amp;gt; 2012-04-16T08:15:41Z
&amp;nbsp;&amp;nbsp;&amp;nbsp; [CORRELATIONID] =&amp;gt; 9a652cbabfdd9
&amp;nbsp;&amp;nbsp;&amp;nbsp; [ACK] =&amp;gt; Success
&amp;nbsp;&amp;nbsp;&amp;nbsp; [VERSION] =&amp;gt; 85.0
&amp;nbsp;&amp;nbsp;&amp;nbsp; [BUILD] =&amp;gt; 2764190
&amp;nbsp;&amp;nbsp;&amp;nbsp; [AMT] =&amp;gt; 100.00
&amp;nbsp;&amp;nbsp;&amp;nbsp; [CURRENCYCODE] =&amp;gt; USD
&amp;nbsp;&amp;nbsp;&amp;nbsp; [AVSCODE] =&amp;gt; X
&amp;nbsp;&amp;nbsp;&amp;nbsp; [CVV2MATCH] =&amp;gt; M
&amp;nbsp;&amp;nbsp;&amp;nbsp; [TRANSACTIONID] =&amp;gt; 6VR832690S591564M
)
&lt;/pre&gt;
And If I were to cause an error again I get the following:
&lt;pre&gt;Array
(
&amp;nbsp;&amp;nbsp;&amp;nbsp; [TIMESTAMP] =&amp;gt; 2012-04-16T08:18:46Z
&amp;nbsp;&amp;nbsp;&amp;nbsp; [CORRELATIONID] =&amp;gt; 2db182b912a9
&amp;nbsp;&amp;nbsp;&amp;nbsp; [ACK] =&amp;gt; Failure
&amp;nbsp;&amp;nbsp;&amp;nbsp; [VERSION] =&amp;gt; 85.0
&amp;nbsp;&amp;nbsp;&amp;nbsp; [BUILD] =&amp;gt; 2764190
&amp;nbsp;&amp;nbsp;&amp;nbsp; [L_ERRORCODE0] =&amp;gt; 10527
&amp;nbsp;&amp;nbsp;&amp;nbsp; [L_SHORTMESSAGE0] =&amp;gt; Invalid Data
&amp;nbsp;&amp;nbsp;&amp;nbsp; [L_LONGMESSAGE0] =&amp;gt; This transaction cannot be processed. Please enter a valid credit card number and type.
&amp;nbsp;&amp;nbsp;&amp;nbsp; [L_SEVERITYCODE0] =&amp;gt; Error
&amp;nbsp;&amp;nbsp;&amp;nbsp; [AMT] =&amp;gt; 100.00
&amp;nbsp;&amp;nbsp;&amp;nbsp; [CURRENCYCODE] =&amp;gt; USD
)
&lt;/pre&gt;
You can see this is a nice, easy to navigate result array that contains everything we might need to move the user through our application and update data sources as necessary.
&lt;hr /&gt;
&lt;h2&gt;
Conclusion&lt;/h2&gt;
As you can see, processing credit cards using PayPal Payments Pro is actually a very simple procedure.&amp;nbsp; It just involves a few standard steps for working with API web services, and a basic knowledge of working with array data can help as well.
Good luck, and happy coding!
&lt;img height=&quot;1&quot; src=&quot;http://feeds.feedburner.com/~r/nettuts/~4/Z2GXyUS0ybw&quot; width=&quot;1&quot; /&gt;&lt;/ul&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/2026788073674372378'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/2026788073674372378'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/06/how-to-process-credit-cards-with-paypal.html' title='How to Process Credit Cards with PayPal Payments Pro Using PHP'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-3909687401820442830</id><published>2012-04-26T23:04:00.001+08:00</published><updated>2012-04-26T23:06:04.613+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Layout"/><category scheme="http://www.blogger.com/atom/ns#" term="Media Queries"/><category scheme="http://www.blogger.com/atom/ns#" term="Responsive"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorial"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Design"/><title type='text'>Responsive Web Design: Layouts and Media Queries</title><content type='html'>With the growing number of Smartphone produced in the last three years and the diversity of screen sizes it’s practically impossible to ignore users that browse on a mobile device. Whether they use an Android phone, Windows Mobile phone, a BlackBerry device or an iPhone, whether they are on a tablet, on a Smartphone or on a big screen, each user deserves the best experience possible. As designers, it is our goal to provide those users a nice experience browsing the websites we created, whatever the device used to browse is.&lt;br /&gt;
Today most of the clients want their website to be &lt;strong&gt;mobile compatible&lt;/strong&gt;, so this is particularly challenging. Creating a version for each device is impossible, due to the number and diversity of those devices, but also simply because we don’t know what will be created tomorrow. That’s where the concept of “Responsive Webdesign” comes to the rescue.&lt;br /&gt;
&lt;img alt=&quot;Responsive Web Design: Layouts and Media Queries&quot; height=&quot;360&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/04/stillloveyou.jpg&quot; title=&quot;Responsive Web Design: Layouts and Media Queries&quot; width=&quot;580&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A responsive website is a website that will respond and adapt to the user’s behavior and screen size.  The idea is to resize and reorder the design, adapt images, typography, columns, etc., based on screen - browser size, resolution and orientation instead of providing each device a specific website.  &lt;br /&gt;
&lt;h2&gt;
A Look at 3 Different Types of Layout&lt;/h2&gt;
&lt;h4&gt;
Basic Fluid Layout&lt;/h4&gt;
Fluid layout is based on a system of relative units instead of absolute pixels. This kind of layout has been around for a while now, and most of the designers use fluid grids created in percentage to achieve such layouts.&lt;br /&gt;
The idea is pretty simple: instead of giving the layout rigid width in pixels, we will give it relative ones in percentage. The fluid layout based websites usually take the whole browser width, hence the 100% in this example.&lt;br /&gt;
You can see a demo of a fluid design &lt;a href=&quot;http://www.onextrapixel.com/examples/responsive-design/example1_fluid.php&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;img alt=&quot;Fluid&quot; height=&quot;403&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/04/fluid.jpg&quot; title=&quot;Fluid&quot; width=&quot;580&quot; /&gt;&lt;br /&gt;
&lt;em&gt;Data JavaScript credit: &lt;a href=&quot;https://twitter.com/#%21/andreasbovens&quot;&gt;Andreas Bovens&lt;/a&gt;&lt;/em&gt;&lt;br /&gt;
The &lt;code&gt;style.css&lt;/code&gt; gives us common styles for the page &lt;em&gt;(color, typo)&lt;/em&gt;, but let’s take a look at our &lt;code&gt;fluid.CSS&lt;/code&gt; file : &lt;br /&gt;
&lt;pre&gt;#header {
    width: 100%;
    margin: 0;
    padding: 0;
}
#content {
    float: left;
    width: 60%;
    margin: 0 0 20px 0;
    padding: 0;
}
#content .inner {
    margin-right: 2%;
}
.sidebar{
    float: left;
    margin: 0 0 20px 1%;
    padding: 0;
}
#bar1{
    width:20%;
}
#bar2{
    width:18%;
}
#footer {
    clear: both;
    width: 100%;
    margin: 0;
    padding: 0;
}
&lt;/pre&gt;
Our header and footer have a 100% width, so they’ll take the whole screen available. The main content has a 60%, and our sidebars 20% and 18% so that we will be able to create a design that will fit the whole space available.&lt;br /&gt;
This design adapts perfectly on big screens, but we can see that the sidebar content tend to become hard to read when we resize too small.&lt;br /&gt;
&lt;h4&gt;
Adaptive Layout&lt;/h4&gt;
The adaptive layout is based on a pretty simple idea: instead of using percentage we will give our layout fixe sizes, but we will adapt those sizes depending of the width of the browser/viewport, thus creating a layout with different “break points”.&lt;br /&gt;
For each of those break point, we will use media queries &lt;em&gt;(will come back to explain them in detail in the second part of the article)&lt;/em&gt; to adapt the layout of our website so that content is not too hard to read.&lt;br /&gt;
You can see and example of adaptive layout &lt;a href=&quot;http://www.onextrapixel.com/examples/responsive-design/example2_adaptative.php&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;img alt=&quot;Adaptive&quot; height=&quot;403&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/04/adaptive-demo.jpg&quot; title=&quot;Adaptive&quot; width=&quot;580&quot; /&gt;&lt;br /&gt;
The HTML and &lt;code&gt;style.css&lt;/code&gt; did not change; all we changed was the structure of the page. Let’s take a closer look at our CSS file.&lt;br /&gt;
The &quot;normal&quot; website uses this CSS: &lt;br /&gt;
&lt;pre&gt;body{
    width:1280px;
    margin:0 auto;
}
#header {
    width: 100%;
    margin: 0;
    padding: 0;
}
#content {
    float: left;
    width: 800px;
    margin: 0 0 20px 0;
    padding: 0;
}
#content .bloc{
    margin-right: 10px;
}
.sidebar{
    float: left;
    margin: 0 0 20px 20px;
    padding: 0;
    width:220px;
}
#footer {
    clear: both;
    width: 100%;
    margin: 0;
    padding: 0;
}
&lt;/pre&gt;
I gave the header and footer a 100% width, but the content has a fixed width. Now the good part, the break points with media queries:&lt;br /&gt;
&lt;pre&gt;/* Media queries */
@media screen and (max-width: 1200px) {
    body{
    width:1000px;
    margin:0 auto;
    }
    #content {
    width: 700px;
    }
    .sidebar{
    width:280px;
    }
}

@media screen and (max-width: 980px) {
body{
    width:850px;
    margin:0 auto;
    }
    #content {
    width: 550px;
    }
    .sidebar{
    width:280px;
    }
}

@media screen and (max-width: 750px) {
    body{
    width:600px;
    margin:0 auto;
    }
    #content {
    width: 400px;
    }
    .sidebar{
    width:190px;
    margin: 0 0 20px 10px;
    }
}

@media screen and (max-width: 540px) {
    body{
    width:450px;
    margin:0 auto;
    }
    #content {
    width: 450px;
    }
    #content .bloc{
    margin:0px;
    }
    .sidebar{
    width:450px;
    margin: 0 0 10px 0;
    }
}

@media screen and (max-width: 380px) {
    body{
    width:360px;
    margin:0 auto;
    }
    #content {
    width: 360px;
    }
    #content .bloc {
    margin:0px;
    }
    .sidebar{
    width:360px;
    margin: 0 0 10px 0;
    }
}
&lt;/pre&gt;
For each break point given by a media query, I changed the size of the body, the content, and the sidebar. Under &lt;code&gt;540px&lt;/code&gt;, the text in the sidebar was too hard to read, so I gave the sidebar the same size as the content, what has the effect of putting the sidebars under the content.&lt;br /&gt;
This nice thing about adaptive layout is the possibility to modify and adapt not only the size of the blocs, but the layout and there place on the page.&lt;br /&gt;
The big difficulty is then to choose those break points. A first technique could be to base the break points on most &quot;common&quot; device width. Chris Coyier from CSStricks put &lt;a href=&quot;http://css-tricks.com/snippets/css/media-queries-for-standard-devices/&quot;&gt;a nice list of media queries together&lt;/a&gt;. Another way to choose the break points it to actually test the design at different screen sizes and see when it gets ugly or when user can’t really read the text easily, and put break point at those size.&lt;br /&gt;
Live example of adaptive layout :&lt;br /&gt;
&lt;a href=&quot;http://foodsense.is/&quot;&gt;Foodsense&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://foodsense.is/&quot;&gt;&lt;img alt=&quot;Adaptive Example&quot; height=&quot;403&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/04/adaptive.jpg&quot; title=&quot;Adaptive Example&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h4&gt;
Responsive Layout&lt;/h4&gt;
We could define the responsive layout, as a mix between the fluid and adaptive layouts. It will use the relative units of the fluid layout and the break points of the adaptive one.&lt;br /&gt;
Here you can see &lt;a href=&quot;http://www.onextrapixel.com/examples/responsive-design/example3_responsive.php&quot;&gt;the demo of our previous example, in responsive layout&lt;/a&gt;.&lt;br /&gt;
&lt;img alt=&quot;Responsive Example&quot; height=&quot;403&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/04/responsiveexample.jpg&quot; title=&quot;Responsive Example&quot; width=&quot;580&quot; /&gt;&lt;br /&gt;
You can see here how fluid the design is: using percentage enables us to create very smooth transition between the different break points of our design.&lt;br /&gt;
Here is our stylesheet for the &quot;normal&quot; version:  &lt;br /&gt;
&lt;pre&gt;#page{
    max-width:1280px;
}
#header {
    width: 100%;
    margin: 0;
    padding: 0;
}
#content {
    float: left;
    width: 60%;
    margin: 0 0 20px 0;
    padding: 0;
}
#content .bloc {
    margin-right: 2%;
}
.sidebar{
    float: left;
    margin: 0 0 20px 1%;
    padding: 0;
}
#bar1{
    width:20%;
}
#bar2{
    width:18%;
}
#footer {
    clear: both;
    width: 100%;
    margin: 0;
    padding: 0;
}
&lt;/pre&gt;
What’s important here is the use of &lt;code&gt;max-width&lt;/code&gt; &lt;em&gt;(instead of width for an adaptive layout)&lt;/em&gt;. It’s this property that enables us to create this smooth transition. Using a max-width, we won’t have to use as many break points as for an adaptive layout, and all the other sizes will be given in a relative unit &lt;em&gt;(percentage for our example)&lt;/em&gt;.&lt;br /&gt;
And the CSS for the media queries:&lt;br /&gt;
&lt;pre&gt;/* The media queries*/
@media screen and (max-width: 1000px) {
    #bar1,
    #bar2{
    width:39%;
    }
    .sidebar{
    float: left;
    margin: 0 0 20px 1%;
    padding: 0;
    }
}

@media screen and (max-width: 540px) {
    #bar1,
    #bar2{
    clear:both;
    width:100%;
    }
    .sidebar{
    float: left;
    margin: 0 0 20px 1%;
    padding: 0;
    }
    #content {
    clear:both;
    width:100%;
    }
    #content .bloc {
    margin:0;
    }
}
&lt;/pre&gt;
All the other size will be once again given in percentage, relative to the &lt;code&gt;max-width&lt;/code&gt; of our body.&lt;br /&gt;
Note that for screen size under 540px, we once again gave the sidebars and the content a 100% width, and place the sidebars under the content using some clear: both.&lt;br /&gt;
The advantage of the responsive layout is that you won’t have to use too many break points. Since the size are given in percentage, they will adapt automatically, so the major role of the break points will be to be place where design breaks, to re-order our layout &lt;em&gt;(putting sidebars under content in our example)&lt;/em&gt; and give the user a more pleasant reading.&lt;br /&gt;
&lt;a href=&quot;http://forefathersgroup.com/&quot;&gt;Fore Fathers Group&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&quot;Responsive&quot; height=&quot;403&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/04/responsive.jpg&quot; title=&quot;Responsive&quot; width=&quot;580&quot; /&gt;&lt;br /&gt;
&lt;h2&gt;
Media Queries: Create and Define Break Points&lt;/h2&gt;
Media queries where introduced in the CSS3 specifications. Put in a simple way, media queries enables the web designer to create conditionals stylesheets based on width, height, but also orientation, color, etc. There’s a huge list of media queries available on &lt;a href=&quot;http://www.w3.org/TR/CSS3-mediaqueries/&quot;&gt;the official w3c website&lt;/a&gt; but we will only use some of them in our case.  Here is a list of the most commonly used media queries and what they do :&lt;br /&gt;
&lt;h4&gt;
Media Query Utilisation&lt;/h4&gt;
&lt;table&gt;&lt;thead&gt;
&lt;tr&gt; &lt;td&gt;&lt;strong&gt;Media Query&lt;/strong&gt;&lt;/td&gt; &lt;td&gt;&lt;strong&gt;Use&lt;/strong&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/thead&gt; &lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;min-width:  … px&lt;/td&gt; &lt;td&gt;Used when the viewport’s width is bigger or equal to width&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;max-width:  … px&lt;/td&gt; &lt;td&gt;Used when the viewport’s width is smaller or equal to width&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;min-device-width: … px&lt;/td&gt; &lt;td&gt;Used when the device’s width is bigger or equal to width&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;max-device-width: … px&lt;/td&gt; &lt;td&gt;Used when the device’s width is smaller or equal to width&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;orientation  : portrait // orientation: landscape&lt;/td&gt; &lt;td&gt;Target orientation&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;-webkit-min-device-pixel-ratio : 1.5&lt;/td&gt; &lt;td&gt;Used to target high density device on android and ios&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
As for print style sheets, media queries can be used as external or internal styles sheets. An external style sheet is easier to organize, it is not downloaded by browsers which don’t support it, but it uses extra http request. An internal style sheet on the other hand does not require extra http request, but the whole stylesheet is downloaded for browsers even if they do not support media queries, and it can be harder to organize. Both have then pro and cons, you’ll have.&lt;br /&gt;
You already saw the internal syntax in the example above: &lt;br /&gt;
&lt;pre&gt;body {
    background: gray;
}
@media all and (max-width:500px) {
body {
        background: blue;
    }
}
&lt;/pre&gt;
And here is the external syntaxes:&lt;br /&gt;
&lt;pre&gt;&amp;lt;link rel=&quot;stylesheet&quot; type=&quot;text/CSS&quot;  media=&quot;screen and (max-device-width: 480px) &quot; href=&quot;mobile.CSS&quot; /&amp;gt;
&lt;/pre&gt;
&lt;h2&gt;
Some &quot;tricks&quot; Worth Knowing About Media Queries&lt;/h2&gt;
&lt;h4&gt;
Cascade Matters&lt;/h4&gt;
Yeah that’s right, as for any peace of CSS code, cascade matters.&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;pre&gt;#container{
background:rgba(111, 78, 152, 0.9); /*violet */
color:rgb(1, 1, 1);

@media all and (min-width:500px) {
    #container{
    background: rgba(255, 0, 0, 0.9); /* red */
    color: white;
    }
}
@media all and (min-width:700px) {
   #container{
    background: rgba(0, 0, 255,0.9); /*blue */
    font-family: serif;
    }
}
&lt;/pre&gt;
See the example on &lt;a href=&quot;http://jsfiddle.net/inpixelitrust/fvTrc/embedded/result/&quot;&gt;jsfiddle&lt;/a&gt;.&lt;br /&gt;
If the width of our browser is bigger than &lt;code&gt;500px&lt;/code&gt;, the color of the text gets white, and the background &lt;code&gt;red&lt;/code&gt;. If we enlarge the screen up to more than &lt;code&gt;700px&lt;/code&gt;, the background gets blue, but the color of the text stays white because it inherited the color of the &lt;code&gt;min-width:500px&lt;/code&gt; media query applied before &lt;em&gt;(700 being, well, bigger than 500)&lt;/em&gt;.&lt;br /&gt;
&lt;h4&gt;
Creating Stacked Media Queries&lt;/h4&gt;
Consider the following example :&lt;br /&gt;
&lt;pre&gt;#container{
    background:rgba(111, 78, 152, 0.9); /*violet */
    padding:10px 5px;
    color:rgb(1, 1, 1);
}

@media all and (min-width:500px) and (max-width:699px) {
   #container{
   background: rgba(255, 0, 0, 0.9); /* rouge */
   font-family: serif;
   }
}
@media all and (min-width:700px) {
   #container{
   background: rgba(0, 0, 255,0.9); /*bleu */
   color: white;
   font-family: serif;
   }
}
&lt;/pre&gt;
See the example on &lt;a href=&quot;http://jsfiddle.net/inpixelitrust/mDRmC/embedded/result/&quot;&gt;jsfiddle&lt;/a&gt;.&lt;br /&gt;
The first media query will only be applied for screen between &lt;code&gt;500px&lt;/code&gt; and &lt;code&gt;699px&lt;/code&gt;, and the second for screen bigger than &lt;code&gt;700px&lt;/code&gt;. In the case of stacked media queries, since property is only applied for a certain width, they are not herited. In our example, if we also want to apply a serif font the layout bigger than &lt;code&gt;700px&lt;/code&gt;, we will have to repeat this property.&lt;br /&gt;
You’ll need a viewport meta tag to make the media queries work. The viewport meta tag enables you to take control of the viewport of the device. Basically, if no viewport is set, mobile device will try to fit the whole page on the screen, resulting in very small websites.&lt;br /&gt;
The viewport meta tag looks like this:&lt;br /&gt;
&lt;pre&gt;&amp;lt;meta name=&quot;viewport&quot;  content=&quot;initial-scale=1, width=device-width&quot;&amp;gt;
&lt;/pre&gt;
We basically tell the device, that we will be using the device width as the width of our page, and that there will be no zooming on the page when we first launch it. &lt;br /&gt;
&lt;h2&gt;
It’s Not Only About the Mobile!&lt;/h2&gt;
In my examples, I showed some media queries used for mobile optimization, tablets and smaller screens. But I wanted as a conclusion, to emphasize the fact that media queries are not only about mobile optimization. We tend to see more and more mobile device, but also more and bigger screens. &lt;br /&gt;
We know have an xbox that can connect to internet, some of the box our internet providers provide us are equipped with a browser, and even some television are able to connect to internet. Maybe tomorrow you will get a web browser on your fridge, who knows. If we use responsive webdesign to optimize for smaller screens, we can also use them to optimize for bigger ones.&lt;br /&gt;
&lt;strong&gt;Let&#39;s remember:&lt;/strong&gt; responsive webdesign is about adapting layout to the user&#39;s browser size, orientation, whatever that size might be!&lt;br /&gt;
&lt;h4&gt;
Some Useful Resources:&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Media queries for browser which don’t support them: &lt;a href=&quot;https://github.com/scottjehl/Respond&quot;&gt;Github Respond&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Mobile hardboiler template : &lt;a href=&quot;http://html5boilerplate.com/mobile&quot;&gt;HTML5boilerplate Mobile&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Testing responsive design: &lt;a href=&quot;http://www.we-are-gurus.com/tools/responsive-design-tester.php&quot;&gt;Responsive Design Tester&lt;/a&gt; and &lt;a href=&quot;http://responsivepx.com/&quot;&gt;Responsivepx&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
Conclusion&lt;/h2&gt;
As you can see, responsive webdesign is not that hard to use and enables web designers to create nice layouts that will adapt to many devices and screen sizes. Your now it’s your turn: did you ever used responsive design? In what kind of projects? Do you have some advice and special tips? How do you define your break points? Let us know in the comments. &lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.onextrapixel.com/2012/03/02/using-css-background-size-responsively/&quot; title=&quot;Using CSS Background-size Responsively&quot;&gt;Using CSS Background-size Responsively&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.onextrapixel.com/2012/04/18/40-beautiful-watercolor-effects-in-web-design/&quot; title=&quot;40 Beautiful Watercolor Effects in Web Design&quot;&gt;40 Beautiful Watercolor Effects in Web Design&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.onextrapixel.com/2012/04/02/neuro-web-design-tips-and-techniques/&quot; title=&quot;Neuro Web Design: Tips and Techniques&quot;&gt;Neuro Web Design: Tips and Techniques&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.onextrapixel.com/2012/03/30/is-the-development-community-alive/&quot; title=&quot;Is the Development Community Alive?&quot;&gt;Is the Development Community Alive?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;img height=&quot;1&quot; src=&quot;http://feeds.feedburner.com/~r/onextrapixel/~4/T7sjh5yAcvY&quot; width=&quot;1&quot; /&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/3909687401820442830'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/3909687401820442830'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/04/responsive-web-design-layouts-and-media.html' title='Responsive Web Design: Layouts and Media Queries'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-1219822982618889357</id><published>2012-04-01T09:28:00.001+08:00</published><updated>2012-04-01T09:30:30.775+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery Plugin"/><category scheme="http://www.blogger.com/atom/ns#" term="Lightbox"/><title type='text'>15 Stunning jQuery Lightbox Plug-ins for Your Upcoming Designs</title><content type='html'>If you see a website built on &lt;strong&gt;jQuery&lt;/strong&gt; using images, they must have played with a &lt;strong&gt;lightbox&lt;/strong&gt; in that context. That’s the power of the lightbox, it can transform any simple image library into an &lt;strong&gt;attractive and effective gallery&lt;/strong&gt;. It’s an important and popular contribution from the jQuery side to the design community.&lt;br /&gt;
Thanks to the awesome jQuery community who make these stunning lightbox plug-ins, giving huge scope for designers to showcase images on websites. There is a huge collection of plug-ins each giving a different look and style to images.&lt;br /&gt;
We collected 15 stunning jQuery lightbox plug-ins for your reference. Hope you’ll find it worth having a look.&lt;br /&gt;
&lt;img alt=&quot;jQuery Lightbox Plug-ins&quot; height=&quot;360&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/03/lightbox-cover.jpg&quot; width=&quot;580&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
Stunning jQuery Lightbox Plug-ins&lt;/h2&gt;
&lt;a href=&quot;http://www.nickstakenburg.com/projects/lightview/&quot; title=&quot;Lightview jQuery Plug-in&quot;&gt;Lightview jQuery Plug-in&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Lightview was built to change the way you overlay content on a website.&lt;br /&gt;
&lt;a href=&quot;http://www.nickstakenburg.com/projects/lightview/&quot;&gt;&lt;img alt=&quot;Lightview jQuery Plug-in&quot; height=&quot;283&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/03/lightbox-1.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;a href=&quot;http://gettopup.com/&quot; title=&quot;TopUp&quot;&gt;TopUp&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
TopUp is an easy to use JavaScript library for unobtrusively displaying images and Web pages in a Web 2.0 approach of pop-up. The library is jQuery and jQuery UI driven in order to maintain cross-browser compatibility and compactness.&lt;br /&gt;
&lt;a href=&quot;http://gettopup.com/&quot;&gt;&lt;img alt=&quot;TopUp&quot; height=&quot;292&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/03/lightbox-2.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;a href=&quot;http://highslide.com/&quot; title=&quot;Highslide Lightbox Plug-in&quot;&gt;Highslide Lightbox Plug-in&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Highslide JS is an image, media and gallery viewer written in JavaScript.&lt;br /&gt;
&lt;a href=&quot;http://highslide.com/&quot;&gt;&lt;img alt=&quot;Highslide Lightbox Plug-in&quot; height=&quot;293&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/03/lightbox-3.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://jacklmoore.com/colorbox/&quot; title=&quot;Color Box&quot;&gt;Color Box&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
A lightweight customizable lightbox plug-in for jQuery 1.3+&lt;br /&gt;
&lt;a href=&quot;http://jacklmoore.com/colorbox/&quot;&gt;&lt;img alt=&quot;Color Box&quot; height=&quot;275&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/03/lightbox-4.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://lokeshdhakar.com/projects/lightbox2/&quot; title=&quot;Lightbox 2&quot;&gt;Lightbox 2&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Lightbox 2 is a simple, unobtrusive script used to overlay images on the current page. It&#39;s a snap to set up and works on all modern browsers.&lt;br /&gt;
&lt;a href=&quot;http://lokeshdhakar.com/projects/lightbox2/&quot;&gt;&lt;img alt=&quot;Lightbox 2&quot; height=&quot;275&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/03/lightbox-5.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/&quot; title=&quot;prettyPhoto&quot;&gt;prettyPhoto&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
prettyPhoto is a jQuery lightbox clone. Not only does it support images, it also supports videos, flash, YouTube, frames and Ajax. It’s a full blown media lightbox.&lt;br /&gt;
&lt;a href=&quot;http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/&quot;&gt;&lt;img alt=&quot;prettyPhoto&quot; height=&quot;275&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/03/lightbox-6.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.digitalia.be/software/slimbox2#download&quot; title=&quot;Slimbox 2&quot;&gt;Slimbox 2&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Slimbox 2 is a 4 KB visual clone of the popular Light box 2 script by Lokesh Dhaka, written using the jQuery JavaScript library.&lt;br /&gt;
&lt;a href=&quot;http://www.digitalia.be/software/slimbox2#download&quot;&gt;&lt;img alt=&quot;Slimbox 2&quot; height=&quot;285&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/03/lightbox-7.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.shadowbox-js.com/index.html&quot; title=&quot;Shadowbox&quot;&gt;Shadowbox&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Shadowbox is a web-based media viewer application that supports all of the web&#39;s most popular media publishing formats. Shadowbox is written entirely in JavaScript and CSS and is highly customizable.&lt;br /&gt;
&lt;a href=&quot;http://www.shadowbox-js.com/index.html&quot;&gt;&lt;img alt=&quot;Shadowbox&quot; height=&quot;285&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/03/lightbox-8.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;a href=&quot;http://www.pirolab.it/pirobox/&quot; title=&quot;Pirobox Extended V.1.0&quot;&gt;Pirobox Extended V.1.0.&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
One of the most important things with this plug-in is the ability to open any kind of file, from inline content to .swf files, from simple images to .pdf files. &lt;br /&gt;
Other things are: automatic image resizing and drag and drop.&lt;br /&gt;
&lt;a href=&quot;http://www.pirolab.it/pirobox/&quot;&gt;&lt;img alt=&quot;Pirobox Extended V.1.0&quot; height=&quot;269&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/03/lightbox-9.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://orangoo.com/labs/GreyBox/&quot; title=&quot;GreyBox&quot;&gt;GreyBox&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
GreyBox can be used to display websites, images and other content in a beautiful way.&lt;br /&gt;
&lt;a href=&quot;http://orangoo.com/labs/GreyBox/&quot;&gt;&lt;img alt=&quot;GreyBox&quot; height=&quot;277&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/03/lightbox-10.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://pierrebertet.net/projects/jquery_superbox/&quot; title=&quot;jQuery Super Box&quot;&gt;jQuery Super Box&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
jQuery Super box! Is a script which allows you to display windows with the lightbox effect. &lt;br /&gt;
This script is a plug-in for jQuery (1.3.x). &lt;br /&gt;
&lt;a href=&quot;http://pierrebertet.net/projects/jquery_superbox/&quot;&gt;&lt;img alt=&quot;jQuery Super Box&quot; height=&quot;305&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/03/lightbox-11.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://fancybox.net/&quot; title=&quot;Fancy Box&quot;&gt;Fancy Box&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Fancy Box is a tool for displaying images, HTML content and multimedia in a Mac-style &quot;light box&quot; that floats overtop of web page.&lt;br /&gt;
&lt;a href=&quot;http://fancybox.net/&quot;&gt;&lt;img alt=&quot;Fancy Box&quot; height=&quot;285&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/03/lightbox-12.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.pirolab.it/pirobox/feb_2011.html&quot; title=&quot;Pirobox Extended V.1.1&quot;&gt;Pirobox Extended V.1.1.&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Pirobox Extended V.1.1 advanced version, Zoom In option with dragable image viewer for large dimension images.&lt;br /&gt;
&lt;a href=&quot;http://www.pirolab.it/pirobox/feb_2011.html&quot;&gt;&lt;img alt=&quot;Pirobox Extended V.1.1&quot; height=&quot;284&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/03/lightbox-13.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://leandrovieira.com/projects/jquery/lightbox/&quot; title=&quot;jQuery Lightbox Plug-in&quot;&gt;jQuery Lightbox Plug-in&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
JQuery lightbox plug-in is simple, elegant, and unobtrusive, no need for extra markup, and is used to overlay images on the current page through the power and flexibility of jQuery´s selector.&lt;br /&gt;
&lt;a href=&quot;http://leandrovieira.com/projects/jquery/lightbox/&quot;&gt;&lt;img alt=&quot;jQuery Lightbox Plug-in&quot; height=&quot;283&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/03/lightbox-14.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;a href=&quot;http://catcubed.com/2008/12/23/ceebox-a-thickboxvideobox-mashup/&quot; title=&quot;Ceebox&quot;&gt;Ceebox&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
An overlay pop-up script for easily embedding flash video, displaying images, or showing HTML (either external sites via iframe or content on your own site via AJAX).&lt;br /&gt;
&lt;a href=&quot;http://catcubed.com/2008/12/23/ceebox-a-thickboxvideobox-mashup/&quot;&gt;&lt;img alt=&quot;Ceebox&quot; height=&quot;387&quot; src=&quot;http://net.onextrapixel.com/wp-content/uploads/2012/03/lightbox-15.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;h2&gt;
Conclusion&lt;/h2&gt;
Do you use any of these lightboxes in your website design work? Do you have a favorite lightbox plug-in? If you do and we haven&#39;t listed it here, please share the link with us in the comments below. Your comments and opinions are always very welcome.&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.onextrapixel.com/2012/03/15/15-simple-effective-jquery-plugins-that-enhance-your-forms/&quot; title=&quot;15 Simple &amp;amp; Effective jQuery Plugins that Enhance Your Forms&quot;&gt;15 Simple &amp;amp; Effective jQuery Plugins that Enhance Your Forms&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.onextrapixel.com/2011/10/17/animating-colors-using-css3-transitions-with-jquery-fallback/&quot; title=&quot;Animating Colors: Using CSS3 Transitions with jQuery Fallback&quot;&gt;Animating Colors: Using CSS3 Transitions with jQuery Fallback&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.onextrapixel.com/2011/09/09/gain-a-better-understanding-of-jquery/&quot; title=&quot;Gain A Better Understanding of jQuery&quot;&gt;Gain A Better Understanding of jQuery&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.onextrapixel.com/2011/08/22/adding-weather-to-your-site-with-jquery-and-yql/&quot; title=&quot;Adding Weather to Your Site with jQuery and YQL&quot;&gt;Adding Weather to Your Site with jQuery and YQL&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
Written by: Carol Francis for &lt;a href=&quot;http://www.onextrapixel.com/&quot;&gt;Onextrapixel - Web Design &amp;amp; Development Online Magazine&lt;/a&gt; | &lt;a href=&quot;http://www.onextrapixel.com/2012/03/29/15-stunning-jquery-lightbox-plug-ins-for-your-upcoming-designs/#comments&quot;&gt;One comment&lt;/a&gt;&lt;br /&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;img height=&quot;1&quot; src=&quot;http://feeds.feedburner.com/~r/onextrapixel/~4/nsDdclpmjlU&quot; width=&quot;1&quot; /&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/1219822982618889357'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/1219822982618889357'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/04/15-stunning-jquery-lightbox-plug-ins.html' title='15 Stunning jQuery Lightbox Plug-ins for Your Upcoming Designs'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-4784499100080740868</id><published>2012-02-29T09:36:00.001+08:00</published><updated>2012-02-29T09:37:20.102+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Tutorial"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress Multisite"/><title type='text'>WordPress Multisite Beyond Basics: Essentials and Domain Mapping</title><content type='html'>&quot;Today we will be discussing a few very important aspects of WordPress Multisite. If you are new to WordPress Multisite please go through the &lt;a href=&quot;http://wp.tutsplus.com/tutorials/using-wordpress-multisite-a-network-of-websites-at-your-fingertips/&quot;&gt;WordPress installation tutorial&lt;/a&gt; first to get an overall idea of the Multisite feature in WordPress. In this tutorial I shall be discussing a few key things essential for WordPress Multisite installation, along with some common troubleshooting tips. Finally I shall discuss WordPress Multisite Domain Mapping in detail.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Key Things to Know About WordPress Multisite Installation&lt;/h2&gt;&lt;h3&gt;Installing WordPress Multisite Using Plugin&lt;/h3&gt;You can install WordPress Multisite using two methods. One is using the plugin &lt;a href=&quot;http://wordpress.org/extend/plugins/wordpress-multi-site-enabler-plugin-v10/&quot;&gt;Enable Multi-Site&lt;/a&gt; and another is manual installation. It’s recommended to use manual installation since the installation changes will then be transparent and can be easily altered later.&lt;br /&gt;
&lt;h3&gt;Changing From Sub-Directory to Sub-Domain&lt;/h3&gt;In case you want to change your installation type from sub-directory to sub-domain, please use the following steps:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;You need to delete all the sites which were created under your main site&lt;/li&gt;
&lt;li&gt;Enable the sub-domain option from the &lt;code&gt;wp-config.php&lt;/code&gt; file by modifying the following code: &lt;pre name=&quot;code&quot;&gt;define( &#39;SUBDOMAIN_INSTALL&#39;, true );&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;Finally update your Permalinks&lt;/li&gt;
&lt;/ul&gt;&lt;blockquote&gt;Since you will need to delete all your sites it’s recommended to make the decision carefully while choosing between sub-domain and sub-directory during installation. &lt;/blockquote&gt;&lt;h3&gt;Keeping a Default Theme for All Your New Sites&lt;/h3&gt;If you want to keep a default theme for all your newly created sites then please go to your &lt;code&gt;wp-config.php&lt;/code&gt; file and add the following line of code below the specified line:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;// Below this line
 define(&#39;WPLANG&#39;, &#39;&#39;);
 // Add this line
 define(&#39;WP_DEFAULT_THEME&#39;, &#39;classic&#39;);
&lt;/pre&gt;Replace ‘classic’ with the folder name of the theme you like.&lt;br /&gt;
&lt;h3&gt;Add Yourself to All Your Sites&lt;/h3&gt;The different sites created will only be visible under &lt;strong&gt;My Sites&lt;/strong&gt; if you have been added as a user for that site. If you are a &lt;strong&gt;Network Admin&lt;/strong&gt; then please add yourself as a regular user for all your created sites so that you can manage them straight from your dashboard.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/196_WordPress_Multisite_Beyond_Basics_Essentials_and_Domain_Mapping/image14.jpg&quot; /&gt;&lt;/div&gt;&lt;h3&gt;Let Users Define Custom CSS&lt;/h3&gt;Generally the users are not able to edit the themes for their sites but once you (as a Network Administrator) install and activate the &lt;a href=&quot;http://wordpress.org/extend/plugins/custom-user-css/&quot;&gt;Custom User CSS&lt;/a&gt; plugin then the site owners can design their themes by defining custom CSS.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Common WordPress Multisite Troubleshooting&lt;/h2&gt;&lt;h3&gt;Created Sub-Domains Not Working&lt;/h3&gt;Your hosting platform should support the &lt;strong&gt;Wildcard DNS&lt;/strong&gt; feature. Please check with your hosting provider prior to installing WordPress Multisite.&lt;br /&gt;
To create a Wildcard DNS entry please login to your &lt;strong&gt;Control Panel&lt;/strong&gt; provided by your host and look for the &lt;strong&gt;Domain&lt;/strong&gt; section. Under &lt;strong&gt;Domain&lt;/strong&gt; click on the &lt;strong&gt;Subdomain&lt;/strong&gt; option. This is the place to enable sub-domains for your website.&lt;br /&gt;
Once you click on the &lt;strong&gt;Subdomain&lt;/strong&gt; option in the control panel, under &lt;strong&gt;Create a Subdomain&lt;/strong&gt; enter an asterisk ‘*’ in the &lt;strong&gt;Subdomain&lt;/strong&gt; field and then click on &lt;strong&gt;Create&lt;/strong&gt;. The &lt;strong&gt;Document Root&lt;/strong&gt; should point to the root directory of your WordPress installation.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/196_WordPress_Multisite_Beyond_Basics_Essentials_and_Domain_Mapping/image13.jpg&quot; /&gt;&lt;/div&gt;&lt;h3&gt;Created Sub-Directories Not Working&lt;/h3&gt;The &lt;strong&gt;Apache mod_rewrite module&lt;/strong&gt; should be supported by your hosting provider. This is required in the creation of multiple sites. If you are using &lt;strong&gt;WAMP&lt;/strong&gt; you can enable it by going to &lt;strong&gt;Apache &amp;gt; Apache modules &amp;gt; mod_rewrite&lt;/strong&gt;.&lt;br /&gt;
&lt;h3&gt;Network Cannot Be Enabled Error&lt;/h3&gt;This error occurs if the &lt;strong&gt;Site URL&lt;/strong&gt; is not the same as the &lt;strong&gt;WordPress URL&lt;/strong&gt;, so under WordPress’   Admin Dashboard &lt;strong&gt;Settings &amp;gt; General&lt;/strong&gt; please ensure that they are the same prior to installing Multisite.&lt;br /&gt;
&lt;h3&gt;Wildcard Sub-Domain Incorrect Error&lt;/h3&gt;In order to solve this problem please go to your hosting provider’s control panel where you have defined the wildcard DNS and then update the &lt;strong&gt;Document Root&lt;/strong&gt; of your sub-domain to point to the correct location.&lt;br /&gt;
&lt;h3&gt;My Uploaded Media Not Working&lt;/h3&gt;All the uploaded media including images are located under your created &lt;strong&gt;blogs.dir&lt;/strong&gt; folder. Please check your &lt;strong&gt;.htaccess&lt;/strong&gt; file if the following line of code is in the same format or not. Also ensure that &lt;strong&gt;mod_rewrite&lt;/strong&gt; is enabled for your server.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;# uploaded files
 RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
&lt;/pre&gt;If you find any other issue with WordPress Multisite please feel free to refer to the &lt;a href=&quot;http://wordpress.org/support/forum/multisite&quot;&gt;Official Multisite Support Forum&lt;/a&gt;, it contains hundreds of solutions for your common Multisite problems.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Domain Mapping&lt;/h2&gt;One of the coolest parts of WordPress Multisite installation is the mapping of domains to turn your network sites into unique domains that carry their own identities. Using Domain Mapping lets you define a custom domain for your blog/site instead of the default address you get when you sign up or create a new site. For example, using a sub-domain install, if you create a new site you will have the URL &lt;strong&gt;newsite.parentsite.com&lt;/strong&gt;. But using Domain Mapping you can turn it into &lt;strong&gt;www.newsite.com&lt;/strong&gt;. Thus Domain Mapping can be used to point external domains to your network sites.&lt;br /&gt;
&lt;blockquote&gt;Domain Mapping hides the fact that the site is a part of a Multisite network. &lt;/blockquote&gt;Let’s discuss Domain Mapping in detail.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 1 A Little Bit of Your Host cPanel&lt;/h2&gt;Before going for the Domain Mapping let’s do a bit of backend work from our cPanel. Please login to your host’s cPanel. Generally the URL of your cPanel will look something like http://www.hostname.com/cpanel or http://www.hostname.com:2082 . Once you log in, you will find two options under the &lt;strong&gt;Domains&lt;/strong&gt; section named &lt;strong&gt;Addon Domains&lt;/strong&gt; and &lt;strong&gt;Parked Domains&lt;/strong&gt;.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/196_WordPress_Multisite_Beyond_Basics_Essentials_and_Domain_Mapping/image2.jpg&quot; /&gt;&lt;/div&gt;Here we will be using the &lt;strong&gt;Parked Domains&lt;/strong&gt; option since we have our WordPress installation in the root directory. The &lt;strong&gt;Addon Domain&lt;/strong&gt; option can be used if you are utilizing WordPress outside the root directory. Under &lt;strong&gt;Parked Domains&lt;/strong&gt; enter the name of the new domain you want to park on your primary domain and then click on &lt;strong&gt;Add Domain&lt;/strong&gt;. The parked domain should automatically point to the root directory of your installation which is generally &lt;strong&gt;public_html&lt;/strong&gt;.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/196_WordPress_Multisite_Beyond_Basics_Essentials_and_Domain_Mapping/image3.jpg&quot; /&gt;&lt;/div&gt;&lt;blockquote&gt;The new domain name should be registered prior to parking. &lt;/blockquote&gt;If you are using the &lt;strong&gt;Addon Domains&lt;/strong&gt; option then you are probably not using your Primary Domain for mapping purposes. After clicking the &lt;strong&gt;Addon Domains&lt;/strong&gt; option fill in all the required details in the window and click on &lt;strong&gt;Add Domain&lt;/strong&gt;.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/196_WordPress_Multisite_Beyond_Basics_Essentials_and_Domain_Mapping/image5.jpg&quot; /&gt;&lt;/div&gt;&lt;hr /&gt;&lt;h2&gt;Step 2 The DNS Settings&lt;/h2&gt;After your new domain has been parked, you need to be sure that the &lt;strong&gt;DNS Settings&lt;/strong&gt; are properly configured for your domain. For this you should have your &lt;strong&gt;DNS&lt;/strong&gt; / &lt;strong&gt;Name Server&lt;/strong&gt; information. This can usually be found in the &lt;strong&gt;Account Information&lt;/strong&gt; section of your host’s cPanel. Once you have that info you need to login to your registrar’s website where the domain was registered. Here we have used &lt;strong&gt;Go Daddy&lt;/strong&gt; for registration. Once you login, under &lt;strong&gt;My Account &amp;gt; Domain&lt;/strong&gt; select the required domain name to open the &lt;strong&gt;domain editor&lt;/strong&gt; and then click on &lt;strong&gt;Set Nameservers&lt;/strong&gt; option under the &lt;strong&gt;Nameserver&lt;/strong&gt; section.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/196_WordPress_Multisite_Beyond_Basics_Essentials_and_Domain_Mapping/image4.jpg&quot; /&gt;&lt;/div&gt;Here you can use either of the four options to set up your Name Server.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;strong&gt;I want to park my domains:&lt;/strong&gt; This option will park your domain on GoDaddy’s parked servers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;I want to forward my domains:&lt;/strong&gt; This option will forward your domain to another URL.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;I have a hosting account with these domains:&lt;/strong&gt; This option is used if the domain is hosted with GoDaddy.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;I have specific nameservers for my domains:&lt;/strong&gt; This option is used if your domain is hosted by another company. Here you need to enter the Name Servers provided by your hosting company. We will be using this option for this tutorial.&lt;/li&gt;
&lt;/ul&gt;Once done click on the &lt;strong&gt;OK&lt;/strong&gt; button.&lt;br /&gt;
&lt;blockquote&gt;If the nameserver info is changed it may take some time to propagate. &lt;/blockquote&gt;Although I have used GoDaddy and Host Gator in this tutorial, these options are very similar to any other vendor’s interface.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 3 WordPress MU Domain Mapping Plugin Installation&lt;/h2&gt;Now you need to manually install the &lt;a href=&quot;http://wordpress.org/extend/plugins/wordpress-mu-domain-mapping/&quot;&gt;WordPress MU Domain Mapping&lt;/a&gt; plugin in order to activate your domain mapping. Please download the plugin and extract the files. Copy all files (except the &lt;strong&gt;sunrise.php&lt;/strong&gt; file) to your &lt;strong&gt;wp-content &amp;gt; plugins&lt;/strong&gt; folder. Then copy the &lt;strong&gt;sunrise.php&lt;/strong&gt; file to your &lt;strong&gt;wp-content&lt;/strong&gt; folder.&lt;br /&gt;
Open your &lt;strong&gt;wp-config.php&lt;/strong&gt; file and enter the following line of code under the code where you have enabled your multisite feature.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;define(&#39;WP_DEBUG&#39;, false);
define(&#39;WP_ALLOW_MULTISITE&#39;, true);

define(&#39;SUNRISE&#39;, &#39;on&#39;); // Add this line here:

define( &#39;MULTISITE&#39;, true );
define( &#39;SUBDOMAIN_INSTALL&#39;, false );
$base = &#39;/&#39;;
define( &#39;DOMAIN_CURRENT_SITE&#39;, &#39;localhost&#39; );
define( &#39;PATH_CURRENT_SITE&#39;, &#39;/&#39; );
define( &#39;SITE_ID_CURRENT_SITE&#39;, 1 );
define( &#39;BLOG_ID_CURRENT_SITE&#39;, 1 );

/* That&#39;s all, stop editing! Happy blogging. */
&lt;/pre&gt;&lt;strong&gt;Save&lt;/strong&gt; the changes.&lt;br /&gt;
After that you will be able to see the &lt;strong&gt;Domain Mapping&lt;/strong&gt; option under the Settings menu of your Network Admin dashboard.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/196_WordPress_Multisite_Beyond_Basics_Essentials_and_Domain_Mapping/image6.jpg&quot; /&gt;&lt;/div&gt;&lt;hr /&gt;&lt;h2&gt;Step 4 Mapping The External Domain to One Of Your Child Sites&lt;/h2&gt;Now you are ready to map the external domain to one of your child sites. For this please click on the &lt;strong&gt;Settings &amp;gt; Domain Mapping&lt;/strong&gt; option of your Network Admin Dashboard.&lt;br /&gt;
Under Server IP Address put the IP address of your web server. You may contact your host for this address or visit &lt;a href=&quot;http://www.networksolutions.com/whois/index.jsp&quot;&gt;this site&lt;/a&gt; to find your site’s IP address.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/196_WordPress_Multisite_Beyond_Basics_Essentials_and_Domain_Mapping/image8.jpg&quot; width=&quot;550&quot; /&gt;&lt;/div&gt;Finally click on &lt;strong&gt;Save&lt;/strong&gt;.&lt;br /&gt;
Next go to the Dashboard of one of your child sites for which you want to map the domain.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/196_WordPress_Multisite_Beyond_Basics_Essentials_and_Domain_Mapping/image7.jpg&quot; /&gt;&lt;/div&gt;Then under &lt;strong&gt;Tools &amp;gt; Domain Mapping&lt;/strong&gt; add the external domain which we have registered. Check the &lt;strong&gt;Primary Domain For this Blog&lt;/strong&gt; checkbox to make it a primary domain for this site. Finally click on &lt;strong&gt;Add&lt;/strong&gt;.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/196_WordPress_Multisite_Beyond_Basics_Essentials_and_Domain_Mapping/image9.jpg&quot; width=&quot;550&quot; /&gt;&lt;/div&gt;If your domain name includes a hostname like &quot;www&quot;, &quot;blog&quot; or some other prefix before the actual domain name you will need to add a CNAME record for that hostname in your DNS pointing at this blog URL. For this please log in to your host cPanel and click on &lt;strong&gt;Advanced DNS Zone Editor&lt;/strong&gt; under the &lt;strong&gt;Domains&lt;/strong&gt; section and set up your CNAME record.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/196_WordPress_Multisite_Beyond_Basics_Essentials_and_Domain_Mapping/image10.jpg&quot; /&gt;&lt;/div&gt;That’s it you have successfully mapped an external domain to your site. To verify please check the URL by visiting your child site.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 5 Final Steps&lt;/h2&gt;If you don’t want to utilize the original sub-domain URL of your child site any more, you may remove all the traces of the URL from the Network Admin Dashboard. For this go to &lt;strong&gt;Sites &amp;gt; All Sites&lt;/strong&gt; and Edit the Site which you have mapped. In each of the tabs search for the old URL and replace it with the new URL.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/196_WordPress_Multisite_Beyond_Basics_Essentials_and_Domain_Mapping/image11.jpg&quot; width=&quot;550&quot; /&gt;&lt;/div&gt;In order to redirect users who type the old URL, please log into your cPanel and click on &lt;strong&gt;Redirects&lt;/strong&gt; under the &lt;strong&gt;Domain&lt;/strong&gt; section. Here you need to select the Type, the URL to be redirected and the URL to which it will be redirected. Finally click on &lt;strong&gt;Add&lt;/strong&gt;.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/196_WordPress_Multisite_Beyond_Basics_Essentials_and_Domain_Mapping/image12.jpg&quot; /&gt;&lt;/div&gt;That’s it for now, in my next tutorial I shall be explaining the WordPress Multisite Database in detail using phpMyAdmin and some really cool functions to be used in WordPress Multisite. Thanks a lot for reading.&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/4784499100080740868'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/4784499100080740868'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/02/wordpress-multisite-beyond-basics.html' title='WordPress Multisite Beyond Basics: Essentials and Domain Mapping'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-1404007811420033518</id><published>2012-02-29T09:22:00.001+08:00</published><updated>2012-02-29T09:23:17.351+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CSS"/><category scheme="http://www.blogger.com/atom/ns#" term="Include"/><category scheme="http://www.blogger.com/atom/ns#" term="Javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="Tips"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress Plugins"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress Themes"/><title type='text'>How to Include JavaScript and CSS in Your WordPress Themes and Plugins</title><content type='html'>&quot;&lt;span style=&quot;font-size: 100%;&quot;&gt;Knowing the proper way to include JavaScript and CSS files in your WordPress themes and plugins is very important for designers and developers. If you don’t adhere to best practices, you run the risk of conflicting with other themes and plugins, and potentially creating problems that could have been easily avoided. This article is intended as a reference for playing nicely with others.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Best Practices Make Everyone Happy&lt;/h2&gt;If you’ve ever developed a theme or plugin for WordPress, or worked with one that someone else has created, you’ve probably come across several different methods for including JavaScript and CSS. While there are several methods that may appear to work in a specific set of circumstances, there is one primary method recommended in the &lt;a href=&quot;http://codex.wordpress.org/&quot;&gt;WordPress Codex&lt;/a&gt;. This preferred way will ensure your theme or plugin works in all cases, assuming others also code the correct way.&lt;br /&gt;
There’s also some misunderstanding about what exactly the Codex says about this, which I will help clarify.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;What’s in the Box?&lt;/h2&gt;When you download WordPress, a selection of common JavaScript libraries are already included that you can use for your JavaScript development. A list of included libraries can be found in the &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Default_scripts_included_with_WordPress&quot;&gt;WordPress Codex &lt;code&gt;wp_enqueue_script&lt;/code&gt;&lt;/a&gt; article.&lt;br /&gt;
All those libraries are included, but by default WordPress only loads the ones it needs to, and only when it needs them in the admin. If you write JavaScript that utilises one of these libraries, you need to tell WordPress that your script needs the library loaded first.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Telling WordPress About Your Script and What It Needs&lt;/h2&gt;Some of the things to think about when you’re coding JavaScript for WordPress are:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Is there an included library I can use?&lt;/li&gt;
&lt;li&gt;Can I use the version that’s included?&lt;/li&gt;
&lt;li&gt;Do I need to load my script in the front-end and in the admin?&lt;/li&gt;
&lt;li&gt;Which front-end and admin pages do I need to load my script on?&lt;/li&gt;
&lt;/ul&gt;Answering these questions helps you know what you need to do to register and load your script. This is done using a WordPress function called &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/wp_register_script&quot;&gt;&lt;code&gt;wp_register_script&lt;/code&gt;&lt;/a&gt;, and here is its usage according to the WordPress Codex:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;wp_register_script( $handle, $src, $deps, $ver, $in_footer );
&lt;/pre&gt;So what are these variables and do we need them every time? (This is covered on the Codex page, so I’ll be brief and use plain English)&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;$handle&lt;/code&gt; – what you’ll use to refer to this particular script wherever you might need to enqueue it, and you have to include this variable at the very least&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$src&lt;/code&gt; – the path to the source file within your plugin or theme&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$deps&lt;/code&gt; – an array containing the &lt;code&gt;$handle&lt;/code&gt; for any other scripts your script needs to run (i.e. a dependency)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$ver&lt;/code&gt; – the version number for your script, which can be used for cache-busting. By default, WordPress will use its own version number as the version number for your script&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$in_footer&lt;/code&gt; – do you want your script to load in the footer? Set this to &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;. It is &lt;code&gt;false&lt;/code&gt; by default, so it loads in the header where &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/wp_head&quot;&gt;&lt;code&gt;wp_head()&lt;/code&gt;&lt;/a&gt; is, and if you specify &lt;code&gt;true&lt;/code&gt; it will load where &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/wp_footer&quot;&gt;&lt;code&gt;wp_footer()&lt;/code&gt;&lt;/a&gt; appears in the theme&lt;/li&gt;
&lt;/ul&gt;&lt;h3&gt;What Is “Cache-Busting”?&lt;/h3&gt;Browsers remember what scripts and stylesheets they’ve downloaded for a particular site based on the URL of the script and stylesheet. If you change the URL, even just by adding a querystring, the browser assumes it’s a new file and downloads it.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Ok, So Let’s Try Some Examples&lt;/h2&gt;Here is the most basic example for loading a custom script:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;function wptuts_scripts_basic()
{
 // Register the script like this for a plugin:
 wp_register_script( &#39;custom-script&#39;, plugins_url( &#39;/js/custom-script.js&#39;, __FILE__ ) );
 // or
 // Register the script like this for a theme:
 wp_register_script( &#39;custom-script&#39;, get_template_directory_uri() . &#39;/js/custom-script.js&#39; );

 // For either a plugin or a theme, you can then enqueue the script:
 wp_enqueue_script( &#39;custom-script&#39; );
}
add_action( &#39;wp_enqueue_scripts&#39;, &#39;wptuts_scripts_basic&#39; );
&lt;/pre&gt;First, we register the script, so WordPress knows what we’re talking about. The way to find the path for our JavaScript file is different whether we’re coding a plugin or a theme, so I’ve included examples of both above. Then we queue it up to be added into the HTML for the page when it’s generated, by default in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; where the &lt;code&gt;wp_head()&lt;/code&gt; is in the theme.&lt;br /&gt;
The output we get from that basic example is:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;script type=&quot;text/javascript&quot; src=&quot;http://yourdomain.com/wp-content/plugins/yourplugin/js/custom-script.js?ver=3.3.1&quot;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/pre&gt;Now if your script relies on one of the libraries included with WordPress, like jQuery, you can make a very simple change to the code:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;function wptuts_scripts_with_jquery()
{
 // Register the script like this for a plugin:
 wp_register_script( &#39;custom-script&#39;, plugins_url( &#39;/js/custom-script.js&#39;, __FILE__ ), array( &#39;jquery&#39; ) );
 // or
 // Register the script like this for a theme:
 wp_register_script( &#39;custom-script&#39;, get_template_directory_uri() . &#39;/js/custom-script.js&#39;, array( &#39;jquery&#39; ) );

 // For either a plugin or a theme, you can then enqueue the script:
 wp_enqueue_script( &#39;custom-script&#39; );
}
add_action( &#39;wp_enqueue_scripts&#39;, &#39;wptuts_scripts_with_jquery&#39; );
&lt;/pre&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;By default, jQuery is loaded with &lt;a href=&quot;http://docs.jquery.com/Using_jQuery_with_Other_Libraries&quot;&gt;noConflict&lt;/a&gt; to prevent clashes with other libraries (such as Prototype). &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_wrappers&quot;&gt;See the noConflict section of the Codex&lt;/a&gt; if you don’t know how to deal with that.&lt;/em&gt;&lt;br /&gt;
See what I did there? You just add an array with the ‘jquery’ handle as a dependency. It uses an array here, because your script could have multiple dependencies. If your script uses jQuery and jQuery UI, you’d add jQuery UI to your dependency array, like &lt;code&gt;array( &#39;jquery&#39;, &#39;jquery-ui-core&#39; )&lt;/code&gt;&lt;br /&gt;
So now the output has changed, and we can see that jQuery has also been added into the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; of the page:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;script type=&#39;text/javascript&#39; src=&#39;http://yourdomain.com/wp-includes/js/jquery/jquery.js?ver=1.7.1&#39;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type=&#39;text/javascript&#39; src=&#39;http://yourdomain.com/wp-content/plugins/yourplugin/js/custom-script.js?ver=3.3.1&#39;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/pre&gt;Let’s try an example with all the bells and whistles:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;function wptuts_scripts_with_the_lot()
{
 // Register the script like this for a plugin:
 wp_register_script( &#39;custom-script&#39;, plugins_url( &#39;/js/custom-script.js&#39;, __FILE__ ), array( &#39;jquery&#39;, &#39;jquery-ui-core&#39; ), &#39;20120208&#39;, true );
 // or
 // Register the script like this for a theme:
 wp_register_script( &#39;custom-script&#39;, get_template_directory_uri() . &#39;/js/custom-script.js&#39;, array( &#39;jquery&#39;, &#39;jquery-ui-core&#39; ), &#39;20120208&#39;, true );

 // For either a plugin or a theme, you can then enqueue the script:
 wp_enqueue_script( &#39;custom-script&#39; );
}
add_action( &#39;wp_enqueue_scripts&#39;, &#39;wptuts_scripts_with_the_lot&#39; );
&lt;/pre&gt;Ok, so I’ve now added a version and specified that this script needs to be loaded in the footer. For the version number, I’ve chosen to use today’s date because it’s easy to keep track of, but you can use any version numbering you like. The output for this one is slightly different too, jQuery is output in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; and our script along with jQuery UI is output just before &lt;code&gt;&amp;lt;/body&amp;gt;&lt;/code&gt;, like this:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;head&amp;gt;
...
&amp;lt;script type=&#39;text/javascript&#39; src=&#39;http://yourdomain.com/wp-includes/js/jquery/jquery.js?ver=1.7.1&#39;&amp;gt;&amp;lt;/script&amp;gt;
...
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
...
&amp;lt;script type=&#39;text/javascript&#39; src=&#39;http://yourdomain.com/wp-includes/js/jquery/ui/jquery.ui.core.min.js?ver=1.8.16&#39;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type=&#39;text/javascript&#39; src=&#39;http://yourdomain.com/wp-content/plugins/yourplugin/js/custom-script.js?ver=20120208&#39;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Getting Your Priorities Straight&lt;/h2&gt;Some people may prefer not to use the proper enqueuing methods because they feel they have less control over the order in which scripts are loaded. For example, in a theme that uses &lt;a href=&quot;http://modernizr.com/&quot;&gt;modernizr&lt;/a&gt;, the theme author might want to make sure modernizr is loaded early on.&lt;br /&gt;
Something I haven’t mentioned earlier is more detail on how the &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/add_action&quot;&gt;&lt;code&gt;add_action&lt;/code&gt;&lt;/a&gt; function works, as this is where we can exercise a little influence over the order of things. Here’s the usage of the function according to the WordPress Codex page:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;add_action( $tag, $function_to_add, $priority, $accepted_args );
&lt;/pre&gt;Note that often, and up until now in this article, only the &lt;code&gt;$tag&lt;/code&gt; and &lt;code&gt;$function_to_add&lt;/code&gt; parameters are used. The &lt;code&gt;$priority&lt;/code&gt; parameter defaults to 10, and the &lt;code&gt;$accepted_args&lt;/code&gt; parameter defaults to 1. If we want our scripts or styles to be enqueued earlier, we simply lower the value for &lt;code&gt;$priority&lt;/code&gt; from the default. For example:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;function wptuts_scripts_important()
{
 // Register the script like this for a plugin:
 wp_register_script( &#39;custom-script&#39;, plugins_url( &#39;/js/custom-script.js&#39;, __FILE__ ) );
 // or
 // Register the script like this for a theme:
 wp_register_script( &#39;custom-script&#39;, get_template_directory_uri() . &#39;/js/custom-script.js&#39; );

 // For either a plugin or a theme, you can then enqueue the script:
 wp_enqueue_script( &#39;custom-script&#39; );
}
add_action( &#39;wp_enqueue_scripts&#39;, &#39;wptuts_scripts_important&#39;, 5 );
&lt;/pre&gt;The output will be the same as we’ve seen previously, but it will occur earlier in the HTML document.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Overriding Default Libraries and Using Content Delivery Networks&lt;/h2&gt;There may be times when you want to use a different version of a library that’s included with WordPress. Perhaps you want to use a cutting-edge version or you don’t want to wait for the next release of WordPress before using the latest stable version of jQuery. Another reason might be that you want to take advantage of Google’s CDN version of a library.&lt;br /&gt;
It’s important to note that this should only be done on plugins or themes used on sites that you will be personally maintaining. Any plugins or themes that you release for public use should use the libraries included with WordPress.&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;“Why?!”&lt;/em&gt;&lt;/strong&gt;, I hear you ask. For the simple reason that you don’t control those sites. You don’t know what other plugins and themes might be used there, and you don’t know how often they will update your plugin or theme. Using the libraries packaged with WordPress is the safest option.&lt;br /&gt;
Having said that, if you are wanting to do this on a site you control, here’s how it’s done:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;function wptuts_scripts_load_cdn()
{
 // Deregister the included library
 wp_deregister_script( &#39;jquery&#39; );

 // Register the library again from Google&#39;s CDN
 wp_register_script( &#39;jquery&#39;, &#39;http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&#39;, array(), null, false );

 // Register the script like this for a plugin:
 wp_register_script( &#39;custom-script&#39;, plugins_url( &#39;/js/custom-script.js&#39;, __FILE__ ), array( &#39;jquery&#39; ) );
 // or
 // Register the script like this for a theme:
 wp_register_script( &#39;custom-script&#39;, get_template_directory_uri() . &#39;/js/custom-script.js&#39;, array( &#39;jquery&#39; ) );

 // For either a plugin or a theme, you can then enqueue the script:
 wp_enqueue_script( &#39;custom-script&#39; );
}
add_action( &#39;wp_enqueue_scripts&#39;, &#39;wptuts_scripts_load_cdn&#39; );
&lt;/pre&gt;So first of all, I deregister the included version of the library, otherwise conflicts between different versions could be introduced. Then register the alternate version, using the same handle, and I’ve chosen to specify null as the version (it’s already in the URL!) and specified not in the footer. The rest of our code is the same, because we were depending on whatever script used the ‘jquery’ handle. The output we get now looks like:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;script type=&#39;text/javascript&#39; src=&#39;http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&#39;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type=&#39;text/javascript&#39; src=&#39;http://yourdomain.com/wp-content/plugins/yourplugin/js/custom-script.js?ver=3.3.1&#39;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/pre&gt;&lt;strong&gt;Note:&lt;/strong&gt; One of the reasons this is a bad idea to do in a plugin or theme for public release, is that all other plugins and themes used on this site will now have to use this version of jQuery. Also, the newly registered version of jQuery doesn’t have noConflict set, so if any other plugin or theme scripts use Prototype for example, &lt;em&gt;this will break things&lt;/em&gt;.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Don’t Be Greedy&lt;/h2&gt;So far we haven’t mentioned anything about how to do all this in the admin, only on the front-end. The primary difference is what action to use. Instead of &lt;code&gt;add_action( &#39;wp_enqueue_scripts&#39;, &#39;wptuts_scripts_basic&#39; );&lt;/code&gt; which we use for the front-end, the action for the admin is &lt;code&gt;add_action( &#39;admin_enqueue_scripts&#39;, &#39;wptuts_scripts_basic&#39; );&lt;/code&gt;&lt;br /&gt;
Something that’s important to do for both the front-end and admin is be selective about which pages you load your scripts on. If your plugin or theme has a script that only does something on one front-end or admin page, such as the theme’s options page, or maybe a page with a specific widget, you only need to load your script on that page. No point clogging things up and loading scripts on pages where they’re not being used!&lt;br /&gt;
There’s a great example in the WordPress Codex on how to &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Load_scripts_only_on_plugin_pages&quot;&gt;load scripts only on plugin pages&lt;/a&gt;. Because plugins and themes can vary a lot in how they’re written, I won’t go into specifics here on how to be choosy about which pages you load scripts on, but it was important to mention so you’re aware of it when you’re coding.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;That’s Scripts, Now Styles&lt;/h2&gt;The process for styles is almost exactly the same as the process for scripts. It is done using a WordPress function called &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/wp_register_style&quot;&gt;&lt;code&gt;wp_register_style&lt;/code&gt;&lt;/a&gt;, and here is its usage according to the WordPress Codex:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;wp_register_style( $handle, $src, $deps, $ver, $media );
&lt;/pre&gt;Note that the only difference there between &lt;code&gt;wp_register_script&lt;/code&gt; and &lt;code&gt;wp_register_style&lt;/code&gt; is that instead of an &lt;code&gt;$in_footer&lt;/code&gt; parameter, we have a &lt;code&gt;$media&lt;/code&gt; parameter. This parameter can be set to any of the following: &lt;code&gt;&#39;all&#39;&lt;/code&gt;, &lt;code&gt;&#39;screen&#39;&lt;/code&gt;, &lt;code&gt;&#39;handheld&#39;&lt;/code&gt;, and &lt;code&gt;&#39;print&#39;&lt;/code&gt;, or any other W3C recognised media type.&lt;br /&gt;
So an example of how you might enqueue a style would be:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;function wptuts_styles_with_the_lot()
{
 // Register the style like this for a plugin:
 wp_register_style( &#39;custom-style&#39;, plugins_url( &#39;/css/custom-style.css&#39;, __FILE__ ), array(), &#39;20120208&#39;, &#39;all&#39; );
 // or
 // Register the style like this for a theme:
 wp_register_style( &#39;custom-style&#39;, get_template_directory_uri() . &#39;/css/custom-style.css&#39;, array(), &#39;20120208&#39;, &#39;all&#39; );

 // For either a plugin or a theme, you can then enqueue the style:
 wp_enqueue_style( &#39;custom-style&#39; );
}
add_action( &#39;wp_enqueue_scripts&#39;, &#39;wptuts_styles_with_the_lot&#39; );
&lt;/pre&gt;This is a fairly comprehensive example, utilising most of the parameters, and the output it produces looks like:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;link rel=&#39;stylesheet&#39; id=&#39;custom-style-css&#39;  href=&#39;http://yourdomain.com/wp-content/plugins/yourplugin/css/custom-style.css?ver=20120208&#39; type=&#39;text/css&#39; media=&#39;all&#39; /&amp;gt;
&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;So, Why Doesn’t Everyone Already Do Things This Way?&lt;/h2&gt;Good question, and the other question I guess you might ask is, “What makes you think this is the ‘right’ way and not just your preference?”. Essentially the answer is that this is the approach recommended by WordPress. It ensures that any combination of plugins and themes should be able to work together happily and without doubling up.&lt;br /&gt;
I’ve seen a few themes and frameworks around the place that use &lt;code&gt;&amp;lt;script&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;link /&amp;gt;&lt;/code&gt; tags in their &lt;code&gt;header.php&lt;/code&gt;, and even &lt;code&gt;footer.php&lt;/code&gt;, files to load the scripts and styles for the theme itself. There’s really no reason to do things this way. As I’ve demonstrated above, it’s perfectly possible to prioritise scripts and styles and nominate whether they load in the header or footer from the comfort and safety of your &lt;code&gt;functions.php&lt;/code&gt;. The benefit being that your theme / framework will work with a wider range of other plugins / child themes.&lt;br /&gt;
One example was loading jQuery using the &lt;code&gt;&amp;lt;script&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt; tags, which might appear to work nicely, but this can actually cause jQuery to be loaded twice! Loading jQuery in this way will not stop WordPress from loading its version of jQuery for other plugins, as WordPress’ version is in noConflict mode by default, and a plugin may specify it as a dependancy. So now you’ll have jQuery working for both noConflict mode and &lt;code&gt;$&lt;/code&gt;, and also probably break any plugin that uses the Prototype library.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;WordPress is a fantastic system, and it has been developed with a lot of thought. If there’s a mechanism made available to do something, it’s often a good idea to use it. When developing your plugins and themes, try to remember to code thoughtfully and for playing nicely with others.&lt;br /&gt;
What do you think about the use of &lt;code&gt;wp_enqueue_script&lt;/code&gt; and its associated functions and actions? Do you know of any examples where it’s being done incorrectly? Do you know of any reason not to follow the advice above?&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/1404007811420033518'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/1404007811420033518'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/02/how-to-include-javascript-and-css-in.html' title='How to Include JavaScript and CSS in Your WordPress Themes and Plugins'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-246957237699321317</id><published>2012-02-29T09:10:00.001+08:00</published><updated>2012-02-29T09:11:23.295+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Contact Methods"/><category scheme="http://www.blogger.com/atom/ns#" term="Tips"/><category scheme="http://www.blogger.com/atom/ns#" term="User Profiles"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><title type='text'>Quick Tip: Add Extra Contact Methods to User Profiles</title><content type='html'>&quot;If you Google “add extra fields to WordPress user profile” you’ll find all sorts of involved coding examples for adding extra inputs to the user profile page so you can capture additional user information. But if all you want to do is expand the default contact methods section then there’s a much simpler way to go.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;The user_contactmethods Filter&lt;/h2&gt;The &lt;a href=&quot;http://codex.wordpress.org/Plugin_API/Filter_Reference/user_contactmethods&quot;&gt;user_contactmethods&lt;/a&gt; filter allows you to set and unset the contact info fields on the user profile page. The great thing about using this method is that WordPress looks after the creation and updating of the fields.&lt;br /&gt;
Let’s add fields for Twitter and Facebook info. Put this in your functions.php file:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;add_filter(&#39;user_contactmethods&#39;, &#39;my_user_contactmethods&#39;);

function my_user_contactmethods($user_contactmethods){

 $user_contactmethods[&#39;twitter&#39;] = &#39;Twitter Username&#39;;
 $user_contactmethods[&#39;facebook&#39;] = &#39;Facebook Username&#39;;

 return $user_contactmethods;
}
&lt;/pre&gt;Here is what you’ll get:&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/190_Quick_Tip_Add_Extra_Contact_Methods_to_User_Profiles/contact_enhanced.png&quot; /&gt;&lt;/div&gt;If you want to remove some fields, just unset them from the array:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;function my_user_contactmethods($user_contactmethods){

 unset($user_contactmethods[&#39;yim&#39;]);
 unset($user_contactmethods[&#39;aim&#39;]);
 unset($user_contactmethods[&#39;jabber&#39;]);

 $user_contactmethods[&#39;twitter&#39;] = &#39;Twitter Username&#39;;
 $user_contactmethods[&#39;facebook&#39;] = &#39;Facebook Username&#39;;

 return $user_contactmethods;
}
&lt;/pre&gt;&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/190_Quick_Tip_Add_Extra_Contact_Methods_to_User_Profiles/contact_unset.png&quot; /&gt;&lt;/div&gt;To display the user’s info, simply use the &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/get_user_meta&quot;&gt;get_user_meta&lt;/a&gt; function.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;echo get_user_meta(1, &#39;twitter&#39;, true);
&lt;/pre&gt;This will show the Twitter username for the user with an ID of 1. The true argument causes the data to be returned as a single value as opposed to an array.&lt;br /&gt;
That’s all there is to it!&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/246957237699321317'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/246957237699321317'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/02/quick-tip-add-extra-contact-methods-to.html' title='Quick Tip: Add Extra Contact Methods to User Profiles'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-7609262033482093335</id><published>2012-02-29T09:07:00.001+08:00</published><updated>2012-02-29T09:08:33.896+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Bots"/><category scheme="http://www.blogger.com/atom/ns#" term="Security"/><category scheme="http://www.blogger.com/atom/ns#" term="User Agents"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><title type='text'>Secure Your WordPress Against User-Agents and Bots</title><content type='html'>&quot;Lately there have been a lot of WordPress sites compromised only due to the bots that roam the world wide web! There are a lot of plugins out there which can protect your WordPress baby by blocking these “roguish” bots!&lt;br /&gt;
In this article you will be learning an easy and useful method of adeptly configuring your .htaccess file to filter these bots which can infect your website and can eat up your server resources. So get your .htaccess file ready for editing!&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 1 Preparing the Code&lt;/h2&gt;The code mainly consists of bot names. I have added the most famous bots in here that I can think of. If there is some bot missing, please mention it in the comments.&lt;br /&gt;
The code is pretty straightforward. Go ahead and copy the code below and paste it in your .htaccess file.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;# Bot Blocker
&amp;lt;IfModule mod_setenvif.c&amp;gt;
 SetEnvIfNoCase User-Agent ^$ keep_out
 SetEnvIfNoCase User-Agent (pycurl|casper|cmsworldmap|diavol|dotbot) keep_out
 SetEnvIfNoCase User-Agent (flicky|ia_archiver|jakarta|kmccrew) keep_out
 SetEnvIfNoCase User-Agent (purebot|comodo|feedfinder|planetwork) keep_out
 &amp;lt;Limit GET POST PUT&amp;gt;
   Order Allow,Deny
   Allow from all
   Deny from env=keep_out
 &amp;lt;/Limit&amp;gt;
&amp;lt;/IfModule&amp;gt;
&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Step 2 Testing the Code&lt;/h2&gt;&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/188_Secure_Your_WordPress_Against_User-Agents_and_Bots/1.jpg&quot; /&gt;&lt;/div&gt;To see whether the code is doing its job, I using recommend this website &lt;a href=&quot;http://www.botsvsbrowsers.com/SimulateUserAgent.asp&quot;&gt;Bots VS Browsers&lt;/a&gt;. This website is a good place to simulate these types of attacks. Once on their website all you have to do is select any bot from the code, which you just added to your .htaccess file, and use that as the user agent. Enter the URL of your site and hit enter. If you see a “403 Error” this means that the code is doing its job. If not the code must’ve gotten messed up while being copied into your .htaccess file, so try again.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 3 Adding More Bots&lt;/h2&gt;Now you are familiar with the code and how to test it, we can add more bots to the code. You must have noticed the repetition in the code, and by using the same logic, you can add a dozen more bots to be blocked by setting the same parameters. Cool huh!&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;SetEnvIfNoCase User-Agent (i-IS-evilBOT) keep_out
&lt;/pre&gt;As you can see in the code above, now I am blocking the “i-IS-evilBOT” (which I just made up). Other than that the name of the bot is not case sensitive and you can add it as per your liking. Go to the &lt;a href=&quot;http://www.botsvsbrowsers.com/SimulateUserAgent.asp&quot;&gt;Bots VS Browsers&lt;/a&gt; page and this time enter the user agent which I just created, and voila, you’ll see that this user agent which was added to my .htaccess file is also blocked! You can add as many bots as you want to be blocked separated with a pipe character “|”&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/188_Secure_Your_WordPress_Against_User-Agents_and_Bots/2.jpg&quot; /&gt;&lt;/div&gt;&lt;hr /&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;I said in the beginning that there are many plugins which can do the same thing and you can avoid this editing. But by manually editing the .htaccess file you can effectively block bad user-agents and bots with better efficiency and better site performance!&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/7609262033482093335'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/7609262033482093335'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/02/secure-your-wordpress-against-user.html' title='Secure Your WordPress Against User-Agents and Bots'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-8177598649437500583</id><published>2012-02-29T08:58:00.001+08:00</published><updated>2012-02-29T08:59:16.143+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Envato API"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorial"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><title type='text'>Using the Envato API with WordPress</title><content type='html'>&quot;Today we are going to discuss how to use the Envato API in WordPress and create a WordPress shortcode that promotes our Envato Marketplace Items inside our WordPress site. We will combine the powerful Envato API, WordPress’ flexibility and a little bit of creativity, to build an amazing plugin for our site.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Let’s Set Our Goal&lt;/h2&gt;In this tutorial we are going to focus on:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Some basic knowledge about the Envato API&lt;/li&gt;
&lt;li&gt;How to use API result data inside WordPress&lt;/li&gt;
&lt;li&gt;Build a WordPress Shortcode that promotes Envato Marketplace items in our WordPress site.&lt;/li&gt;
&lt;/ul&gt;So let’s get into the first one!&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 1: Understanding the Envato API&lt;/h2&gt;Envato provides an API that allows developers to get some information about Envato Marketplace items, users info, popular projects and so on. All possible queries are listed in the &lt;a href=&quot;http://marketplace.envato.com/api/documentation&quot;&gt;official documentation&lt;/a&gt;. In this article we discuss the public API only.&lt;br /&gt;
The Envato Public API has the following structure.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;http://marketplace.envato.com/api/edge/set.json
&lt;/pre&gt;The word &lt;strong&gt;set&lt;/strong&gt; must to be replaced with an option listed in the set column of the API documentation. So if we want all information about a marketplace item we have to replace &lt;em&gt;set&lt;/em&gt; with &lt;em&gt;item:the_item_id&lt;/em&gt;. The final request URL will be:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;http://marketplace.envato.com/api/edge/item:1263846.json
&lt;/pre&gt;You can try to insert the URL above in your web browser and see the returned data.&lt;br /&gt;
We can also concatenate more than one &lt;em&gt;set option&lt;/em&gt; in a single request to get more data. For example we want the item data and its author information. So the previous URL will become:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;http://marketplace.envato.com/api/edge/item:1263846+user:evoG.json
&lt;/pre&gt;The Envato API returns JSON, so in the next paragraph we are going to show how to manage it in WordPress.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 2: How to Use API Results in WordPress&lt;/h2&gt;In this tutorial we are not going to discuss how to create a WordPress plugin, but we are going to focus on some techniques to use the API in WordPress:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Send the API request&lt;/li&gt;
&lt;li&gt;Manage the result data (the JSON string)&lt;/li&gt;
&lt;/ul&gt;The function below fetches the data from the Envato server and returns a PHP array that contains all the informations we want.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;/**
* @param String $item_id - The ID of an Envato Marketplace item
* @returns Array - The item informations
*/
function WPTP_get_item_info( $item_id ) {

 /* Set the API URL, %s will be replaced with the item ID  */
 $api_url = &quot;http://marketplace.envato.com/api/edge/item:%s.json&quot;;

 /* Fetch data using the WordPress function wp_remote_get() */
 $response = wp_remote_get( sprintf( $api_url, $item_id ) );

 /* Check for errors, if there are some errors return false */
 if ( is_wp_error( $response ) or ( wp_remote_retrieve_response_code( $response ) != 200 ) ) {
  return false;
 }

 /* Transform the JSON string into a PHP array */
 $item_data = json_decode( wp_remote_retrieve_body( $response ), true );

 /* Check for incorrect data */
 if ( !is_array( $item_data ) ) {
  return false;
 }

 /* Return item info array */
 return $item_data;

}
&lt;/pre&gt;We can improve the function above. To prevent stress on the Envato API server we can cache item data and request the info again after a timeout. WordPress offers us some functions to implement this feature. Let’s add it.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;/**
* @param String $item_id - The ID of an Envato Marketplace item
* @returns Array - The item informations
*/
function WPTP_get_item_info( $item_id ) {

 /* Data cache timeout in seconds - It send a new request each hour instead of each page refresh */
 $CACHE_EXPIRATION = 3600;

 /* Set the transient ID for caching */
 $transient_id = &#39;WPTP_envato_item_data&#39;;

 /* Get the cached data */
 $cached_item = get_transient( $transient_id );

 /* Check if the function has to send a new API request */
 if ( !$cached_item || ( $cached_item-&amp;gt;item_id != $item_id ) ) {

  /* Set the API URL, %s will be replaced with the item ID  */
  $api_url = &quot;http://marketplace.envato.com/api/edge/item:%s.json&quot;;

  /* Fetch data using the WordPress function wp_remote_get() */
  $response = wp_remote_get( sprintf( $api_url, $item_id ) );

  /* Check for errors, if there are some errors return false */
  if ( is_wp_error( $response ) or ( wp_remote_retrieve_response_code( $response ) != 200 ) ) {
   return false;
  }

  /* Transform the JSON string into a PHP array */
  $item_data = json_decode( wp_remote_retrieve_body( $response ), true );

  /* Check for incorrect data */
  if ( !is_array( $item_data ) ) {
   return false;
  }

  /* Prepare data for caching */
  $data_to_cache = new stdClass();
  $data_to_cache-&amp;gt;item_id = $item_id;
  $data_to_cache-&amp;gt;item_info = $item_data;

  /* Set the transient - cache item data*/
  set_transient( $transient_id, $data_to_cache, $CACHE_EXPIRATION );

  /* Return item info array */
  return $item_data;

 }

 /* If the item is already cached return the cached info */
 return $cached_item-&amp;gt;item_info;

}
&lt;/pre&gt;Now the core function of our WordPress plugin is ready. We have used some WordPress functions that help us to save time. All information about them is explained in the official &lt;a href=&quot;http://codex.wordpress.org/&quot;&gt;WordPress Codex&lt;/a&gt;.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;em&gt;&lt;a href=&quot;http://codex.wordpress.org/Function_API/wp_remote_get&quot;&gt;wp_remote_get()&lt;/a&gt;&lt;/em&gt; – Retrieves a URL using the HTTP GET method&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href=&quot;http://codex.wordpress.org/Function_API/wp_remote_retrieve_response_code&quot;&gt;wp_remote_retrieve_response_code()&lt;/a&gt;&lt;/em&gt; – Checks that there are no errors inside the raw response&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href=&quot;http://codex.wordpress.org/Function_API/wp_remote_retrieve_body&quot;&gt;wp_remote_retrieve_body()&lt;/a&gt;&lt;/em&gt; – Retrieves the body of an already retrieved HTTP request.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href=&quot;http://codex.wordpress.org/Function_Reference/set_transient&quot;&gt;set_transient()&lt;/a&gt;&lt;/em&gt; – Caches data&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href=&quot;http://codex.wordpress.org/Function_Reference/get_transient&quot;&gt;get_transient()&lt;/a&gt;&lt;/em&gt; – Gets cached data&lt;/li&gt;
&lt;/ul&gt;&lt;hr /&gt;&lt;h2&gt;Step 3: Build WordPress Shortcode&lt;/h2&gt;In the next steps we are going to code a useful WordPress plugin that allows us to display some informations about an Envato Marketplace item. All code below is well commented so you can easily understand each line. For more details about &lt;a href=&quot;http://codex.wordpress.org/Writing_a_Plugin&quot;&gt;Writing a WordPress Plugin&lt;/a&gt; and the &lt;a href=&quot;http://codex.wordpress.org/Shortcode_API&quot;&gt;WordPress Shortcode API&lt;/a&gt; check out the online documentation in the &lt;a href=&quot;http://codex.wordpress.org/&quot;&gt;WordPress Codex&lt;/a&gt;.&lt;br /&gt;
&lt;h3&gt;Let’s start&lt;/h3&gt;Let’s write the header informations for our plugin&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php
/*
Plugin Name: WordPress Tutsplus Envato Item Info
Plugin URI: http://wp.tutsplus.com
Description: Display some informations about Envato Marketplace items
Version: 1.0
Author: Michele Ivani
Author URI: http://evographics.net
*/
&lt;/pre&gt;&lt;h3&gt;Add the WordPress shortcode&lt;/h3&gt;Now we write the code to add the shortcode and its functionalities.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php
/**
* Add the shortcode using the WordPress function add_shortcode()
* We used as shortcode tag &quot;wptp-envato-item&quot;
*/
add_shortcode( &#39;wptp-envato-item&#39;, &#39;WPTP_add_shortcode&#39; );

/**
* Hook to run when the shortcode is found
* @param Array $atts - shortcode attributes
* @param String $content - shortcode content (not necessary for our plugin)
* @return String - plugin HTML code
*/
function WPTP_add_shortcode( $atts, $content = null ) {

 /* Default shortcode attributes  */
 $atts = shortcode_atts( array(
  &#39;item_id&#39; =&amp;gt; &#39;&#39;
 ), $atts );

 extract( $atts );

 /* Validation */
 if ( empty( $item_id ) ) {
  return &quot;&amp;lt;p&amp;gt;Please insert an Envato Marketplace Item ID.&amp;lt;/p&amp;gt;&quot;;
 }

 /* Get data from the API*/
 $item = WPTP_get_item_info( $item_id );

 /* Validation - Check if something went wrong */
 if ( $item === false ) {
  return &quot;&amp;lt;p&amp;gt;Oops… Something went wrong. Please check out the item ID and try again.&amp;lt;/p&amp;gt;&quot;;
 }

 /* Format the $item array */
 $item = $item[&#39;item&#39;];
 extract( $item );

 /* Prepare the Plugin HTML */
 $html = &#39;&#39;;

 $html .= &#39;
 &amp;lt;div class=&quot;wptp_envato_item&quot;&amp;gt;

  &amp;lt;div class=&quot;wptp_title&quot;&amp;gt;&#39;.$item.&#39;&amp;lt;/div&amp;gt;

  &amp;lt;div class=&quot;wptp_wrap&quot;&amp;gt;

   &amp;lt;div class=&quot;wptp_top&quot;&amp;gt;

    &amp;lt;div class=&quot;wptp_rating&quot;&amp;gt;

     &amp;lt;span class=&quot;wptp_desc&quot;&amp;gt;rating&amp;lt;/span&amp;gt;&#39;.

     WPTP_get_stars($rating)

    .&#39;&amp;lt;/div&amp;gt; &amp;lt;!-- end wptp_rating --&amp;gt;

   &amp;lt;/div&amp;gt; &amp;lt;!-- end wptp_top --&amp;gt;

   &amp;lt;div class=&quot;wptp_middle&quot;&amp;gt;

    &amp;lt;div class=&quot;wptp_sales&quot;&amp;gt;

     &amp;lt;span class=&quot;wptp_img_sales&quot;&amp;gt;&amp;lt;/span&amp;gt;

     &amp;lt;div class=&quot;wptp_text&quot;&amp;gt;

      &amp;lt;span class=&quot;wptp_num&quot;&amp;gt;&#39;.$sales.&#39;&amp;lt;/span&amp;gt;
      &amp;lt;span class=&quot;wptp_desc&quot;&amp;gt;sales&amp;lt;/span&amp;gt;

     &amp;lt;/div&amp;gt; &amp;lt;!-- end  wptp_text --&amp;gt;

    &amp;lt;/div&amp;gt; &amp;lt;!-- end wptp_sales --&amp;gt;

    &amp;lt;div class=&quot;wptp_thumb&quot;&amp;gt;
     &amp;lt;img src=&quot;&#39;.$thumbnail.&#39;&quot; alt=&quot;&#39;.$item.&#39;&quot; width=&quot;80&quot; height=&quot;80&quot;/&amp;gt;
    &amp;lt;/div&amp;gt; &amp;lt;!-- end wptp_thumb --&amp;gt;

    &amp;lt;div class=&quot;wptp_price&quot;&amp;gt;

     &amp;lt;span class=&quot;wptp_img_price&quot;&amp;gt;&amp;lt;/span&amp;gt;

     &amp;lt;div class=&quot;wptp_text&quot;&amp;gt;

      &amp;lt;span class=&quot;wptp_num&quot;&amp;gt;&amp;lt;span&amp;gt;${body}lt;/span&amp;gt;&#39;.round($cost).&#39;&amp;lt;/span&amp;gt;
      &amp;lt;span class=&quot;wptp_desc&quot;&amp;gt;only&amp;lt;/span&amp;gt;

     &amp;lt;/div&amp;gt; &amp;lt;!-- end wptp_text --&amp;gt;

    &amp;lt;/div&amp;gt; &amp;lt;!-- end wptp_price --&amp;gt;

   &amp;lt;/div&amp;gt; &amp;lt;!-- end wptp_middle --&amp;gt;

   &amp;lt;div class=&quot;wptp_bottom&quot;&amp;gt;

    &amp;lt;a href=&quot;&#39;.$url.&#39;&quot; target=&quot;_blank&quot;&amp;gt;&amp;lt;/a&amp;gt;

   &amp;lt;/div&amp;gt; &amp;lt;!-- end wptp_bottom --&amp;gt;

  &amp;lt;/div&amp;gt; &amp;lt;!-- end wptp_wrap --&amp;gt;

 &amp;lt;/div&amp;gt; &amp;lt;!-- end wptp_envato_item --&amp;gt;&#39;; 

 return $html;
}
&lt;/pre&gt;&lt;h3&gt;Star ratings function&lt;/h3&gt;The &lt;em&gt;WPTP_add_shortcode()&lt;/em&gt; function above has the &lt;em&gt;WPTP_get_stars()&lt;/em&gt; procedure that coverts the rating number to HTML stars. Let’s implement it.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php
/**
* Convert the rating number to HTML stars
* @param String $rating - Envato Item rating
*/
function WPTP_get_stars( $rating ) {

 /* If item rating is null the function prints a message */
 if ( ( int ) $rating == 0 ) {
  return &#39;&amp;lt;div class=&quot;wptp_not_rating&quot;&amp;gt;Not rate yet&amp;lt;/div&amp;gt;&#39;;
 }

 /* Else if rating is &amp;gt;= 1 the function converts it to HTML stars and returns them as a string */
 $return = &#39;&amp;lt;ul class=&quot;wptp_stars&quot;&amp;gt;&#39;;
 $i=1;
 while ( ( --$rating ) &amp;gt;= 0 ) {
  $return .= &#39;&amp;lt;li class=&quot;wptp_full_star&quot;&amp;gt;&amp;lt;/li&amp;gt;&#39;;
  $i++;
 }

 if ( $rating == -0.5 ) {
  $return .= &#39;&amp;lt;li class=&quot;wptp_full_star&quot;&amp;gt;&amp;lt;/li&amp;gt;&#39;;
  $i++;
 }

 while ( $i &amp;lt;= 5 ) {
  $return .= &#39;&amp;lt;li class=&quot;wptp_empty_star&quot;&amp;gt;&amp;lt;/li&amp;gt;&#39;;
  $i++;
 }

 $return .= &#39;&amp;lt;/ul&amp;gt;&#39;;

 return $return;

}
&lt;/pre&gt;&lt;h3&gt;Include CSS&lt;/h3&gt;When the shortcode functions are completed, we have to include the &lt;em&gt;style.css&lt;/em&gt; file that styles our plugin.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php
/**
* Add the CSS style file
*/
add_action( &#39;wp_print_styles&#39;, &#39;WPTP_add_css&#39; );

/**
* Attach the plugin CSS file to the WordPress site
*/
function WPTP_add_css() {
 /* Register style */
 wp_register_style( &#39;WPTP_css&#39;, plugins_url( &#39;style.css&#39;, __FILE__ ) );

 /* Enqueue style */
 wp_enqueue_style( &#39;WPTP_css&#39; );
}
&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Step 4: Write CSS Rules&lt;/h2&gt;The &lt;em&gt;style.css&lt;/em&gt; file is inside the same directory as the main plugin file and it contains all the CSS rules.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;/* WordPress Tutsplus Envato Item Info - CSS Rules*/

/* Main layout and typography */
.wptp_envato_item {
 font-family: &quot;Helvetiva Neue&quot;, Arial, sans-serif;
 margin: 20px 0;
}

.wptp_wrap { width: 210px; }

.wptp_text { display: block; }

.wptp_num {
 display: block;
 font-size: 24px;
 font-weight: 300;
 margin: 0;
 padding: 0;
 line-height: 24px;
 color: #66696d;
}

.wptp_num span {
 font-size: 14px;
 vertical-align: super;
}

.wptp_desc {
 display: block;
 font-size: 12px;
 font-weight: 300;
 margin: 0;
 padding: 0;
 line-height: 12px;
 color: #96999d;
}

.wptp_not_rating {
 color: #66696d;
 font-size: 13px;
 font-weight: bold;
}

.wptp_title { font-size: 14px; font-weight: 300; color: #66696d; margin-bottom: 10px; }

/* Stars rating section */

.wptp_rating {
 width: 82px;
 text-align: center;
 margin: 0 auto 10px auto;
}

.wptp_stars {
 margin: 0;
 padding: 0;
 list-style: none;
}

.wptp_stars li {
 margin-left: 2px;
 display: inline-block;
 vertical-align: middle;
 width: 13px;
 height: 13px;
}

.wptp_stars li.wptp_full_star { background: url(icons-sprite.png) 0px -64px ; }

.wptp_stars li.wptp_empty_star { background: url(icons-sprite.png) -14px -64px ; }

/* Sales and Price sections */
.wptp_sales, .wptp_thumb, .wptp_price {
 display: inline-block;
 vertical-align: middle;
}

.wptp_sales {
 text-align: right;
 margin-right: 10px;
}

.wptp_sales .wptp_text {
 width: 52px;
}

.wptp_img_sales {
 background: url(icons-sprite.png) 0px 0px;
 width: 32px;
 height: 32px;
 display: block;
 margin: 0 0 12px 20px;
}

.wptp_img_price {
 background: url(icons-sprite.png) 0px -32px ;
 width: 32px;
 height: 32px;
 display: block;
 margin-bottom: 7px;
}

.wptp_price {
 text-align: left;
 margin-left: 10px;
}

.wptp_price .wptp_text { width: 34px; }

/* Purchase button section */
.wptp_bottom a {
 display: block;
 width: 78px;
 height: 33px;
 background: url(icons-sprite.png) -32px 0px;
 margin: 10px auto 0 auto;
}
&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;That’s it, now we can upload the plugin to our Worpdress site and use the power of WordPress shortcodes to display some info about Envato Marketplace items. For more details about &lt;a href=&quot;http://codex.wordpress.org/Writing_a_Plugin&quot;&gt;Writing a WordPress Plugin&lt;/a&gt; and the &lt;a href=&quot;http://codex.wordpress.org/Shortcode_API&quot;&gt;WordPress Shortcode API&lt;/a&gt; check out the online documentation on the &lt;a href=&quot;http://codex.wordpress.org/&quot;&gt;WordPress Codex&lt;/a&gt;.&lt;br /&gt;
I’m Michele Ivani and I hope this tutorial was helpful for your WordPress development. Thanks so much for reading.&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/8177598649437500583'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/8177598649437500583'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/02/using-envato-api-with-wordpress.html' title='Using the Envato API with WordPress'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-541870660716385269</id><published>2012-02-07T10:56:00.003+08:00</published><updated>2012-02-07T10:57:24.824+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="eCommerce"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorial"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress Plugins"/><title type='text'>How to Build an E-Commerce Website Using WordPress: Part 2</title><content type='html'>&quot;This is the second and final part of the &lt;a href=&quot;http://wp.tutsplus.com/tutorials/how-to-build-an-e-commerce-website-using-wordpress-part-1/&quot;&gt;WordPress E-Commerce tutorial.&lt;/a&gt; Here we will go through the final steps of completing our WordPress e-commerce web site. You will be shown with the process of adding products to your site, using different widgets to enhance your site, using different reports to keep track of the sales and efficient use of  shortcodes.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Once done with the wp-ecommerce settings, adding your products and selling becomes child’s play.&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt;Before We Move On &lt;/h2&gt;Before we dive straight into the process, let’s look at a few changes we made to the e-commerce site since part 1.&lt;br /&gt;
1. We have installed the latest version of &lt;strong&gt;Liquorice&lt;/strong&gt; theme, i.e &lt;strong&gt;Liquorice 2.2&lt;/strong&gt; by&lt;strong&gt; Nudge Design&lt;/strong&gt;.&lt;br /&gt;
2. We have updated WordPress to the latest &lt;strong&gt;WordPress 3.3 &lt;/strong&gt;version.&lt;br /&gt;
3. Under&lt;strong&gt; Settings -&amp;gt; Store -&amp;gt; Shipping&lt;/strong&gt; we have edited the &lt;strong&gt;Flat Rate&lt;/strong&gt; option and put $ 0.00 under all the fields. This is done since we will use different shipping rates for different products (without any base rates). Putting $ 0.00 keeps this feature enabled.  If you want to keep a Base rate to be added to the individual shipping cost of each product, you may enter your Base rates here. &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/163_ECommercePart2/Article/Article/image2.JPG&quot; /&gt;&lt;/div&gt;Now our site looks like…. &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/163_ECommercePart2/Article/Article/image3.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;&lt;hr /&gt;&lt;h2&gt; Adding Products &lt;/h2&gt;Lets discuss a few useful options before we add our first product.&lt;br /&gt;
1. The&lt;strong&gt; Product -&amp;gt; Coupons&lt;/strong&gt; page lets us add special discount coupons for the products. Here you can specify the &lt;strong&gt;Coupon Code, Discount, Coupon Expiry Date &lt;/strong&gt;and other conditions as per your requirements. &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/163_ECommercePart2/Article/Article/image4.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;2. The &lt;strong&gt;Product -&amp;gt; Variations&lt;/strong&gt; options lets you add variations to your products. &lt;br /&gt;
Supose you are selling T-Shirts and you want to specify its variations in Size or Color. This options lets you define your &lt;strong&gt;Variations Set &lt;/strong&gt;first and then define the different variations under it. You can also set a price for each of the variations. &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/163_ECommercePart2/Article/Article/image5.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;3. The &lt;strong&gt;Product -&amp;gt; Product Tags &lt;/strong&gt;options lets you define your own product tags useful for searching a product while using the&lt;strong&gt; Product Tags&lt;/strong&gt; &lt;strong&gt;widget&lt;/strong&gt;.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/163_ECommercePart2/Article/Article/image6.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;&lt;hr /&gt;&lt;h2&gt;Adding Product Categories &lt;/h2&gt;Before adding a product lets add our product categories from the &lt;strong&gt;Products -&amp;gt; Categories&lt;/strong&gt; page. &lt;br /&gt;
While adding a category you need to specify the&lt;strong&gt; Name, Parent Category&lt;/strong&gt; (if any) and &lt;strong&gt;Description&lt;/strong&gt;. You may specify a &lt;strong&gt;Thumbnail image&lt;/strong&gt; and also restrict a few countries from accessing this product. As of now we have added three categories- &lt;strong&gt;Flowers, Confectioneries &lt;/strong&gt;and &lt;strong&gt;Chocolates&lt;/strong&gt;. &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/163_ECommercePart2/Article/Article/image7.jpg&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;&lt;hr /&gt;&lt;h2&gt;Adding Your First Product&lt;/h2&gt;The&lt;strong&gt; Products -&amp;gt; Add New&lt;/strong&gt; option lets you add products to your e-commerce site. &lt;br /&gt;
Here you need to specify the&lt;strong&gt; Product Name, Product Description, Product Tags&lt;/strong&gt; and categorize your product under the created &lt;strong&gt;Categories&lt;/strong&gt;.  The  &lt;strong&gt;Variations&lt;/strong&gt; option lets you add your created Variations to this product. &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/163_ECommercePart2/Article/Article/image8.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;Now you need to add the &lt;strong&gt;Price, Stock&lt;/strong&gt; and &lt;strong&gt;Taxes&lt;/strong&gt;(if any) of this product. While adding the Price, you can also specify a Sale Price to show a discounted price to your customers, which  will increase the customer’s interest. &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/163_ECommercePart2/Article/Article/image9.JPG&quot; /&gt;&lt;/div&gt;The &lt;strong&gt;Product Download&lt;/strong&gt; option is used if you are selling downloadable products. &lt;br /&gt;
Please upload Product image by clicking the &lt;strong&gt;Manage Products Images&lt;/strong&gt; link. Here you have the option to upload the image form your local hard disk, URL or using your WordPress Media Library. You can also Drag and Drop your images in this page. &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/163_ECommercePart2/Article/Article/image10.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;The most important part is specifying your shipping options. Here at first you need to specify a &lt;strong&gt;Weight&lt;/strong&gt; for your product and then specify the &lt;strong&gt;Local&lt;/strong&gt; and &lt;strong&gt;International&lt;/strong&gt; &lt;strong&gt;Shipping&lt;/strong&gt; &lt;strong&gt;Charges&lt;/strong&gt;. You also have the option to disregard the shipping charges. &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/163_ECommercePart2/Article/Article/image11.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;After making all the changes click on &lt;strong&gt;Publish&lt;/strong&gt;.&lt;br /&gt;
Now your product appears under the &lt;strong&gt;Products -&amp;gt; Products&lt;/strong&gt; option. You can edit/delete the product  from here.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/163_ECommercePart2/Article/Article/image12.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;Lets add two more products to our site. &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/163_ECommercePart2/Article/Article/image13.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;&lt;strong&gt;Lightbox effect &lt;/strong&gt;Image of products.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/163_ECommercePart2/Article/Article/image14.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;In the same way you can add different products to your site. You can also use the&lt;strong&gt; Settings -&amp;gt; Store -&amp;gt; Import &lt;/strong&gt;option to upload products in a batch using a comma delimited text file.. After adding the products you can upload the images and insert the additional details.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Using a Few Essential Widgets &lt;/h2&gt;Under the &lt;strong&gt;Appearance -&amp;gt; Widgets&lt;/strong&gt;, you will find many useful widgets. You just need to drag and drop it in the area of the page where you want to place it. Lets discuss a few of these one by one.&lt;br /&gt;
1.&lt;strong&gt; Latest Products&lt;/strong&gt;– Using the Latest Products widget will display the recently added products on your sidebar or the area where you are placing this widget. &lt;br /&gt;
2. &lt;strong&gt;Products Categories&lt;/strong&gt; – Using this widget will show all your product categories in your sidebar. The customer can search for products using those categories. &lt;br /&gt;
3.&lt;strong&gt; Product Specials&lt;/strong&gt; – This widget displays those products that is on Sale in your site, i.e if the product has any discounted price or the Table Rate Price. &lt;br /&gt;
4. &lt;strong&gt;Product Tags&lt;/strong&gt;- This widget displays the specified product tags in your sidebar so that customer can search for their required products using those Tags. &lt;br /&gt;
5. &lt;strong&gt;Price Range&lt;/strong&gt; – This widget adds the price range of the products in your sidebar through which the customer can search for the products using different price ranges.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/163_ECommercePart2/Article/Article/image15.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;6. &lt;strong&gt;Shopping Cart&lt;/strong&gt; – If you have selected the &lt;strong&gt;Widget&lt;/strong&gt; option for your &lt;strong&gt;Cart Location&lt;/strong&gt; , you can use this widget to display the shopping cart in your sidebar. &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/163_ECommercePart2/Article/Article/image16.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;7. &lt;strong&gt;Text&lt;/strong&gt;- This wizard is very helpful if you want to display any special ad on your website. You can also copy paste html snippets in this widget. &lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Reporting &lt;/h2&gt;Once the products have been purchased, you can see the purchase reports under the &lt;strong&gt;Sales Summary, Sales by Quarter &lt;/strong&gt;and&lt;strong&gt; Sales by Month.&lt;/strong&gt; Under the &lt;strong&gt;Sales Summary&lt;/strong&gt; you will get to know the current month’s sales as well as the &lt;strong&gt;Total Income&lt;/strong&gt;. The &lt;strong&gt;Sales by Quarter&lt;/strong&gt; displays the sales by Financial Quarters and &lt;strong&gt;Sales by Month &lt;/strong&gt;displays Last four months of sales on a per product basis.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/163_ECommercePart2/Article/Article/image17.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;&lt;strong&gt;Under Dashboard -&amp;gt; Store Sales&lt;/strong&gt;, you will get a summary of the sales for the Current Month. It is through this screen that you will be able to see all the sales details and also process the orders. You can change the&lt;strong&gt; Sales Status&lt;/strong&gt; and also add anew&lt;strong&gt; Tracking IDs&lt;/strong&gt; to each of the products. Clicking on the &lt;strong&gt;Details-&amp;gt;Items&lt;/strong&gt; displays the  invoice. You can also email the customer the purchase receipt from this page.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/163_ECommercePart2/Article/Article/image18.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;That’s it your e-commerce site is ready for the first sale.While checking out, the system automatically asks for you Login Credentials or Registers you if you are a new customer.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Importance of Shortcodes&lt;/h2&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br /&gt;
A shortcode is a specific code in WordPress that lets you do great things using very little effort. The other name of Shortcode is Shortcut, you can embed files or create objects using just one line of shortcode which otherwise would have required lots of ugly codes. &lt;br /&gt;
Here are the details of a few important shortcodes used in our site.&lt;br /&gt;
&lt;strong&gt;productspage&lt;/strong&gt; shortcode helps in displaying the complete list of products and their presentation in the website. This is a very important shortcode in Wp e-commercerce that is used within Products Pages, Products Categories and single Product Templates. &lt;br /&gt;
&lt;strong&gt;shoppingcart&lt;/strong&gt; shortcode displays the checkout page or the checkout template in the site. &lt;br /&gt;
&lt;strong&gt;transactionresults&lt;/strong&gt; shortcode displays the transaction page which shows the customers the  status and the summary of their purchase.&lt;br /&gt;
&lt;strong&gt;userlog&lt;/strong&gt; shortcode displays the &lt;strong&gt;My Account &lt;/strong&gt;page of the site. Its is used by already registered customers to see their details regarding purchase history, downloads and account details.&lt;br /&gt;
Some other examples of shortcodes-&lt;br /&gt;
&lt;strong&gt;[wpsc_products product_id=&#39;288&#39;] &lt;/strong&gt;– Displays the product which has ID of 288   &lt;strong&gt;[buy_now_button product_id=&#39;198&#39;]&lt;/strong&gt; – Displays a PayPal buy now button for the product(ID-198).  &lt;strong&gt;[add_to_cart=112]&lt;/strong&gt; – Displays an add to cart button for the product(ID-112).&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;I hope you have enjoyed both the e-commerce tutorials.This is only the tip of the iceberg of what can be done with the Wp e-commerce plugin. In the future I shall try to bring more tutorials on WordPress e-commerce.&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/541870660716385269'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/541870660716385269'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/02/how-to-build-e-commerce-website-using_07.html' title='How to Build an E-Commerce Website Using WordPress: Part 2'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-5224266092014919762</id><published>2012-02-07T10:56:00.001+08:00</published><updated>2012-02-07T10:56:50.076+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="eCommerce"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorial"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress Plugins"/><title type='text'>How to Build an E-Commerce Website Using WordPress: Part 1</title><content type='html'>&quot;Today we will be creating a simple but powerful e-commerce site using one of the most popular WordPress plugins called &lt;strong&gt;WP e-Commerce&lt;/strong&gt;. Using this plugin we will be creating a website which sells holiday gifts!  &lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt; Knowing WP e-Commerce Plugin&lt;/h2&gt;WP e-Commerce is a powerful shopping cart plugin for WordPress developed by &lt;strong&gt;GetShopped.org&lt;/strong&gt;. Using this plugin in WordPress lets users buy your products and services online. Given below are some of the features of this amazing plugin.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;   Easy to install.&lt;/li&gt;
&lt;li&gt;   Works with any WordPress theme.&lt;/li&gt;
&lt;li&gt;   Supports all kind of WordPress Widgets.&lt;/li&gt;
&lt;li&gt;   Template modification is very easy.&lt;/li&gt;
&lt;li&gt;   Instant support community.&lt;/li&gt;
&lt;li&gt;   All the popular payment gateways supported.&lt;/li&gt;
&lt;li&gt;   100% Search Engine friendly.&lt;/li&gt;
&lt;li&gt;   Can be used to promote products on social networking sites.&lt;/li&gt;
&lt;li&gt;   Supports multiple languages.&lt;/li&gt;
&lt;li&gt;   Can be integrated with Google.&lt;/li&gt;
&lt;li&gt;   Supports multiple currencies.&lt;/li&gt;
&lt;li&gt;   Multi shipping options.&lt;/li&gt;
&lt;li&gt;   SSL security integration and many more.&lt;/li&gt;
&lt;/ul&gt;&lt;blockquote&gt;You can start selling your products, downloads and services right away. &lt;/blockquote&gt;There are also additional features for premium customers. You can go through all of these features by clicking &lt;a href=&quot;http://wordpress.org/extend/plugins/wp-e-commerce/&quot;&gt;here.&lt;/a&gt;&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt; Prerequisites of installing WP e-Commerce&lt;/h2&gt;Before installing and activating the plugin lets discuss some core pre requirements.&lt;br /&gt;
1. WordPress development environment must be ready in your system.You can either host your site locally or using a web hosting service. You can also use &lt;strong&gt;BitNami &lt;/strong&gt;for WordPress, which is a great combined tool for WordPress development and testing.&lt;br /&gt;
2. Please log in to your WordPress admin and go to &lt;strong&gt;Post -&amp;gt; All Posts&lt;/strong&gt; and remove (trash) the default post from the list.&lt;br /&gt;
3. Please go to &lt;strong&gt;Posts -&amp;gt; Categories&lt;/strong&gt; and create categories relevant to your products. Here we will create &lt;strong&gt;Bakery Items, Confectionaries&lt;/strong&gt; and &lt;strong&gt;Flowers&lt;/strong&gt;. While creating the categories you just need to provide the name and a short description.We have changed the &lt;strong&gt;Uncategorized &lt;/strong&gt;category to &lt;strong&gt;Bakery&lt;/strong&gt; &lt;strong&gt;Items&lt;/strong&gt;.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image2.jpg&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;4. Please go to&lt;strong&gt; Pages -&amp;gt; All Pages&lt;/strong&gt; and remove (trash) the default page from there.&lt;br /&gt;
5. You can customize and keep the current theme or go to &lt;strong&gt;Appearance -&amp;gt; Themes&lt;/strong&gt; to install a new one that suits your e-commerce site. You can also use third party themes for your e-commerce site.&lt;br /&gt;
6. On the &lt;strong&gt;Appearance &lt;/strong&gt;menu click on &lt;strong&gt;Header&lt;/strong&gt; and upload your site’s header image. You may need to crop the image while uploading.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image3.jpg&quot; width=&quot;599px&quot; /&gt;&lt;/div&gt;7. Under the &lt;strong&gt;Settings -&amp;gt; General&lt;/strong&gt; change the following things.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;   &lt;strong&gt; Site Title&lt;/strong&gt; to Christmas Shopping&lt;/li&gt;
&lt;li&gt;   &lt;strong&gt;Tagline&lt;/strong&gt; to Gift n Enjoy&lt;/li&gt;
&lt;li&gt;   Select the &lt;strong&gt;Anyone can Register&lt;/strong&gt; option.&lt;/li&gt;
&lt;/ul&gt;Please click on &lt;strong&gt;Save Changes&lt;/strong&gt; after changing these options.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image4.jpg&quot; width=&quot;599px&quot; /&gt;&lt;/div&gt;8. Please go to &lt;strong&gt;Settings-&amp;gt; Permalinks&lt;/strong&gt;. Select &lt;strong&gt;Custom Structure&lt;/strong&gt; and enter &lt;strong&gt;/%postname%/&lt;/strong&gt;. Finally  &lt;strong&gt;Save &lt;/strong&gt;the changes done. Permalinks helps you to create customized urls for your pages instead of the default ones.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image5.jpg&quot; width=&quot;599px&quot; /&gt;&lt;/div&gt;9. In the &lt;strong&gt;Settings -&amp;gt; Discussions&lt;/strong&gt; page, uncheck all the options and click &lt;strong&gt;Save Changes&lt;/strong&gt;. This will prevent any type of comment in your e-commerce site.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image6.jpg&quot; width=&quot;599px&quot; /&gt;&lt;/div&gt;&lt;hr /&gt;&lt;h2&gt;  Installing WP-eCommerce&lt;/h2&gt;This plugin can be installed either manually or from the WordPress plugin menu.&lt;br /&gt;
Lets install it using the easiest method that is by using the WordPress plugin menu.&lt;br /&gt;
Please go to &lt;strong&gt;Plugins -&amp;gt; Add New&lt;/strong&gt; and Search for &lt;strong&gt;WP e-commerce&lt;/strong&gt;. In the list generated locate the WP e-commerce plugin and click on &lt;strong&gt;Install Now.&lt;/strong&gt;&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image7.jpg&quot; /&gt;&lt;/div&gt;&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image8.jpg&quot; width=&quot;599px&quot; /&gt;&lt;/div&gt;&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image9.jpg&quot; width=&quot;599px&quot; /&gt;&lt;/div&gt;After the plugin is installed, click on &lt;strong&gt;Activate Plugin&lt;/strong&gt; to activate the plugin.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image10.jpg&quot; width=&quot;599px&quot; /&gt;&lt;/div&gt;That’s it the plug has been installed and ready to use.&lt;br /&gt;
After the plugin is installed, you will see a &lt;strong&gt;Products &lt;/strong&gt;menu in your dashboard and a &lt;strong&gt;Store &lt;/strong&gt;option under &lt;strong&gt;Settings&lt;/strong&gt;. The &lt;strong&gt;Products &lt;/strong&gt;menu is used for adding different products to your site and the &lt;strong&gt;Store &lt;/strong&gt;option is used for the plugin settings.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image11.jpg&quot; /&gt;&lt;/div&gt;&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image12.jpg&quot; /&gt;&lt;/div&gt;In your dashboard you will also find three new items which shows- &lt;strong&gt;Sales by Quarter, Sales by Month &lt;/strong&gt;and &lt;strong&gt;Sales Summary.&lt;/strong&gt;&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image13.jpg&quot; width=&quot;599px&quot; /&gt;&lt;/div&gt;&lt;hr /&gt;&lt;h2&gt;  A few more additional changes before configuring the plugin&lt;/h2&gt;Please go to &lt;strong&gt;Settings -&amp;gt; Reading&lt;/strong&gt; and under&lt;strong&gt; Front page&lt;/strong&gt; &lt;strong&gt;displays &lt;/strong&gt;select &lt;strong&gt;A static page&lt;/strong&gt; and choose the &lt;strong&gt;Products Page &lt;/strong&gt;as your front page. This will ensure that when customers visits your site, the products page will be displayed by default.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image14.jpg&quot; width=&quot;599px&quot; /&gt;&lt;/div&gt;&lt;h2&gt;Defining a Contact Us page for your site.&lt;/h2&gt;We shall use the &lt;strong&gt;Contact Form 7&lt;/strong&gt; plugin to create a Contact Us page for the site.&lt;br /&gt;
For this please go to &lt;strong&gt;Plugins -&amp;gt; Installed Plugins&lt;/strong&gt; and &lt;strong&gt;Activate &lt;/strong&gt;the &lt;strong&gt;Contact Form 7&lt;/strong&gt; plugin. After activation please click on the plugin settings.  &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image15.jpg&quot; width=&quot;599px&quot; /&gt;&lt;/div&gt;In the plugin’s settings page you can create a customized contact us form by using different types of options available there. Under the &lt;strong&gt;Mail&lt;/strong&gt; option enter your email address beside the &lt;strong&gt;To: &lt;/strong&gt;field. Under &lt;strong&gt;Messages &lt;/strong&gt; you can use your own error messages.  Finally copy the generated  short code and paste it into your post, page or text widget content. In our case we have copied the code &lt;strong&gt;[contact-form-7 id=&quot;18&quot; title=&quot;Contact form 1&quot;] &lt;/strong&gt;to a newly created page named &lt;strong&gt;Contact Us&lt;/strong&gt;.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image16.jpg&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;Finally our site looks…&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image18.jpg&quot; /&gt;&lt;/div&gt;&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image17.jpg&quot; width=&quot;599px&quot; /&gt;&lt;/div&gt;&lt;hr /&gt;&lt;h2&gt; Lets set up the WP-eCommerce plugin before adding products&lt;/h2&gt;Please go to &lt;strong&gt;Settings -&amp;gt; Store&lt;/strong&gt;. Here you can set the different options for the plugin.&lt;br /&gt;
&lt;h2&gt; 1. General&lt;/h2&gt;a) Select a &lt;strong&gt;Base Country/ Region&lt;/strong&gt;.&lt;br /&gt;
b) Select the markets you are selling products to.&lt;br /&gt;
c) Set the amount of time the items in a customer&#39;s cart are kept reserved.&lt;br /&gt;
d) Select a &lt;strong&gt;Currency Type&lt;/strong&gt; and &lt;strong&gt;Currency Sign Location&lt;/strong&gt;.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image20.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;Finally click &lt;strong&gt;Update&lt;/strong&gt;.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt; 2. Presentation&lt;/h2&gt;a) Select &lt;strong&gt;Add to Cart&lt;/strong&gt; under &lt;strong&gt;Button Type&lt;/strong&gt;.&lt;br /&gt;
b)You can enable additional options from &lt;strong&gt;Show Product Ratings&lt;/strong&gt;, &lt;strong&gt;Show Stock Availability&lt;/strong&gt;, &lt;strong&gt;Display Fancy Purchase Notifications&lt;/strong&gt;, &lt;strong&gt;Display per item shipping &lt;/strong&gt; etc. For now we will only enable the&lt;strong&gt; Display per item&lt;/strong&gt; &lt;strong&gt;shipping&lt;/strong&gt;: option.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image21.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;c) Under &lt;strong&gt;Gird View Settings&lt;/strong&gt; we will enter &lt;strong&gt;3 &lt;/strong&gt;products per row and select &lt;strong&gt;Display Description&lt;/strong&gt;, &lt;strong&gt;Display &quot;Add to Cart&quot; Button&lt;/strong&gt; and &lt;strong&gt;Display &quot;More Details&quot; Button&lt;/strong&gt; options.&lt;br /&gt;
d) Under &lt;strong&gt;Shopping Cart Settings&lt;/strong&gt; select &lt;strong&gt;Cart Location&lt;/strong&gt; as &lt;strong&gt;Widget&lt;/strong&gt;. and enable &lt;strong&gt;Display &quot;+ Postage &amp;amp; Tax&quot;&lt;/strong&gt;:&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image22.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;e) You can set the product image thumbnail format from the &lt;strong&gt;Thumbnail Settings&lt;/strong&gt;.&lt;br /&gt;
f) You may enable other options as per your requirements. As of now we shall keep the other options as default.&lt;br /&gt;
Finally click &lt;strong&gt;Update&lt;/strong&gt;.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt; 3. Admin&lt;/h2&gt;a) The first three options are used for downloadable products like software, music, games etc.&lt;br /&gt;
b) Under &lt;strong&gt;Purchase Log Email &lt;/strong&gt;and &lt;strong&gt;Purchase Receipt – Reply Address: &lt;/strong&gt; enter your email address.&lt;br /&gt;
c) Enter your name against &lt;strong&gt;Purchase Receipt – Reply Name&lt;/strong&gt;:&lt;br /&gt;
d) Set &lt;strong&gt;Terms and Conditions&lt;/strong&gt; if any.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image23.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;e) You can edit the &lt;strong&gt;Purchase Receipt &lt;/strong&gt;and &lt;strong&gt;Admin Report&lt;/strong&gt; formats under the &lt;strong&gt;Custom Messages&lt;/strong&gt;.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image24.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;f) &lt;strong&gt;Tracking responses&lt;/strong&gt; can also be created from this page.&lt;br /&gt;
Finally click &lt;strong&gt;Update&lt;/strong&gt;.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt; 4. Taxes&lt;/h2&gt;Here you can define the tax rules according to your requirements. You can also define the tax per item.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image25.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;&lt;hr /&gt;&lt;h2&gt; 5. Shipping&lt;/h2&gt;a) We will enable the &lt;strong&gt;Use Shipping&lt;/strong&gt; option since we are selling Christmas Gifts.&lt;br /&gt;
b) By selecting the &lt;strong&gt;Enable Free Shipping Discount&lt;/strong&gt;, you can provide shippings discounts to customers.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image26.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;c) Under &lt;strong&gt;Shipping Modules&lt;/strong&gt; we have selected and edited the &lt;strong&gt;Fixed Rate&lt;/strong&gt; shipping option and provided the shipping rates for the customers of different countries.&lt;br /&gt;
d) Under&lt;strong&gt; External Shipping Calculators&lt;/strong&gt; we have selected &lt;strong&gt;UPS &lt;/strong&gt;as our shipping gateway and provided all the details.&lt;br /&gt;
&lt;strong&gt;Please note&lt;/strong&gt;: You need to have a UPS account in order to use this option. You can also use other shipping options.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image27.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;Finally click &lt;strong&gt;Update&lt;/strong&gt;.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt; 6. Payments&lt;/h2&gt;Here you can define the payment gateway for the customers. Among the various options available, we will use the &lt;strong&gt;Test Gateway&lt;/strong&gt; and &lt;strong&gt;PayPal Payments Standard 2.0.&lt;/strong&gt; The &lt;strong&gt;PayPal Payments Standard 2.0&lt;/strong&gt; option can be used if you have a PayPal account. This lets customers buy products using PayPal. We will also use the &lt;strong&gt;Test Gateway&lt;/strong&gt; option as a means of manual payment. After selecting and editing the payment options you need to provide all the details.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image28.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image29.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;Finally click &lt;strong&gt;Update &lt;/strong&gt;when done.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt; 7. Checkout&lt;/h2&gt;a) Under &lt;strong&gt;Misc Checkout Options&lt;/strong&gt; enable &lt;strong&gt;Users must register before checking out, Enable Shipping Same as Billing Option:&lt;/strong&gt; and &lt;strong&gt;Force users to use SSL &lt;/strong&gt;options&lt;strong&gt;.   &lt;/strong&gt;&lt;br /&gt;
b) The &lt;strong&gt;Form Fields&lt;/strong&gt; define the Customer&#39;s checkout form. You can create a new form or use the default one. You can change the field&#39;s &lt;strong&gt;Name, Type &lt;/strong&gt;and &lt;strong&gt;Mandatory &lt;/strong&gt; options. You can also &lt;strong&gt;Drag and Drop, Delete&lt;/strong&gt; different fields based on your requirements.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image30.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;Finally click &lt;strong&gt;Save Changes&lt;/strong&gt; after its done.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt; 8. Marketing&lt;/h2&gt;This option is used to share and broadcast your products among different social networking sites, RSS and Google Merchant Center. For now we shall select the &lt;strong&gt;Show Share This, Customer Survey &lt;/strong&gt;and &lt;strong&gt;Facebook Like&lt;/strong&gt; options.  &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image31.JPG&quot; width=&quot;599px/&quot; /&gt;&lt;/div&gt;Click &lt;strong&gt;Update &lt;/strong&gt;when done.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt; 9. Import&lt;/h2&gt;The import option is used to upload products automatically using a csv file. We shall come to this later.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;2&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/141_BuildingECommercePt1/Article/Article/image32.JPG&quot; width=&quot;599px&quot; /&gt;&lt;/div&gt;In the next part of this Tutorial I shall explain how to add products and use different widgets/plugins in your e-commerce site.&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/5224266092014919762'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/5224266092014919762'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/02/how-to-build-e-commerce-website-using.html' title='How to Build an E-Commerce Website Using WordPress: Part 1'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-1936908757915473349</id><published>2012-02-07T10:42:00.001+08:00</published><updated>2012-02-07T10:43:38.520+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Tips"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorial"/><category scheme="http://www.blogger.com/atom/ns#" term="Website Optimization"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><title type='text'>The Ultimate Quickstart Guide to Speeding Up Your WordPress Site</title><content type='html'>&quot;Give your site a boost! Implement crucial optimization techniques that will improve not only your &lt;strong&gt;&lt;a href=&quot;http://developer.yahoo.com/yslow/&quot;&gt;ySlow &lt;/a&gt;&lt;/strong&gt;score, but your Google rank too. In this tutorial we will cover all aspects of W3 caching, ySlow, Google page speed, CSS sprites &amp;amp; htaccess rules, to achieve a high ySlow score like i have done on &lt;a href=&quot;http://imattic.com/&quot;&gt;my blog.&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Before We Begin&lt;/h2&gt;A quick note before we start, although this tutorial will cover everything in as much detail as is required, there will (wherever possible) be shortcuts, to save you some time. &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/167_ySlowTut/img/0.png&quot; /&gt;&lt;/div&gt;&lt;hr /&gt;&lt;h2&gt;Step 1: Install the Necessary Components&lt;/h2&gt;&lt;strong&gt;Install a Caching Plugin&lt;/strong&gt;: First off, whatever caching plugin you are using, switch it off NOW! Unless it is the mighty W3 Total cache, as that is what we will be working with here. (Ok, so that came on a bit strong, but I’ve used a lot of the caching plugins and W3 is my favorite. If you’re using another for any reason, that’s probably fine – we’ll move along with the W3 recommendation though.) Head over to your “Add new” plugins section within the WordPress, search “W3 Total Cache” download it, install it but don’t switch it on… well not yet anyway.&lt;br /&gt;
&lt;strong&gt;Install a Database Manager Plugin:&lt;/strong&gt; Next you will need another plugin called “WP-DBmanager” again search and install this making sure you have no other database plugins installed.&lt;br /&gt;
Before we go ahead and start improving your site lets first see what were dealing with. Open up Google chrome or install it if you don’t have it already. Once you are in chrome install the ySlow plugin &lt;a href=&quot;https://chrome.google.com/webstore/detail/ninejjcohidippngpapiilnmkgllmakh&quot;&gt;HERE&lt;/a&gt; once installed you will see a new icon in the top right of your screen. Click it. (Ensuring you are on the homepage of your site)&lt;br /&gt;
ySlow will then check your site, tell you what’s good, what’s bad and everything in between. We want to focus first on everything that is below a grade B. Below i will run through every W3 setting you need to improve your sites load time.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/167_ySlowTut/img/1.png&quot; /&gt;&lt;/div&gt;&lt;hr /&gt;&lt;h2&gt;Step 2: Switch on W3 Total Cache&lt;/h2&gt;Once W3 Total Cache is switched on you will see a new sidebar tab called “Performance” click it. Now obviously we will run though all the different sections of W3 but to save you some time you could import the W3 settings file, bundled in the “source files” &amp;amp; jump to step 2C.&lt;br /&gt;
This is where all the settings for W3 sit. Let’s first look at the “General Settings”, you will want to tick the following boxes (to enable):&lt;br /&gt;
&lt;ul&gt;&lt;li&gt; Page Cache (select “Disk: Enhanced” in the drop down) – Caching pages will reduce the response time of your site and increase the scale of your web server.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/167_ySlowTut/img/2.png&quot; /&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt; Minify (Select “Manual”, leave the other settings) – Minification can decrease file size of HTML, CSS, JS and feeds respectively by ~10% on average.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/167_ySlowTut/img/3.png&quot; /&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt; Do not tick Database cache (we will sort this later via a different method)&lt;/li&gt;
&lt;li&gt; Object cache (select “Disk” in the drop down) – Object caching greatly increases performance for highly dynamic sites (that use the Object Cache API).&lt;/li&gt;
&lt;li&gt; Browser Cache – Enable HTTP compression and add headers to reduce server load and decrease file load time.&lt;/li&gt;
&lt;li&gt; Leave CDN, Varnish &amp;amp; cloudflare untouched. (again to do this quick upload the settings file included in the “source files” via the option at the bottom of the “General Settings”)&lt;/li&gt;
&lt;/ul&gt;&lt;hr /&gt;&lt;h2&gt;Step 2B: Get Cracking with Minify&lt;/h2&gt;Click the “Minify” tab/link at the top of the W3 panel/page. In the “HTML &amp;amp; XML” section make sure that the first three boxes are checked. Then click the “Help” button at the top. &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/167_ySlowTut/img/4.png&quot; /&gt;&lt;/div&gt;Once this popover loads up you will be faced with a list of javascript files, followed by stylesheets that your site is linking to. Essentially we want to try and tick everything EXCEPT:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt; Jquery files&lt;/li&gt;
&lt;li&gt; Google ads (or any ads for that matter)&lt;/li&gt;
&lt;li&gt; Any stats.wordpress.js files (you will have these if you have jetpack installed&lt;/li&gt;
&lt;/ul&gt;However for CSS you can pretty safely select all of them. Now this isn’t an exact science as this is minifying your theme files (Don’t worry it’s non destructive) and there are alot of different themes all employing a wide range of different files, plugins and functions. Basically preview your changes before submitting them.&lt;br /&gt;
Minify is one of the biggest improvements you will be integrating, once you have selected all your files (and done the same with every theme, if you are using more than one) then click “Apply &amp;amp; close”, directly followed by “Save all settings” (Deploy it if your site still looks/works the same).&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 2C: Head Over to Browser Cache…&lt;/h2&gt;Once your in the “Browser Cache” tab/page you will need to change the “Expires header lifetime” to 691200 seconds. This will immediately boost your ySlow score.&lt;br /&gt;
Now head back to “General Settings” and click “empty all caches”, then go to your homepage and run the ySlow test again, you should see a nice improvement.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 3: Let’s get back to that pesky Database optimization&lt;/h2&gt;Below the “Performance” sidebar tab in the WordPress backend there should be another tab with the name “Database” (if not then go back and activate it). &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/167_ySlowTut/img/6.png&quot; /&gt;&lt;/div&gt;Now this is very simple you need to do three things, backup, repair, optimize.&lt;br /&gt;
To backup click the “Backup DB” then at the bottom click “Backup” (Don’t worry about gzipping).&lt;br /&gt;
Next up we want to repair your database (just incase) so go to the “Repair DB” in the sidebar. Click the “Repair” button at the bottom.&lt;br /&gt;
Lastly, optimize it. Click the “Optimize DB” sidebar button &amp;amp; yep you’ve guessed it, click the “Optimize” button at the bottom.&lt;br /&gt;
To avoid this process again pop into the “DB Options” sidebar tab. At the bottom there will be an “Automatic Scheduling” section. Ensure that backups are done EVERY DAY (you can’t be too careful) then set it to optimize say every few days and repair once a week. Then save the changes.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 4: CSS Sprites&lt;/h2&gt;Now in ySlow you will probably have noticed in the “Make fewer HTTP requests” section a string of text that says something like “This page has 10 external background images. Try combining them with CSS sprites.”&lt;br /&gt;
Imagine the savings if all those little images could be just one image… It would sure speed things up. For this we are going to use a free tool called “Spriteme” so head on over to the site &lt;a href=&quot;http://spriteme.org/&quot;&gt;HERE&lt;/a&gt; (do so in a new tab though, again make sure your site is on the homepage). &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/167_ySlowTut/img/7.png&quot; /&gt;&lt;/div&gt;Once you have both your homepage open in one tab and spriteme open in another drag the “SpriteMe” text onto the tab that has your site in it. A box will appear in the top right of the tab/window. You’ll want to click the “make sprite” button that resides within the “Suggested Sprites” box. Once it does it’s magic download the image it has created and upload it to somewhere on your site (preferably within the theme you are using).&lt;a href=&quot;http://wp.tutsplus.com/&quot;&gt; &lt;/a&gt;&lt;br /&gt;
&lt;div&gt;&lt;a href=&quot;http://wp.tutsplus.com/&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/167_ySlowTut/img/10.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href=&quot;http://wp.tutsplus.com/&quot;&gt; &lt;/a&gt;&lt;br /&gt;
Now click the “export CSS” button in the top right of the “SpriteMe” popover, copy &amp;amp; paste the css code it has given you ( that’s right ALL of it) directly into the bottom of your themes “style.css” or anywhere it is going to be used instead of the default code (as we don’t really want to overwrite the default theme code). You will need to ensure the second “background-image: url” is changed from “http://www.jaredhirsch.com” to where ever you saved the sprite image from earlier.&lt;br /&gt;
Once you have done this please once again “empty all caches” in the “Performance” sidebar tab.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 5: Optimize Those Images (compression)&lt;/h2&gt;For the most part i personally always use Photoshop to compress my images before uploading but for many of you this is not an option as you don’t have photoshop. So here i will assist you in how to decrease the file size of you images.&lt;br /&gt;
First off you will want to make sure any theme images are optimized and you can do this buy grabbing all of them and whacking them in this fantastic little app called “&lt;a href=&quot;http://imageoptim.pornel.net/&quot;&gt;ImageOptim&lt;/a&gt;“&lt;br /&gt;
Once your theme images are nice an compressed you may want to look at plugins such as “Smush.it” for WordPress that will optimize images you may use in posts and the like.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 6: GZIP-APPAGE!!!&lt;/h2&gt;This is most certainly a crucial optimization technique. To enable PHP GZIP compression, edit the php.ini (example locations such as in /etc/ or /usr/local/lib) with any text editor such as vi, and locate the following directive:  zlib.output_compression&lt;br /&gt;
The default value is Off, change the setting to On to make the line looks like below:&lt;br /&gt;
zlib.output_compression = On&lt;br /&gt;
Restart Apache HTTPD server after the change. Every web pages produced by PHP will now be compressed before sending over Internet to the web browser to decode.&lt;br /&gt;
PHP also has a directive which can be used to adjust the compression level. To set the compress level, use the following line in php.ini, with valid values between 1 and 9, where 1 is least compress and 9 is most compress. Default compression level is 6, which provides the best compression without degrading server performance.&lt;br /&gt;
zlib.output_compression_level = 6&lt;br /&gt;
Previously, PHP compression is achieved by entering &amp;lt;?php ob_start(“ob_gzhandler”); ?&amp;gt; code at the beginning of each PHP scripts. The method is not recommended as each and every scripts have to be changed. zlib enabling in php.ini will apply to all PHP scripts on the web server without exclusion.&lt;br /&gt;
If it’s impossible to modify php.ini file, or does not have control over php.ini especially on a shared hosting, the PHP GZIP compression can also be setup via .htaccess file, typically located on the root of the website. To enable PHP GZIP compression via Zlib, just add the following line to the .htaccessfile. Note that each website has to be changed individually.&lt;br /&gt;
php_flag zlib.output_compression on&lt;br /&gt;
The disadvantage of enabling GZIP compression via PHP is that only web pages generated by PHP scripts will be compressed by GZIP encoding. All external CSS or JavaScript files will not be compressed. For the ability to enable GZIP compression on all file types, uses mod_deflate or mod_gzip on HTTPD web server instead.&lt;br /&gt;
&lt;a href=&quot;http://www.mydigitallife.info/how-to-test-and-check-or-verify-gzip-page-compression-on-website/&quot;&gt;Do check and verify that GZIP compression is running properly&lt;/a&gt;&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 7: Tidbits&lt;/h2&gt;As we come towards the end of this tutorial i just want to run through a few last things. Now that your images have been crushed and sprites have been made you may want to clear both your browser cache and once more “empty all caches” in the “Performance” sidebar tab.&lt;br /&gt;
Now let’s head back, log out of WordPress load up your sites homepage and do a ySlow test. Again it should have risen, in the CDN section of ySlow you have the option to “Add as CDN” on some components. Doing this will boost your grade even further. &lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/167_ySlowTut/img/9.png&quot; /&gt;&lt;/div&gt;If you do want to properly add a dedicated CDN may i suggest you follow this &lt;a href=&quot;http://www.wpbeginner.com/wp-tutorials/increase-your-wordpress-blog-performance-by-using-google-app-engine/&quot;&gt;TUTORIAL&lt;/a&gt;.&lt;br /&gt;
Now Fingers crossed you should be looking at a grade A test score and if you compare this with Google’s own page speed report test you will see a very healthy score.&lt;br /&gt;
One section of ySlow that i haven’t covered is the “Cookie free domain” which is when the browser makes a request for a static image and sends cookies together with the request, the server doesn’t have any use for those cookies. So they only create network traffic for no good reason. You should make sure static components are requested with cookie-free requests. Create a subdomain and host all your static components there.&lt;br /&gt;
If your domain is www.example.org, you can host your static components onstatic.example.org. However, if you’ve already set cookies on the top-level domain example.org as opposed to www.example.org, then all the requests to static.example.org will include those cookies. In this case, you can buy a whole new domain, host your static components there, and keep this domain cookie-free. Yahoo! uses yimg.com, YouTube uses ytimg.com, Amazon uses images-amazon.com and so on.&lt;br /&gt;
Another benefit of hosting static components on a cookie-free domain is that some proxies might refuse to cache the components that are requested with cookies. On a related note, if you wonder if you should use example.org or www.example.org for your home page, consider the cookie impact. Omitting www leaves you no choice but to write cookies to *.example.org, so for performance reasons it’s best to use the www subdomain and write the cookies to that subdomain.&lt;br /&gt;
I won’t go into this but the above should give you a fair idea. I will go over this in depth in a later tutorial. This does improve the score but it’s not completely essential.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;These are the steps i take when building websites and they do a great deal of difference when it comes to improving the speed and allowing for fast response times. For those of you needing more info or that would like some help carrying out the procedures please comment below or send me a message via my &lt;a href=&quot;http://wp.tutsplus.com/author/matt/&quot;&gt;author profile.&lt;/a&gt;&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/1936908757915473349'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/1936908757915473349'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/02/ultimate-quickstart-guide-to-speeding.html' title='The Ultimate Quickstart Guide to Speeding Up Your WordPress Site'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-2801300741631875703</id><published>2012-02-07T10:20:00.001+08:00</published><updated>2012-02-07T10:21:05.620+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hierarchy"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress Themes"/><title type='text'>The WordPress Theme Files Execution Hierarchy</title><content type='html'>&quot;This article will show the WordPress theme file execution hierarchy. In short, we’ll look at which files get served up when you load a page in WordPress. You might already know that detail post is served by single.php and detail page is served by page.php, but WordPress will search for different files depending on a variety of factors, so we’ll be looking at how this works!&lt;br /&gt;
&lt;br /&gt;
First thing we should establish is this: without&lt;strong&gt; index.php&lt;/strong&gt; and &lt;strong&gt;style.css&lt;/strong&gt; your theme is no longer a valid WordPress theme… so it stands to reason that if all you have is those two files, each page will you try to load will be served up by index.php. Take a quick peek at this “cheatsheet” to see what I’m referring to:&lt;br /&gt;
&lt;div&gt;&lt;a href=&quot;http://wptutsplus.s3.amazonaws.com/090_WPCheatSheets/WP_CheatSheet_TemplateMap.jpg&quot;&gt;&lt;img src=&quot;http://wptutsplus.s3.amazonaws.com/090_WPCheatSheets/wordpress_cheat_sheet_template_map_preview.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Notice that the flow for each page types will end up with the &lt;strong&gt;index.php&lt;/strong&gt;. That is the reason why index.php is required file for the WordPress theme. If we are missing any other files in WordPress theme (for instance, if there is no “search.php” file included in the theme), then index.php will be served instead.&lt;br /&gt;
Now let’s look at some details about the execution order. I am going to show you the flow in which WordPress will search for files in your active theme folder. I hope this will be useful when you create a WordPress theme from now on:&lt;br /&gt;
I will go through each type of files one by one and will show the execution hierarchy for the same.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Home Page&lt;/h2&gt;This is the first and most important page of any website. So WordPress has provided the scope to customize the page. Let’s have a look at the file hierarchy for the home page.&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;front-page.php&lt;/li&gt;
&lt;li&gt;home.php&lt;/li&gt;
&lt;li&gt;index.php&lt;/li&gt;
&lt;/ol&gt;While serving the home page, WordPress will search for front-page.php. If that is not found, it will use home.php. If home.php exists, it’ll use that. If not, it will simply default to using index.php.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;WordPress Post Detail&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;single-&lt;strong&gt;[post-type]&lt;/strong&gt;.php &lt;/li&gt;
&lt;li&gt;single.php&lt;/li&gt;
&lt;li&gt;index.php&lt;/li&gt;
&lt;/ol&gt;WordPress can have as many post types as we need. So this will be easier to get different design for all/some post types. By default ‘post’ is the main and default post type of the WordPress.&lt;br /&gt;
So for example, if your custom post type is &lt;strong&gt;product&lt;/strong&gt; then it will be &lt;strong&gt;single-product.php&lt;/strong&gt;&lt;br /&gt;
To know more how to add new post types in WordPress you can refer to &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/register_post_type&quot;&gt;this link&lt;/a&gt;.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;WordPress Page Detail&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;strong&gt;[custom-template]&lt;/strong&gt;.php&lt;/li&gt;
&lt;li&gt;page-&lt;strong&gt;[slug]&lt;/strong&gt;.php&lt;/li&gt;
&lt;li&gt;page-&lt;strong&gt;[id]&lt;/strong&gt;.php&lt;/li&gt;
&lt;li&gt;page.php&lt;/li&gt;
&lt;li&gt;index.php&lt;/li&gt;
&lt;/ol&gt;&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/147_ThemeFilesExecutionHierarchy/wordpress_theme_file_hierarchy/custom_page_template.jpg&quot; /&gt;&lt;/div&gt;Just the same as with post types, we can have a different page layout using the custom page template. So WordPress first searches for the files of the selected Page template (if it exists).&lt;br /&gt;
If none are found, it will search for the file with the slug of the current page. Basically, if the slug is &lt;strong&gt;aboutus&lt;/strong&gt;, then it will search for the file &lt;strong&gt;page-aboutus.php&lt;/strong&gt; in active theme folder.&lt;br /&gt;
WordPress will search for the files with the ID just like searching for the files with slug.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Category Page&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;category-&lt;strong&gt;[slug]&lt;/strong&gt;.php&lt;/li&gt;
&lt;li&gt;category-&lt;strong&gt;[id]&lt;/strong&gt;.php&lt;/li&gt;
&lt;li&gt;category.php&lt;/li&gt;
&lt;li&gt;archive.php&lt;/li&gt;
&lt;li&gt;index.php&lt;/li&gt;
&lt;/ol&gt;From the above flow, you can understand that how you can have different templates used for the category page. For instance, you could have a custom page based on slug and id, and then use a default “category.php” file for the rest of your categories..&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Tag Page&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;tag-&lt;strong&gt;[slug]&lt;/strong&gt;.php&lt;/li&gt;
&lt;li&gt;tag-&lt;strong&gt;[id]&lt;/strong&gt;.php&lt;/li&gt;
&lt;li&gt;tag.php&lt;/li&gt;
&lt;li&gt;archive.php&lt;/li&gt;
&lt;li&gt;index.php&lt;/li&gt;
&lt;/ol&gt;This will be same case as the category. You can have different pages for tag slug and tag id also.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Taxonomy Page&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;taxonomy-&lt;strong&gt;[tax]-[term]&lt;/strong&gt;.php&lt;/li&gt;
&lt;li&gt;taxonomy-&lt;strong&gt;[tax]&lt;/strong&gt;.php&lt;/li&gt;
&lt;li&gt;taxonomy.php&lt;/li&gt;
&lt;li&gt;archive.php&lt;/li&gt;
&lt;li&gt;index.php&lt;/li&gt;
&lt;/ol&gt;Here goes the different file hierarchy for the taxonomy Pages.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Author Page&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;author-&lt;strong&gt;[author-nicname]&lt;/strong&gt;.php&lt;/li&gt;
&lt;li&gt;author-&lt;strong&gt;[author-id]&lt;/strong&gt;.php&lt;/li&gt;
&lt;li&gt;author.php&lt;/li&gt;
&lt;li&gt;archive.php&lt;/li&gt;
&lt;li&gt;index.php&lt;/li&gt;
&lt;/ol&gt;Here you come to know that you can have different designs based on users also. Same as category and tags we can have different files based on slug and ID of the user.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Attachment Page&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;strong&gt;[mime-type]&lt;/strong&gt;.php&lt;/li&gt;
&lt;li&gt;attachment.php&lt;/li&gt;
&lt;li&gt;single.php&lt;/li&gt;
&lt;li&gt;index.php&lt;/li&gt;
&lt;/ol&gt;Here you can see that you can have different page layout for different types of attachment. These can be differentiate from the mime type of the attached file.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Date Page&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;date.php&lt;/li&gt;
&lt;li&gt;archive.php&lt;/li&gt;
&lt;li&gt;index.php&lt;/li&gt;
&lt;/ol&gt;For the date specific layout we can create date.php in theme folder. Then the flow goes to archive.php and then at last index.php.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Archive Page&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;archive.php&lt;/li&gt;
&lt;li&gt;index.php&lt;/li&gt;
&lt;/ol&gt;As we come downwards to the type of files, number of files are reduced in the hierarchy. So this are the basic or we can say most used files in any WordPress themes.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Search Page&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;search.php&lt;/li&gt;
&lt;li&gt;index.php&lt;/li&gt;
&lt;/ol&gt;You can customize your search result with the search.php first. If search.php is not available then index.php will be served.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;404 Page&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;404.php&lt;/li&gt;
&lt;li&gt;index.php&lt;/li&gt;
&lt;/ol&gt;In the case of page or post not found, WordPress will search for 404.php then if not found then it will serve index.php.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;You can obviously use this information in a wide range of ways to load up custom templates for various pages… In many cases, even if you’re using an existing theme, you can get a custom solution without modifying the existing files. You will just need to create new file and give it a new name using the information above.&lt;br /&gt;
Share your thoughts and any additional file which can be included above hierarchy.&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/2801300741631875703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/2801300741631875703'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/02/wordpress-theme-files-execution.html' title='The WordPress Theme Files Execution Hierarchy'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-1758550233021264592</id><published>2012-02-07T10:17:00.001+08:00</published><updated>2012-02-07T10:18:15.612+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Comments"/><category scheme="http://www.blogger.com/atom/ns#" term="Facebook"/><category scheme="http://www.blogger.com/atom/ns#" term="Tips"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorial"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><title type='text'>The Ultimate Guide to Implementing Facebook Comments on your Blog</title><content type='html'>&quot;Using Facebook Comments on your blog offers your readers a way to instantaneously comment on posts, as well as to share them without having to do any work. If you think this type of commenting system will suit your audience, read on to find out how you can implement it &lt;strong&gt;the right way.&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 1: Create A Facebook App&lt;/h2&gt;Before you actually generate the Facebook Comments code and implement it on your blog, you need to create an app for your site. &lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Go to &lt;a href=&quot;http://developers.facebook.com/&quot;&gt;developers.facebook.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Apps&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Create New App&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Enter an &lt;strong&gt;App Display Name&lt;/strong&gt; and &lt;strong&gt;Namespace&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/166_FacebookComments/createnewapp.png&quot; /&gt;&lt;/div&gt;On the next screen, you’ll see your newly created app’s &lt;strong&gt;App ID&lt;/strong&gt; and &lt;strong&gt;App Secret Key&lt;/strong&gt;. You won’t need the secret key, but the App ID will be used later. Take note of it.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/166_FacebookComments/appkeys.png&quot; /&gt;&lt;/div&gt;Below these keys, go ahead and fill out the &lt;strong&gt;Contact Email&lt;/strong&gt; and &lt;strong&gt;App Domain&lt;/strong&gt; (your blog’s domain). Go down and click on &lt;strong&gt;Website&lt;/strong&gt;. Fill in the same domain that you used for the App Domain. Click &lt;strong&gt;Save Changes&lt;/strong&gt;.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 2: Insert the Facebook Comments Code into Your Theme&lt;/h2&gt;In this tutorial, we’ll be implementing Facebook Comments alongside the default WordPress comment system instead of replacing it. If you want, you can head over to the &lt;a href=&quot;http://developers.facebook.com/docs/reference/plugins/comments/&quot;&gt;Facebook Comments code generator&lt;/a&gt; to get the code you’ll need for inserting the comment system; however, I’ve included it here so you can just copy it. You’ll need to customize a few parts of it, however; I’ll note which parts those are for each block.&lt;br /&gt;
The code block below should be placed in your theme’s &lt;strong&gt;header.php&lt;/strong&gt; file. Find the opening &amp;lt;body&amp;gt; tag and paste the block directly below it. On the 6th line, replace “Your App ID Here” with your App ID.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;div id=&quot;fb-root&quot;&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;script&amp;gt;(function(d, s, id) {
 var js, fjs = d.getElementsByTagName(s)[0];
 if (d.getElementById(id)) return;
 js = d.createElement(s); js.id = id;
 js.src = &quot;//connect.facebook.net/en_US/all.js#xfbml=1&amp;amp;appId=Your App ID Here&quot;;
 fjs.parentNode.insertBefore(js, fjs);
}(document, &#39;script&#39;, &#39;facebook-jssdk&#39;));&amp;lt;/script&amp;gt;
&lt;/pre&gt;While you’re still in your &lt;strong&gt;header.php&lt;/strong&gt; file, go up into the &amp;lt;head&amp;gt; section and paste this block of code somewhere. It will ensure that the Facebook Commenting system on your blog posts knows it’s owned by the app you created before. Replace the “Your App ID Here” bit with your App ID (leave the quotes in place).&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;meta property=&quot;fb:app_id&quot; content=&quot;Your App ID Here&quot;/&amp;gt;
&lt;/pre&gt;The next code block should be placed in your theme’s &lt;strong&gt;comments.php&lt;/strong&gt; file. Since we’re implementing Facebook Comments &lt;em&gt;alongside&lt;/em&gt; WordPress comments, you’ll just be pasting it where you want the Facebook Comments box to appear, and you won’t be deleting any of the original code.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;div class=&quot;fb-comments&quot; data-href=&quot;&amp;lt;?php the_permalink() ?&amp;gt;&quot; data-num-posts=&quot;2&quot; data-width=&quot;470&quot; data-colorscheme=&quot;light&quot; data-mobile=&quot;false&quot;&amp;gt;&amp;lt;/div&amp;gt;
&lt;/pre&gt;If you generate your Facebook Comments code from the link I gave you earlier, instead of just grabbing it from this tutorial, remember to change the &lt;em&gt;data-href&lt;/em&gt; attribute from the original URL to &amp;lt;?php the_permalink() ?&amp;gt;, otherwise Facebook Comments won’t work.&lt;br /&gt;
You can also edit the &lt;em&gt;data-num-posts&lt;/em&gt;, &lt;em&gt;data-width&lt;/em&gt;, and &lt;em&gt;data-colorscheme&lt;/em&gt; attributes to your liking. The first defines how many comments will be shown on each post before a user needs to click “See More”, the second defines the width of the commenting system (set it to something slightly smaller than your content area’s width), and the last is the color scheme, which can be set to “light” or “dark”.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 3: Display the Combined Facebook and WordPress Comment Count&lt;/h2&gt;Your theme most likely has several areas where it will show the number of comments there are on a post. By default, it will only show the number of WordPress comments. Since you’re implementing Facebook Comments alongside WordPress comments now, you’ll want to display the sum of the comments from both systems on each post.&lt;br /&gt;
To do this, first open up your theme’s &lt;strong&gt;functions.php&lt;/strong&gt; file. Paste the code shown below at the bottom of the file and save it.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;// Get combined FB and WordPress comment count
function full_comment_count() {
global $post;
$url = get_permalink($post-&amp;gt;ID);

$filecontent = file_get_contents(&#39;https://graph.facebook.com/?ids=&#39; . $url);
$json = json_decode($filecontent);
$count = $json-&amp;gt;$url-&amp;gt;comments;
$wpCount = get_comments_number();
$realCount = $count + $wpCount;
if ($realCount == 0 || !isset($realCount)) {
   $realCount = 0;
}
return $realCount;
}
&lt;/pre&gt;&lt;blockquote&gt;&lt;strong&gt;Note&lt;/strong&gt;: This code was built off of a function written by Viceprez on the &lt;a href=&quot;http://wordpress.stackexchange.com/questions/18603/facebook-comment-count&quot;&gt;WordPress Stack Exchange&lt;/a&gt;. I’ve simply added a couple of lines to his original function that add in the WordPress comment count. Thanks Viceprez!&lt;/blockquote&gt;Now that you have the function added to your theme, you can use it to replace the original comment count functions used throughout your theme. In my theme, the comments are called using this code:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php comments_popup_link(&#39;0&#39;,&#39;1&#39;,&#39;%&#39;); ?&amp;gt;
&lt;/pre&gt;Your theme may use this function to display the comment count, or it may not. Once you’ve found whatever &lt;strong&gt;does&lt;/strong&gt; display it, replace it with this code:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php echo full_comment_count(); ?&amp;gt;
&lt;/pre&gt;There will likely be several places within your theme that you’ll need to insert this code. Here’s a list of the most common ones:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;The &lt;strong&gt;comments.php&lt;/strong&gt; file&lt;/li&gt;
&lt;li&gt;Near the top of your &lt;strong&gt;single.php&lt;/strong&gt; file&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;index.php&lt;/strong&gt; – it’ll be located in the loop that calls each post&lt;/li&gt;
&lt;li&gt;Any archive files like &lt;strong&gt;archive.php&lt;/strong&gt;, &lt;strong&gt;category.php&lt;/strong&gt;, &lt;strong&gt;author.php&lt;/strong&gt;, etc. In this, it’ll be located in the loop that calls each post as well.&lt;/li&gt;
&lt;li&gt;On &lt;strong&gt;search.php&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;On &lt;strong&gt;page.php&lt;/strong&gt; if you allow comments on pages&lt;/li&gt;
&lt;/ul&gt;If the comment count in your &lt;strong&gt;comments.php&lt;/strong&gt; is diplayed as a sentence, instead of just a number, you can use the code below instead of the one line function call in order to allow for words like “no comments” and “one comment”. I’ve customized mine to be more inviting – I’d recommend that you do the same instead of being generic &lt;img alt=&quot;:)&quot; src=&quot;http://wp.tutsplus.com/wp-includes/images/smilies/icon_smile.gif&quot; /&gt; &lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php
 $commentCount = full_comment_count();
 if ( $commentCount == 0 ) {
  echo &#39;&amp;lt;h5&amp;gt;No comments yet - you should start the discussion!&amp;lt;/h5&amp;gt;&#39;;
 }
 else if ( $commentCount == 1 ) {
  echo &#39;&amp;lt;h5&amp;gt;One comment so far - add yours!&amp;lt;/h5&amp;gt;&#39;;
 }
 else {
  echo &#39;&amp;lt;h5&amp;gt;&#39; . $commentCount . &#39; comments so far - add yours!&amp;lt;/h5&amp;gt;&#39;;
 }
?&amp;gt;
&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Step 4: Get Immediate Notifications of New Comments&lt;/h2&gt;The last part of the tutorial will show you how to get Facebook Notifications whenever someone comments on your blog.&lt;br /&gt;
First, you’ll need to access your comments moderation panel. You can do that by pasting the following URL into your browser, substituting “Your App ID Here” with your App ID. &lt;em&gt;You might also want to add this page to your bookmarks once you’re at it.&lt;/em&gt;&lt;br /&gt;
https://developers.facebook.com/tools/comments/?id=Your App ID Here&lt;br /&gt;
Once you’re at your comments moderation panel, hit the &lt;strong&gt;Settings&lt;/strong&gt; button in the top right corner. A window will come up, and you should see a &lt;strong&gt;Moderators&lt;/strong&gt; field in the middle of it. Simply add yourself as a moderator, and you’ll start getting notications whenever someone comments on a blog post.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/166_FacebookComments/commentoptions.png&quot; /&gt;&lt;/div&gt;&lt;hr /&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;If you’ve followed all the steps in this tutorial, your blog should now have Facebook Comments implemented right alongside the default WordPress comment system. I believe this is an ideal setup, as it gives your readers the best of both worlds; Facebook Comments is probably the most convenient commenting system out there, if a reader is signed in to Facebook (they most likely are), then there’s absolutely no authentication or identification fields to fill out. They can just comment away. However, if a reader doesn’t want to use Facebook, or wants to add their link or get CommentLuv benefits, you can still let them use WordPress comments.&lt;br /&gt;
You also now have a comment count for each post that shows the sum of the comments from each system, and since you’re a moderator for your app, you’ll get immediate notifications of new comments. I hope you enjoy your new and improved commenting solution!&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/1758550233021264592'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/1758550233021264592'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/02/ultimate-guide-to-implementing-facebook.html' title='The Ultimate Guide to Implementing Facebook Comments on your Blog'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-7845479104186815890</id><published>2012-02-07T10:11:00.002+08:00</published><updated>2012-02-07T10:14:16.709+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Filterable Portfolio"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="Tips"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorial"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><title type='text'>Creating a Filterable Portfolio with WordPress and jQuery</title><content type='html'>&quot;Learn in this tutorial how to make a filterable Portfolio with jQuery integrated with WordPress, remember that this portfolio kind can make a big difference on your themes!&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 1: Introduction&lt;/h2&gt;You can use the code from this tutorial in any theme that you’ve created or are creating, we’ll follow simple steps and in my case, I’ll use the default &lt;strong&gt;Twenty Eleven&lt;/strong&gt; theme and running on &lt;strong&gt;WordPress 3.3&lt;/strong&gt;. Okay, let’s work!&lt;br /&gt;
&lt;blockquote&gt;You can use the code used in this tutorial in any theme that you’ve created or are creating.&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt;Step 2: Creating the Project Item on Admin&lt;/h2&gt;We’ll need to create a section on Admin bar called &lt;strong&gt;Project&lt;/strong&gt;, in this section you’ll create all the portfolio entries with their respective &lt;em&gt;thumbnail&lt;/em&gt; and &lt;em&gt;demo link&lt;/em&gt;.&lt;br /&gt;
Open the &lt;strong&gt;functions.php&lt;/strong&gt; file and at the end, let’s create a function to register the Project item. &lt;strong&gt;(You can see the complete function at the end of this step)&lt;/strong&gt;&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;add_action(&#39;init&#39;, &#39;project_custom_init&#39;);   

/* SECTION - project_custom_init */
function project_custom_init()
{
 // the remainder code goes here
}
/* #end SECTION - project_custom_init --*/
&lt;/pre&gt;In this code we are using the &lt;strong&gt;add_action&lt;/strong&gt; function so that when WordPress begins to load our function will be called.&lt;br /&gt;
&lt;strong&gt;Inside the project_custom_init function&lt;/strong&gt; lets add the code that registers a &lt;strong&gt;Custom Post Type&lt;/strong&gt; called &lt;em&gt;Project&lt;/em&gt;.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;// The following is all the names, in our tutorial, we use &quot;Project&quot;
 $labels = array(
  &#39;name&#39; =&amp;gt; _x(&#39;Projects&#39;, &#39;post type general name&#39;),
  &#39;singular_name&#39; =&amp;gt; _x(&#39;Project&#39;, &#39;post type singular name&#39;),
  &#39;add_new&#39; =&amp;gt; _x(&#39;Add New&#39;, &#39;project&#39;),
  &#39;add_new_item&#39; =&amp;gt; __(&#39;Add New Project&#39;),
  &#39;edit_item&#39; =&amp;gt; __(&#39;Edit Project&#39;),
  &#39;new_item&#39; =&amp;gt; __(&#39;New Project&#39;),
  &#39;view_item&#39; =&amp;gt; __(&#39;View Project&#39;),
  &#39;search_items&#39; =&amp;gt; __(&#39;Search Projects&#39;),
  &#39;not_found&#39; =&amp;gt;  __(&#39;No projects found&#39;),
  &#39;not_found_in_trash&#39; =&amp;gt; __(&#39;No projects found in Trash&#39;),
  &#39;parent_item_colon&#39; =&amp;gt; &#39;&#39;,
  &#39;menu_name&#39; =&amp;gt; &#39;Portfolio&#39;
 );

 // Some arguments and in the last line &#39;supports&#39;, we say to WordPress what features are supported on the Project post type
 $args = array(
  &#39;labels&#39; =&amp;gt; $labels,
  &#39;public&#39; =&amp;gt; true,
  &#39;publicly_queryable&#39; =&amp;gt; true,
  &#39;show_ui&#39; =&amp;gt; true,
  &#39;show_in_menu&#39; =&amp;gt; true,
  &#39;query_var&#39; =&amp;gt; true,
  &#39;rewrite&#39; =&amp;gt; true,
  &#39;capability_type&#39; =&amp;gt; &#39;post&#39;,
  &#39;has_archive&#39; =&amp;gt; true,
  &#39;hierarchical&#39; =&amp;gt; false,
  &#39;menu_position&#39; =&amp;gt; null,
  &#39;supports&#39; =&amp;gt; array(&#39;title&#39;,&#39;editor&#39;,&#39;author&#39;,&#39;thumbnail&#39;,&#39;excerpt&#39;,&#39;comments&#39;)
 );

 // We call this function to register the custom post type
 register_post_type(&#39;project&#39;,$args);
&lt;/pre&gt;The code above will add an item on the Admin menu called &lt;strong&gt;Portfolio&lt;/strong&gt; and it will be in this section that we’ll create all the portfolio items.&lt;br /&gt;
&lt;strong&gt;Now, inside the function, let’s add more code.&lt;/strong&gt;&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;// Initialize Taxonomy Labels
 $labels = array(
  &#39;name&#39; =&amp;gt; _x( &#39;Tags&#39;, &#39;taxonomy general name&#39; ),
  &#39;singular_name&#39; =&amp;gt; _x( &#39;Tag&#39;, &#39;taxonomy singular name&#39; ),
  &#39;search_items&#39; =&amp;gt;  __( &#39;Search Types&#39; ),
  &#39;all_items&#39; =&amp;gt; __( &#39;All Tags&#39; ),
  &#39;parent_item&#39; =&amp;gt; __( &#39;Parent Tag&#39; ),
  &#39;parent_item_colon&#39; =&amp;gt; __( &#39;Parent Tag:&#39; ),
  &#39;edit_item&#39; =&amp;gt; __( &#39;Edit Tags&#39; ),
  &#39;update_item&#39; =&amp;gt; __( &#39;Update Tag&#39; ),
  &#39;add_new_item&#39; =&amp;gt; __( &#39;Add New Tag&#39; ),
  &#39;new_item_name&#39; =&amp;gt; __( &#39;New Tag Name&#39; ),
 );

 // Register Custom Taxonomy
 register_taxonomy(&#39;tagportfolio&#39;,array(&#39;project&#39;), array(
  &#39;hierarchical&#39; =&amp;gt; true, // define whether to use a system like tags or categories
  &#39;labels&#39; =&amp;gt; $labels,
  &#39;show_ui&#39; =&amp;gt; true,
  &#39;query_var&#39; =&amp;gt; true,
  &#39;rewrite&#39; =&amp;gt; array( &#39;slug&#39; =&amp;gt; &#39;tag-portfolio&#39; ),
 ));
&lt;/pre&gt;Attention to the ‘hierarchical’ argument on the &lt;em&gt;register_taxonomy&lt;/em&gt; function, if you type &lt;strong&gt;true&lt;/strong&gt; you will have a system like categories for your portfolio items, but if you type &lt;strong&gt;false&lt;/strong&gt; you will have a system like tags. I prefer the category style system.&lt;br /&gt;
Oh yeah! The &lt;strong&gt;project_custom_init() function&lt;/strong&gt; is finished! See below for the full code of this function.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;add_action(&#39;init&#39;, &#39;project_custom_init&#39;); 

 /*-- Custom Post Init Begin --*/
 function project_custom_init()
 {
   $labels = array(
  &#39;name&#39; =&amp;gt; _x(&#39;Projects&#39;, &#39;post type general name&#39;),
  &#39;singular_name&#39; =&amp;gt; _x(&#39;Project&#39;, &#39;post type singular name&#39;),
  &#39;add_new&#39; =&amp;gt; _x(&#39;Add New&#39;, &#39;project&#39;),
  &#39;add_new_item&#39; =&amp;gt; __(&#39;Add New Project&#39;),
  &#39;edit_item&#39; =&amp;gt; __(&#39;Edit Project&#39;),
  &#39;new_item&#39; =&amp;gt; __(&#39;New Project&#39;),
  &#39;view_item&#39; =&amp;gt; __(&#39;View Project&#39;),
  &#39;search_items&#39; =&amp;gt; __(&#39;Search Projects&#39;),
  &#39;not_found&#39; =&amp;gt;  __(&#39;No projects found&#39;),
  &#39;not_found_in_trash&#39; =&amp;gt; __(&#39;No projects found in Trash&#39;),
  &#39;parent_item_colon&#39; =&amp;gt; &#39;&#39;,
  &#39;menu_name&#39; =&amp;gt; &#39;Project&#39;

   );

  $args = array(
  &#39;labels&#39; =&amp;gt; $labels,
  &#39;public&#39; =&amp;gt; true,
  &#39;publicly_queryable&#39; =&amp;gt; true,
  &#39;show_ui&#39; =&amp;gt; true,
  &#39;show_in_menu&#39; =&amp;gt; true,
  &#39;query_var&#39; =&amp;gt; true,
  &#39;rewrite&#39; =&amp;gt; true,
  &#39;capability_type&#39; =&amp;gt; &#39;post&#39;,
  &#39;has_archive&#39; =&amp;gt; true,
  &#39;hierarchical&#39; =&amp;gt; false,
  &#39;menu_position&#39; =&amp;gt; null,
  &#39;supports&#39; =&amp;gt; array(&#39;title&#39;,&#39;editor&#39;,&#39;author&#39;,&#39;thumbnail&#39;,&#39;excerpt&#39;,&#39;comments&#39;)
   );
   // The following is the main step where we register the post.
   register_post_type(&#39;project&#39;,$args);

   // Initialize New Taxonomy Labels
   $labels = array(
  &#39;name&#39; =&amp;gt; _x( &#39;Tags&#39;, &#39;taxonomy general name&#39; ),
  &#39;singular_name&#39; =&amp;gt; _x( &#39;Tag&#39;, &#39;taxonomy singular name&#39; ),
  &#39;search_items&#39; =&amp;gt;  __( &#39;Search Types&#39; ),
  &#39;all_items&#39; =&amp;gt; __( &#39;All Tags&#39; ),
  &#39;parent_item&#39; =&amp;gt; __( &#39;Parent Tag&#39; ),
  &#39;parent_item_colon&#39; =&amp;gt; __( &#39;Parent Tag:&#39; ),
  &#39;edit_item&#39; =&amp;gt; __( &#39;Edit Tags&#39; ),
  &#39;update_item&#39; =&amp;gt; __( &#39;Update Tag&#39; ),
  &#39;add_new_item&#39; =&amp;gt; __( &#39;Add New Tag&#39; ),
  &#39;new_item_name&#39; =&amp;gt; __( &#39;New Tag Name&#39; ),
   );
  // Custom taxonomy for Project Tags
  register_taxonomy(&#39;tagportfolio&#39;,array(&#39;project&#39;), array(
  &#39;hierarchical&#39; =&amp;gt; true,
  &#39;labels&#39; =&amp;gt; $labels,
  &#39;show_ui&#39; =&amp;gt; true,
  &#39;query_var&#39; =&amp;gt; true,
  &#39;rewrite&#39; =&amp;gt; array( &#39;slug&#39; =&amp;gt; &#39;tag-portfolio&#39; ),
   ));

 }
 /*-- Custom Post Init Ends --*/
&lt;/pre&gt;If you go to the Admin now, you will see a new item on menu called &lt;strong&gt;Portfolio&lt;/strong&gt; like the image below:&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/178_Creating_a_Filterable_Portfolio_with_WordPress_and_jQuery/admin_menu.png&quot; /&gt;&lt;/div&gt;Let’s create a new function that will ensure nice messages are shown when the user, for example, creates a new item on portfolio or something like this.&lt;br /&gt;
The code below must be typed below our last function and &lt;strong&gt;not inside it&lt;/strong&gt;.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;/*--- Custom Messages - project_updated_messages ---*/
 add_filter(&#39;post_updated_messages&#39;, &#39;project_updated_messages&#39;);

 function project_updated_messages( $messages ) {
   global $post, $post_ID;

   $messages[&#39;project&#39;] = array(
  0 =&amp;gt; &#39;&#39;, // Unused. Messages start at index 1.
  1 =&amp;gt; sprintf( __(&#39;Project updated. &amp;lt;a href=&quot;%s&quot;&amp;gt;View project&amp;lt;/a&amp;gt;&#39;), esc_url( get_permalink($post_ID) ) ),
  2 =&amp;gt; __(&#39;Custom field updated.&#39;),
  3 =&amp;gt; __(&#39;Custom field deleted.&#39;),
  4 =&amp;gt; __(&#39;Project updated.&#39;),
  /* translators: %s: date and time of the revision */
  5 =&amp;gt; isset($_GET[&#39;revision&#39;]) ? sprintf( __(&#39;Project restored to revision from %s&#39;), wp_post_revision_title( (int) $_GET[&#39;revision&#39;], false ) ) : false,
  6 =&amp;gt; sprintf( __(&#39;Project published. &amp;lt;a href=&quot;%s&quot;&amp;gt;View project&amp;lt;/a&amp;gt;&#39;), esc_url( get_permalink($post_ID) ) ),
  7 =&amp;gt; __(&#39;Project saved.&#39;),
  8 =&amp;gt; sprintf( __(&#39;Project submitted. &amp;lt;a target=&quot;_blank&quot; href=&quot;%s&quot;&amp;gt;Preview project&amp;lt;/a&amp;gt;&#39;), esc_url( add_query_arg( &#39;preview&#39;, &#39;true&#39;, get_permalink($post_ID) ) ) ),
  9 =&amp;gt; sprintf( __(&#39;Project scheduled for: &amp;lt;strong&amp;gt;%1$s&amp;lt;/strong&amp;gt;. &amp;lt;a target=&quot;_blank&quot; href=&quot;%2$s&quot;&amp;gt;Preview project&amp;lt;/a&amp;gt;&#39;),
    // translators: Publish box date format, see http://php.net/date
    date_i18n( __( &#39;M j, Y @ G:i&#39; ), strtotime( $post-&amp;gt;post_date ) ), esc_url( get_permalink($post_ID) ) ),
  10 =&amp;gt; sprintf( __(&#39;Project draft updated. &amp;lt;a target=&quot;_blank&quot; href=&quot;%s&quot;&amp;gt;Preview project&amp;lt;/a&amp;gt;&#39;), esc_url( add_query_arg( &#39;preview&#39;, &#39;true&#39;, get_permalink($post_ID) ) ) ),
   );

   return $messages;
 }

 /*--- #end SECTION - project_updated_messages ---*/
&lt;/pre&gt;This function creates custom messages for when a user modifies the portfolio post, see a message example on image below:&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/178_Creating_a_Filterable_Portfolio_with_WordPress_and_jQuery/custom_message.png&quot; /&gt;&lt;/div&gt;You can see that with only this code you can add tags/categories to your portfolio and create new portfolio items! But let’s add more one feature, good idea? Sure!&lt;br /&gt;
&lt;h3&gt;Adding a Demo URL Meta Box&lt;/h3&gt;In this step, we’ll add a meta box on the portfolio item creation screen where the user can paste a &lt;strong&gt;url to the website or other page&lt;/strong&gt;.&lt;br /&gt;
Let’s create three functions to add this meta box where we will save our URL for the portfolio item. The code goes below the last function that we’ve created.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;/*--- Demo URL meta box ---*/

 add_action(&#39;admin_init&#39;,&#39;portfolio_meta_init&#39;);

 function portfolio_meta_init()
 {
  // add a meta box for WordPress &#39;project&#39; type
  add_meta_box(&#39;portfolio_meta&#39;, &#39;Project Infos&#39;, &#39;portfolio_meta_setup&#39;, &#39;project&#39;, &#39;side&#39;, &#39;low&#39;);

  // add a callback function to save any data a user enters in
  add_action(&#39;save_post&#39;,&#39;portfolio_meta_save&#39;);
 }

 function portfolio_meta_setup()
 {
  global $post;

  ?&amp;gt;
   &amp;lt;div class=&quot;portfolio_meta_control&quot;&amp;gt;
    &amp;lt;label&amp;gt;URL&amp;lt;/label&amp;gt;
    &amp;lt;p&amp;gt;
     &amp;lt;input type=&quot;text&quot; name=&quot;_url&quot; value=&quot;&amp;lt;?php echo get_post_meta($post-&amp;gt;ID,&#39;_url&#39;,TRUE); ?&amp;gt;&quot; style=&quot;width: 100%;&quot; /&amp;gt;
    &amp;lt;/p&amp;gt;
   &amp;lt;/div&amp;gt;
  &amp;lt;?php

  // create for validation
  echo &#39;&amp;lt;input type=&quot;hidden&quot; name=&quot;meta_noncename&quot; value=&quot;&#39; . wp_create_nonce(__FILE__) . &#39;&quot; /&amp;gt;&#39;;
 }

 function portfolio_meta_save($post_id)
 {
  // check nonce
  if (!isset($_POST[&#39;meta_noncename&#39;]) || !wp_verify_nonce($_POST[&#39;meta_noncename&#39;], __FILE__)) {
  return $post_id;
  }

  // check capabilities
  if (&#39;post&#39; == $_POST[&#39;post_type&#39;]) {
  if (!current_user_can(&#39;edit_post&#39;, $post_id)) {
  return $post_id;
  }
  } elseif (!current_user_can(&#39;edit_page&#39;, $post_id)) {
  return $post_id;
  }

  // exit on autosave
  if (defined(&#39;DOING_AUTOSAVE&#39;) == DOING_AUTOSAVE) {
  return $post_id;
  }

  if(isset($_POST[&#39;_url&#39;]))
  {
   update_post_meta($post_id, &#39;_url&#39;, $_POST[&#39;_url&#39;]);
  } else
  {
   delete_post_meta($post_id, &#39;_url&#39;);
  }
 }

 /*--- #end  Demo URL meta box ---*/
&lt;/pre&gt;I won’t explain in details this code because you can learn about meta boxes in this tutorial: &lt;a href=&quot;http://wp.tutsplus.com/tutorials/reusable-custom-meta-boxes-part-1-intro-and-basic-fields/&quot;&gt;Reusable Custom Meta Boxes&lt;/a&gt; or just do a little search through the &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/add_meta_box&quot;&gt;WordPress Codex&lt;/a&gt; or on Google.&lt;br /&gt;
The code above just creates one meta box with one field where the user can type a URL. We need all these functions, the first just initializes the meta box, the second is the meta box code, and the last is a function to save the data.&lt;br /&gt;
Ok! After this, we can go on to next step and work on the front-end, because the back-end is done! We’ll then add the content after.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 3: Creating the Portfolio Page template&lt;/h2&gt;Now we’ll work to show our portfolio entries to the user! But first let’s create some categories and then add some items to the portfolio.&lt;br /&gt;
&lt;strong&gt;In this tutorial I’ll use a two column portfolio layout, with some adjustments on markup and CSS you can create a lots of layouts!&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;A few tips to create a portfolio item&lt;/strong&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Create the tags/categories first&lt;/li&gt;
&lt;li&gt;In the “Add New Project” page you’ll have an editor like the post/page editor, then just type all the text and images that your user will see when they click on the “More Details” link&lt;/li&gt;
&lt;li&gt;To add &lt;em&gt;thumbnails&lt;/em&gt; we’ll use the &lt;strong&gt;Featured Image&lt;/strong&gt; that is a default WordPress feature&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;In this tutorial I’ll use images with 400px x 160px (width and height), but feel free to use one that you like and that fits in your layout&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Use http:// before the links on the meta box so you don’t get a 404 not found error&lt;/li&gt;
&lt;/ul&gt;Ok, the first thing that we’ll need to do now is create a new &lt;em&gt;Page Template&lt;/em&gt; called “Portfolio 2 Columns”, so let’s go!&lt;br /&gt;
&lt;h3&gt;Creating the Page Template&lt;/h3&gt;First, duplicate the &lt;strong&gt;page.php&lt;/strong&gt; file. Then, rename it to &lt;strong&gt;page_portfolio_2c.php&lt;/strong&gt;.&lt;br /&gt;
We need to edit this new file and paste the code below on the file’s first line: &lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php
/*
Template Name: Portfolio 2 Columns
*/
?&amp;gt;
&lt;/pre&gt;This will show a new option on the page creation screen, but remember that &lt;strong&gt;this code MUST be pasted on the file’s first line!&lt;/strong&gt;&lt;br /&gt;
Now just erase all the content inside content div, in this tutorial, I’m using the &lt;em&gt;Twenty Eleven&lt;/em&gt; theme and after erasing, I have this code in my file:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php
/*
Template Name: Portfolio 2 Columns
*/
?&amp;gt;

&amp;lt;?php
get_header(); ?&amp;gt;

  &amp;lt;div id=&quot;primary&quot;&amp;gt;
   &amp;lt;div id=&quot;content&quot; role=&quot;main&quot;&amp;gt;

    &amp;lt;?php // I removed all the lines here ?&amp;gt;

   &amp;lt;/div&amp;gt;&amp;lt;!-- #content --&amp;gt;
  &amp;lt;/div&amp;gt;&amp;lt;!-- #primary --&amp;gt;

&amp;lt;?php get_footer(); ?&amp;gt;
&lt;/pre&gt;If you are using your own theme, then erase all the lines that get content from your page, like the_content() for example. We’ll create some custom code, so don’t leave other code here, in the portfolio page we just need your projects!&lt;br /&gt;
Now, go to WordPress Admin and create a new Page called “Portfolio” and don’t forget to select “Portfolio 2 Columns” in the Template field, like the image below.&lt;br /&gt;
&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/178_Creating_a_Filterable_Portfolio_with_WordPress_and_jQuery/portfolio_page.png&quot; /&gt;&lt;/div&gt;Just add a title and leave the content blank, we don’t need it.&lt;br /&gt;
If you try to access the page now you’ll get only the header, footer and blank content. So, let’s add life to our filterable portfolio!&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 4:The jQuery Filterable Portfolio&lt;/h2&gt;Let’s talk a little about the plugin that we’ll use to make the portfolio.&lt;br /&gt;
&lt;h3&gt;The plugin&lt;/h3&gt;In this tutorial I’ll make use of a plugin called Filterable, this plugin was created by &lt;a href=&quot;http://www.gethifi.com/blog/a-jquery-plugin-to-create-an-interactive-filterable-portfolio-like-ours&quot;&gt;GetHifi&lt;/a&gt;.&lt;br /&gt;
This plugin was written without jQuery’s compatibility mode, so I just changed it and the version that works fine with WordPress is in the Source Code file for this tutorial.&lt;br /&gt;
The plugin is a little old, to be more exact, it’s from 2009, but it’s on &lt;strong&gt;MIT License&lt;/strong&gt;, so you can use on premium themes, commercial sites and wherever you like.&lt;br /&gt;
&lt;strong&gt;Just download the modified script that is on Source Code (link on tutorial top) and let’s begin! If you like, visit the homepage to get more details about it.&lt;/strong&gt;&lt;br /&gt;
&lt;h3&gt;How Filterable works&lt;/h3&gt;Using Filterable is very simple! The first step is use the right markup, the plugin expects markup like the example below:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;ul id=&quot;portfolio-filter&quot;&amp;gt;
  &amp;lt;li&amp;gt;&amp;lt;a href=&quot;#all&quot;&amp;gt;All&amp;lt;/a&amp;gt;
  &amp;lt;li&amp;gt;&amp;lt;a rel=&quot;jquery&quot; href=&quot;#jquery&quot;&amp;gt;jQuery&amp;lt;/a&amp;gt;
  &amp;lt;li&amp;gt;&amp;lt;a rel=&quot;webdesign&quot; href=&quot;#webdesign&quot;&amp;gt;Webdesign&amp;lt;/a&amp;gt;
 &amp;lt;/ul&amp;gt;
&lt;/pre&gt;Here we have the filter items, when we click on one of these links, then all the magic will happen. &lt;strong&gt;Important: all the entries will need a class with the same text in the ‘href’ and ‘rel’ attributes.&lt;/strong&gt;&lt;br /&gt;
And now, we have the portfolio items markup:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;div id=&quot;portfolio-wrapper&quot;&amp;gt;
  &amp;lt;ul id=&quot;portfolio-list&quot;&amp;gt;

   &amp;lt;li class=&quot;portfolio-item all webdesign&quot;&amp;gt;
    &amp;lt;!-- ALL CUSTOM MARKUP HERE --&amp;gt;
   &amp;lt;/li&amp;gt;

   &amp;lt;li class=&quot;portfolio-item all jquery&quot;&amp;gt;
    &amp;lt;!-- ALL CUSTOM MARKUP HERE --&amp;gt;
   &amp;lt;/li&amp;gt;

  &amp;lt;/ul&amp;gt;
  &amp;lt;div class=&quot;clearboth&quot;&amp;gt;&amp;lt;/div&amp;gt;
 &amp;lt;/div&amp;gt;
&lt;/pre&gt;&lt;strong&gt;Important:&lt;/strong&gt; What really matters here is that all the items (li) must be inside a (ul), in other words, must be wrapped. Note that we use a &lt;em&gt;div&lt;/em&gt; too, we use it because we’ll ‘float’ the &lt;em&gt;li&lt;/em&gt; elements, so it is important to have another wrapper and a &lt;em&gt;clear div&lt;/em&gt; to avoid structure breaking problems.&lt;br /&gt;
After this, we’ll need to call the &lt;em&gt;filterable&lt;/em&gt; script in our functions.php file and initialize the filterable portfolio by calling the &lt;em&gt;filterable()&lt;/em&gt; function, like the code below:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;script&amp;gt;
  jQuery(document).ready(function() {
   jQuery(&quot;#portfolio-list&quot;).filterable();
  });
 &amp;lt;/script&amp;gt;
&lt;/pre&gt;But for now, we’ll add our custom markup inside the &lt;em&gt;li&lt;/em&gt;, but, we’ll need to generate all the filters and class names with PHP to get all the categories, portfolio entries and all the other details from WordPress! Let’s work!&lt;br /&gt;
&lt;h3&gt;Creating the Portfolio Filter&lt;/h3&gt;Let’s back to the &lt;strong&gt;page_portfolio_2c.php&lt;/strong&gt; file and write the portfolio filter. The code actually is something like the code below:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php
/*
Template Name: Portfolio 2 Columns
*/
?&amp;gt;

&amp;lt;?php
get_header(); ?&amp;gt;

  &amp;lt;div id=&quot;primary&quot;&amp;gt;
   &amp;lt;div id=&quot;content&quot; role=&quot;main&quot;&amp;gt;

    &amp;lt;!-- WE&#39;LL ADD OUR CODE HERE, INSIDE CONTENT DIV --&amp;gt;

   &amp;lt;/div&amp;gt;&amp;lt;!-- #content --&amp;gt;
  &amp;lt;/div&amp;gt;&amp;lt;!-- #primary --&amp;gt;

&amp;lt;?php get_footer(); ?&amp;gt;
&lt;/pre&gt;We need get all the terms/categories from WordPress, edit some names to use inside the class attribute and print a &lt;em&gt;ul&lt;/em&gt; for the required template.&lt;br /&gt;
We’ll type the following code inside the &lt;em&gt;#content div&lt;/em&gt;:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php
  $terms = get_terms(&quot;tagportfolio&quot;);
  $count = count($terms);
  echo &#39;&amp;lt;ul id=&quot;portfolio-filter&quot;&amp;gt;&#39;;
  echo &#39;&amp;lt;li&amp;gt;&amp;lt;a href=&quot;#all&quot; title=&quot;&quot;&amp;gt;All&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&#39;;
   if ( $count &amp;gt; 0 )
   {
    foreach ( $terms as $term ) {
     $termname = strtolower($term-&amp;gt;name);
     $termname = str_replace(&#39; &#39;, &#39;-&#39;, $termname);
     echo &#39;&amp;lt;li&amp;gt;&amp;lt;a href=&quot;#&#39;.$termname.&#39;&quot; title=&quot;&quot; rel=&quot;&#39;.$termname.&#39;&quot;&amp;gt;&#39;.$term-&amp;gt;name.&#39;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&#39;;
    }
   }
  echo &quot;&amp;lt;/ul&amp;gt;&quot;;
 ?&amp;gt;
&lt;/pre&gt;The code above will generate a &lt;em&gt;ul&lt;/em&gt; with the default element ‘All’, and do a loop on terms to print all other categories that &lt;strong&gt;have entries&lt;/strong&gt;. Let’s do a more detailed explanation:&lt;br /&gt;
First, we create a variable called $terms, and we use the &lt;em&gt;get_terms()&lt;/em&gt; function that returns an array with all terms. As a parameter, the function requires a string or an array of strings with the taxonomy name(s), we pass &lt;strong&gt;tagportfolio&lt;/strong&gt;, that was the name we used in our &lt;em&gt;functions.php&lt;/em&gt; file. You can get more detailed info under &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/get_terms&quot;&gt;get_terms()&lt;/a&gt; in the WordPress Codex.&lt;br /&gt;
Then, we create a variable called $count and use the &lt;em&gt;count()&lt;/em&gt; function to get the total number of elements in the array, we print the default markup and the &lt;strong&gt;All&lt;/strong&gt; item.&lt;br /&gt;
After that, we verify if the $count variable is greater than zero, if yes, we have at least one category with items to print.&lt;br /&gt;
Inside if, we create a foreach loop to get all array values, and create a different &lt;em&gt;li element&lt;/em&gt; for each element in the $terms array.&lt;br /&gt;
Inside foreach, we create a variable called $termname to store the term name, remember that we change the text to lower case, because this variable will be used inside the class attribute.   Then, we just replace any white space with a &lt;strong&gt;-&lt;/strong&gt; using the &lt;em&gt;str_replace&lt;/em&gt; function, this line will enable you to use categories/terms with more than one word, like “WordPress Themes” for example.   And last, we print an &lt;em&gt;li&lt;/em&gt; element and use our variables to print the data in the right place.&lt;br /&gt;
If you test now, you’ll see a categories/terms list with the names that you created in WordPress Admin. Now, let’s work on the items.&lt;br /&gt;
&lt;h3&gt;Displaying the Portfolio Items&lt;/h3&gt;Now let’s display the portfolio items, we need do it following the required template shown above.&lt;br /&gt;
We’ll do it just adding the code below:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php
 $loop = new WP_Query(array(&#39;post_type&#39; =&amp;gt; &#39;project&#39;, &#39;posts_per_page&#39; =&amp;gt; -1));
 $count =0;
?&amp;gt;

&amp;lt;div id=&quot;portfolio-wrapper&quot;&amp;gt;
 &amp;lt;ul id=&quot;portfolio-list&quot;&amp;gt;

  &amp;lt;?php if ( $loop ) :

   while ( $loop-&amp;gt;have_posts() ) : $loop-&amp;gt;the_post(); ?&amp;gt;

    &amp;lt;?php
    $terms = get_the_terms( $post-&amp;gt;ID, &#39;tagportfolio&#39; );

    if ( $terms &amp;amp;&amp;amp; ! is_wp_error( $terms ) ) :
     $links = array();

     foreach ( $terms as $term )
     {
      $links[] = $term-&amp;gt;name;
     }
     $links = str_replace(&#39; &#39;, &#39;-&#39;, $links);
     $tax = join( &quot; &quot;, $links );
    else :
     $tax = &#39;&#39;;
    endif;
    ?&amp;gt;

    &amp;lt;?php $infos = get_post_custom_values(&#39;_url&#39;); ?&amp;gt;

    &amp;lt;li class=&quot;portfolio-item &amp;lt;?php echo strtolower($tax); ?&amp;gt; all&quot;&amp;gt;
     &amp;lt;div class=&quot;thumb&quot;&amp;gt;&amp;lt;a href=&quot;&amp;lt;?php the_permalink() ?&amp;gt;&quot;&amp;gt;&amp;lt;?php the_post_thumbnail( array(400, 160) ); ?&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;
     &amp;lt;h3&amp;gt;&amp;lt;a href=&quot;&amp;lt;?php the_permalink() ?&amp;gt;&quot;&amp;gt;&amp;lt;?php the_title(); ?&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/h3&amp;gt;
     &amp;lt;p class=&quot;excerpt&quot;&amp;gt;&amp;lt;a href=&quot;&amp;lt;?php the_permalink() ?&amp;gt;&quot;&amp;gt;&amp;lt;?php echo get_the_excerpt(); ?&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;
     &amp;lt;p class=&quot;links&quot;&amp;gt;&amp;lt;a href=&quot;&amp;lt;?php echo $infos[0]; ?&amp;gt;&quot; target=&quot;_blank&quot;&amp;gt;Live Preview →&amp;lt;/a&amp;gt; &amp;lt;a href=&quot;&amp;lt;?php the_permalink() ?&amp;gt;&quot;&amp;gt;More Details →&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;
    &amp;lt;/li&amp;gt;

   &amp;lt;?php endwhile; else: ?&amp;gt;

    &amp;lt;li class=&quot;error-not-found&quot;&amp;gt;Sorry, no portfolio entries found.&amp;lt;/li&amp;gt;

  &amp;lt;?php endif; ?&amp;gt;

 &amp;lt;/ul&amp;gt;

 &amp;lt;div class=&quot;clearboth&quot;&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;A lot of lines of code, no? But don’t worry, I’ll explain the code for you.&lt;br /&gt;
The first step is create a custom query, we do it with &lt;em&gt;WP_Query function&lt;/em&gt;, I pass as parameter the custom post type “project”, that we created on &lt;em&gt;functions.php&lt;/em&gt; file. This query will get all the projects that you’ve created.&lt;br /&gt;
Then, I do a loop like we do normally with post exhibition, for example.&lt;br /&gt;
Inside the while, we do the same process used on filter creation, but here we create a array called links where we’ll store all the terms of the post. Note that now, beyond the taxonomy name we pass the post ID in &lt;strong&gt;get_the_terms()&lt;/strong&gt;.&lt;br /&gt;
Then, we use &lt;em&gt;join&lt;/em&gt; and create a unique string with all array elements, if the post terms are “WordPress” and “Design”, the $tax variable will be equal to “wordpress design”, we’ll use this to add the right classes to allow the portfolio to be filterable. If the post doesn’t have terms, we just set $tax being equal to a blank string.&lt;br /&gt;
After this, we create a variable called $infos where we’ll get the demo url from our Custom Post Field created in the &lt;em&gt;functions.php&lt;/em&gt; file&lt;br /&gt;
Then, we just print the template markup and make use of functions like get_the_excerpt(), the_post_thumbnail (note that you can change the dimensions to fit your layout, if you for example, would like to create a three column portfolio.)&lt;br /&gt;
If you update the page, you will see all the items listed, but the filter still doesn’t work. Let’s fix it!&lt;br /&gt;
&lt;h3&gt;Using Filterable in WordPress&lt;/h3&gt;Now, let’s use our plugin. Did you already download it? If yes, copy and paste the &lt;em&gt;filterable.js&lt;/em&gt; file inside the &lt;strong&gt;js/&lt;/strong&gt; folder.&lt;br /&gt;
In the &lt;em&gt;functions.php&lt;/em&gt; file, let’s add the jQuery library to the ‘head’ tag first. To do it we’ll use a custom function and the &lt;em&gt;wp_enqueue_script&lt;/em&gt; function.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;function enqueue_filterable()
 {
  wp_register_script( &#39;filterable&#39;, get_template_directory_uri() . &#39;/js/filterable.js&#39;, array( &#39;jquery&#39; ) );
  wp_enqueue_script( &#39;filterable&#39; );
 }
 add_action(&#39;wp_enqueue_scripts&#39;, &#39;enqueue_filterable&#39;);
&lt;/pre&gt;Now, back to the &lt;em&gt;page_portfolio_2c.php&lt;/em&gt; file and below the last code added but inside the &lt;em&gt;content div&lt;/em&gt;, add the following code:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;script&amp;gt;
  jQuery(document).ready(function() {
   jQuery(&quot;#portfolio-list&quot;).filterable();
  });
 &amp;lt;/script&amp;gt;
&lt;/pre&gt;This only links the plugin to the page and calls the &lt;em&gt;filterable()&lt;/em&gt; function to make our portfolio filterable.&lt;br /&gt;
&lt;h3&gt;Full Code&lt;/h3&gt;&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php
/*
Template Name: Portfolio 2 Columns
*/
?&amp;gt;

&amp;lt;?php
get_header(); ?&amp;gt;

  &amp;lt;div id=&quot;primary&quot;&amp;gt;
   &amp;lt;div id=&quot;content&quot; role=&quot;main&quot;&amp;gt;

   &amp;lt;?php
     $terms = get_terms(&quot;tagportfolio&quot;);
     $count = count($terms);
     echo &#39;&amp;lt;ul id=&quot;portfolio-filter&quot;&amp;gt;&#39;;
     echo &#39;&amp;lt;li&amp;gt;&amp;lt;a href=&quot;#all&quot; title=&quot;&quot;&amp;gt;All&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&#39;;
     if ( $count &amp;gt; 0 ){

      foreach ( $terms as $term ) {

       $termname = strtolower($term-&amp;gt;name);
       $termname = str_replace(&#39; &#39;, &#39;-&#39;, $termname);
       echo &#39;&amp;lt;li&amp;gt;&amp;lt;a href=&quot;#&#39;.$termname.&#39;&quot; title=&quot;&quot; rel=&quot;&#39;.$termname.&#39;&quot;&amp;gt;&#39;.$term-&amp;gt;name.&#39;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&#39;;
      }
     }
     echo &quot;&amp;lt;/ul&amp;gt;&quot;;
   ?&amp;gt;

   &amp;lt;?php
    $loop = new WP_Query(array(&#39;post_type&#39; =&amp;gt; &#39;project&#39;, &#39;posts_per_page&#39; =&amp;gt; -1));
    $count =0;
   ?&amp;gt;

   &amp;lt;div id=&quot;portfolio-wrapper&quot;&amp;gt;
    &amp;lt;ul id=&quot;portfolio-list&quot;&amp;gt;

    &amp;lt;?php if ( $loop ) :

     while ( $loop-&amp;gt;have_posts() ) : $loop-&amp;gt;the_post(); ?&amp;gt;

      &amp;lt;?php
      $terms = get_the_terms( $post-&amp;gt;ID, &#39;tagportfolio&#39; );

      if ( $terms &amp;amp;&amp;amp; ! is_wp_error( $terms ) ) :
       $links = array();

       foreach ( $terms as $term )
       {
        $links[] = $term-&amp;gt;name;
       }
       $links = str_replace(&#39; &#39;, &#39;-&#39;, $links);
       $tax = join( &quot; &quot;, $links );
      else :
       $tax = &#39;&#39;;
      endif;
      ?&amp;gt;

      &amp;lt;?php $infos = get_post_custom_values(&#39;_url&#39;); ?&amp;gt;

      &amp;lt;li class=&quot;portfolio-item &amp;lt;?php echo strtolower($tax); ?&amp;gt; all&quot;&amp;gt;
       &amp;lt;div class=&quot;thumb&quot;&amp;gt;&amp;lt;a href=&quot;&amp;lt;?php the_permalink() ?&amp;gt;&quot;&amp;gt;&amp;lt;?php the_post_thumbnail( array(400, 160) ); ?&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;
       &amp;lt;h3&amp;gt;&amp;lt;a href=&quot;&amp;lt;?php the_permalink() ?&amp;gt;&quot;&amp;gt;&amp;lt;?php the_title(); ?&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/h3&amp;gt;
       &amp;lt;p class=&quot;excerpt&quot;&amp;gt;&amp;lt;a href=&quot;&amp;lt;?php the_permalink() ?&amp;gt;&quot;&amp;gt;&amp;lt;?php echo get_the_excerpt(); ?&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;
       &amp;lt;p class=&quot;links&quot;&amp;gt;&amp;lt;a href=&quot;&amp;lt;?php echo $infos[0]; ?&amp;gt;&quot; target=&quot;_blank&quot;&amp;gt;Live Preview →&amp;lt;/a&amp;gt; &amp;lt;a href=&quot;&amp;lt;?php the_permalink() ?&amp;gt;&quot;&amp;gt;More Details →&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;
      &amp;lt;/li&amp;gt;

     &amp;lt;?php endwhile; else: ?&amp;gt;

     &amp;lt;li class=&quot;error-not-found&quot;&amp;gt;Sorry, no portfolio entries for while.&amp;lt;/li&amp;gt;

    &amp;lt;?php endif; ?&amp;gt;

    &amp;lt;/ul&amp;gt;

    &amp;lt;div class=&quot;clearboth&quot;&amp;gt;&amp;lt;/div&amp;gt;

   &amp;lt;/div&amp;gt; &amp;lt;!-- end #portfolio-wrapper--&amp;gt;

   &amp;lt;script&amp;gt;
    jQuery(document).ready(function() {
     jQuery(&quot;#portfolio-list&quot;).filterable();
    });
   &amp;lt;/script&amp;gt;

   &amp;lt;/div&amp;gt;&amp;lt;!-- #content --&amp;gt;
  &amp;lt;/div&amp;gt;&amp;lt;!-- #primary --&amp;gt;

&amp;lt;?php get_footer(); ?&amp;gt;
&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Step 5: Some style&lt;/h2&gt;Now that we’ve coded everything that we need, let’s add some CSS to our &lt;em&gt;style.css&lt;/em&gt; file, if you have other files just add the code there.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;/* CLEARFIX
----------------------------------------------- */

.clearboth {
 display: block;
 margin: 0;
 padding: 0;
 clear: both;
}

/* PORTFOLIO FILTER STYLE
----------------------------------------------- */

#portfolio-filter {
 list-style-type: none;
}

#portfolio-filter li {
 display: inline;
 padding-right: 10px;
}

#portfolio-filter li a {
 color: #777;
 text-decoration: none;
}

#portfolio-filter li .current,
#portfolio-filter li:hover {
 color: #084a9a;
}

/* PORTFOLIO LIST STYLE
----------------------------------------------- */

#portfolio-wrapper {
 padding-bottom: 25px;
}

#portfolio-list {
 list-style-type: none;

}

#portfolio-list .portfolio-item {
 width: 400px;
 float: left;
 margin-right: 5px;
}

#portfolio-list .portfolio-item h3 a {
 color: #084a9a;
 text-transform: uppercase;
 font-weight: bold;
}

#portfolio-list .portfolio-item .excerpt
{
 text-align: justify;
 font-size: 14px;
 line-height: 18px;
 padding-right: 15px;
 margin-bottom: 5px;
}

#portfolio-list .portfolio-item .excerpt a {
 color: #555;
}

#portfolio-list .portfolio-item .excerpt a:hover {
 text-decoration: none;
}
&lt;/pre&gt;Now, if you test again you’ll get a nice filterable portfolio! Wow, all the work is done!&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;And it’s done! Now you know how to create an amazing filterable portfolio with a free jQuery plugin that you can use in any work that you do.&lt;br /&gt;
I hope that you enjoy the content, thank you very much for reading!&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/7845479104186815890'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/7845479104186815890'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/02/creating-filterable-portfolio-with.html' title='Creating a Filterable Portfolio with WordPress and jQuery'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-5671998267206401346</id><published>2012-02-06T17:49:00.001+08:00</published><updated>2012-02-06T17:50:11.777+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Multisite"/><category scheme="http://www.blogger.com/atom/ns#" term="Tips"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorial"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><title type='text'>Using WordPress Multisite: A Network of Websites at Your Fingertips</title><content type='html'>&quot;Today, we will look at the basics of WordPress MS – or for those users that have been using WordPress for a while – Multisite or WordPress MU. WordPress MS is a feature that many users are unaware of, and one that is often confusing to install and configure. But no more! In this tutorial, we will walk through installing WordPress MS, becoming familiar with the network admin, and integrating useful plugins for your Multisite network.  &lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Introduction&lt;/h2&gt;WordPress Multisite is a feature that since WordPress version 3 has been included discreetly right into the install itself. It is a feature that packs a huge punch, allowing 1000s of blogs to exist virtually within one, single WordPress install. It is a great idea for large-scale sites that use multiple sub-domains, blog networks, social networks, or even internal networking for businesses or organizations. While this feature has been around for almost as long as WordPress itself, it is just now getting the attention it deserves – even from &lt;a href=&quot;http://wpdevel.wordpress.com/2011/12/23/core-team-meetup-recap-multisite/&quot;&gt;WordPress devs&lt;/a&gt;.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;What We Will Do&lt;/h2&gt;In this tutorial we will:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;take an in-depth look at WordPress MS (aka Multisite or WordPress MU)&lt;/li&gt;
&lt;li&gt;install WordPress MS and learn about the different installation options&lt;/li&gt;
&lt;li&gt;create new sites with MS&lt;/li&gt;
&lt;li&gt;look at some useful plugins to combine with WordPress MS&lt;/li&gt;
&lt;li&gt;examine projects that could benefit from MS&lt;/li&gt;
&lt;/ul&gt;By the end of this tutorial series, you should be extremely familiar with what WordPress MS is, how to install it, how to create new sites, and how to use it most effectively for your next project.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;What Exactly is WordPress MS?&lt;/h2&gt;In a nutshell, Multisite enables a single WordPress install to act like a network of sites centered around a single domain (http://yoursite.com). It allows for either new sub-domains (http://subdomain.yoursite.com) or sub-directories (http://yoursite.com/subdomain), and it does all this virtually, which means you do not need to create new folders. Instead, by just adding some code to wp-config.php and .htaccess, you have thousands of sites right at your fingertips.&lt;br /&gt;
Multisite also allows for easy network management through a single admin dashboard which a user with appropriate permissions can access via any network site’s admin bar. Multisite is by no means “new”. It has been around for almost as long as WordPress itself, although previously it was developed separately. Since WP 3.0 it has been included together with WordPress, and, as I mentioned above, it seems like it will only get more user-friendly as the WordPress devs seem to be paying some particular attention to it in 2012.&lt;br /&gt;
Next, let’s look at installing Multisite on a typical WordPress install.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Installing WordPress Multisite&lt;/h2&gt;For many people, installing Multisite can be a nightmare. I hope to alleviate that by taking you step-by-step through both a sub-directory and sub-domain install. Let me say first, that it is by far easier to install Multisite on a new install, even though it is still possible to do it on an older install with pre-existing content. However, there could possibly be permalink issues.&lt;br /&gt;
With that said, the following steps assume that you have completed a standard install of WordPress. However, the steps can apply to a new or previous install.&lt;br /&gt;
&lt;h3&gt;Activating the Network Setup Menu Item&lt;/h3&gt;In order to even begin the process of installing Multisite, you need to open your wp-config.php file, and right above&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;/* That’s all, stop editing! Happy blogging. */
&lt;/pre&gt;add the following:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;/** Allow Multisite **/

define(’WP_ALLOW_MULTISITE’, true);
&lt;/pre&gt;The first line simply is a comment that will help us keep our code tidy. Next, we tell our WordPress install to allow Multisite functionality. Once you have edited and saved the file, you should now see the following in your “Tools” submenu:&lt;br /&gt;
&lt;div&gt;&lt;img src=&quot;http://wptutsplus.s3.amazonaws.com/173_MultipressBasics/network_activated.jpg&quot; /&gt;&lt;/div&gt;&lt;blockquote&gt;If you are using a previous WordPress install with active plugins, you will get a notice in Network Setup to deactivate all of your plugins before you continue.&lt;/blockquote&gt;&lt;h3&gt;Configuring the Network from the Dashboard&lt;/h3&gt;The first screen in “Network Setup” will look like this:&lt;br /&gt;
&lt;div&gt;&lt;img src=&quot;http://wptutsplus.s3.amazonaws.com/173_MultipressBasics/install_1.png&quot; /&gt;&lt;/div&gt;From this screen, you have the following items to configure:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Site Addresses&lt;/strong&gt; – From here you will select whether to use sub-domains or sub-directories. If you choose to work with sub-domains, you should verify with your host if it is possible.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Network Title&lt;/strong&gt; – The title for your network.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Admin E-Mail Address&lt;/strong&gt; – The admin contact for your new network.&lt;/li&gt;
&lt;/ul&gt;The &lt;strong&gt;server address&lt;/strong&gt; should already be filled in to display how your new permalinks will appear.&lt;br /&gt;
&lt;blockquote&gt;If this is a pre-existing install, you will receive a note saying that only sub-domains are possible due to possible permalink conflicts. If you are installing on a localhost, you will only be allowed to install via sub-directories.&lt;/blockquote&gt;After you have configured these settings, click install, and you should see the following screen:&lt;br /&gt;
&lt;div&gt;&lt;img src=&quot;http://wptutsplus.s3.amazonaws.com/173_MultipressBasics/install_2.png&quot; /&gt;&lt;/div&gt;&lt;h3&gt;Finishing the Multisite Install&lt;/h3&gt;Now, let’s look step-by-step at the instructions given on the “Enabling the Network” page. Before you dig into this, I would strongly suggest that you backup your wp-config.php and .htaccess files. This will save a lot of headache in the future.&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Create a new directory named &lt;strong&gt;blogs.dir&lt;/strong&gt;, and place that in your root folder’s &lt;strong&gt;wp-content&lt;/strong&gt; folder. This folder must be writable by the web server, as it will be used to store all of our network’s uploaded media.&lt;/li&gt;
&lt;li&gt; Add the following code for a subdomain install:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;define( ’SUBDOMAIN_INSTALL’, true );
 $base = ’/’;
 define( ’DOMAIN_CURRENT_SITE’, ’yoursite.com’ );
 define( ’PATH_CURRENT_SITE’, ’/’ );
 define( ’SITE_ID_CURRENT_SITE’, 1 );
 define( ’BLOG_ID_CURRENT_SITE’, 1 );
 &lt;/pre&gt;and this for a sub-directory install&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;define( ’MULTISITE’, true );
 define( ’SUBDOMAIN_INSTALL’, false );
 $base = ’/’;
 define( ’DOMAIN_CURRENT_SITE’, ’yoursite.com’ );
 define( ’PATH_CURRENT_SITE’, ’/’ );
 define( ’SITE_ID_CURRENT_SITE’, 1 );
 define( ’BLOG_ID_CURRENT_SITE’, 1 );
 &lt;/pre&gt;to &lt;strong&gt;wp-config.php&lt;/strong&gt; right above:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;/* That’s all, stop editing! Happy blogging. */
 &lt;/pre&gt;Make sure to change &lt;strong&gt;yoursite.com&lt;/strong&gt; to the URL of your site – make sure it is without WWW. Broken down, this code identifies this as a sub-domain or sub-directory install, and sets your main site’s ID as 1. Every site has an ID, and it is important to note these as you start to work with plugins and build custom queries.&lt;/li&gt;
&lt;li&gt;Add the authentication keys provided to wp-config.php. This will help secure your install.&lt;/li&gt;
&lt;li&gt; Finally, you want to add the following code to your .htaccess file:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.php$ - [L]

  # uploaded files
  RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]

  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]
  RewriteRule . index.php [L]
 &lt;/pre&gt;This code will replace any other WordPress code that you find in .htaccess.&lt;/li&gt;
&lt;/ol&gt;For another reference on setting up a WordPress Multisite network, be sure to visit  the “&lt;a href=&quot;http://codex.wordpress.org/Tools_Network_Screen#Create_a_Network_of_WordPress_Sites&quot;&gt;Create a Network of WordPress Sites&lt;/a&gt;” page in the Codex.&lt;br /&gt;
&lt;h3&gt;Things to Note with Multisite Installs&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Multisite is easiest to install on a fresh WordPress install with the sites as sub-directories. That isn’t to say don’t install it any other way, just to point out the easiest path.&lt;/li&gt;
&lt;li&gt;If you use Multisite, then you &lt;strong&gt;can not&lt;/strong&gt; give WordPress it’s own folder. It must be installed in the root folder of your site. &lt;strong&gt;&lt;em&gt;Editor’s Note: This is not 100% correct, for further information and clarification, &lt;a href=&quot;http://wp.tutsplus.com/tutorials/using-wordpress-multisite-a-network-of-websites-at-your-fingertips/#comment-15457&quot;&gt;see Andrea_R’s comment below.&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Your web host may not allow for the creation of sub-domains. Be sure to check this out before attempting a sub-domain install.&lt;/li&gt;
&lt;li&gt;You must activate the network feature from the WordPress dashboard. Simply adding the code to wp-config.php and .htaccess is not enough.&lt;/li&gt;
&lt;/ul&gt;&lt;hr /&gt;&lt;h2&gt;Navigating the Network Admin&lt;/h2&gt;In order to access the Multisite admin dashboard in WordPress 3.0 and later, simply hover over &lt;strong&gt;My Sites&lt;/strong&gt; in the admin bar at the top of the browser window, and click on &lt;strong&gt;Network Admin&lt;/strong&gt;.&lt;br /&gt;
&lt;div&gt;&lt;img src=&quot;http://wptutsplus.s3.amazonaws.com/173_MultipressBasics/network_admin.jpg&quot; /&gt;&lt;/div&gt;Once in the dashboard, the menu looks like this:&lt;br /&gt;
&lt;div&gt;&lt;img src=&quot;http://wptutsplus.s3.amazonaws.com/173_MultipressBasics/mu_menu.jpg&quot; /&gt;&lt;/div&gt;The Network Admin menu has the following submenus:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Sites&lt;/strong&gt; – From here you can create new network sites, visit admin dashboards, delete sites, and edit site settings.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Users&lt;/strong&gt; – This submenu allows you to manage users by creating, editing, and deleting them. You can also see which users have registered on specific sites.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Themes&lt;/strong&gt; – With Multisite, themes are managed from the network. Themes must be installed, activated, and edited from within the network admin dashboard. They can still be switched in the site dashboard.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Plugins&lt;/strong&gt; – Just like themes, plugins are installed and activated on the network from this dashboard.  Plugins can still be activated and set up in the site dashboard.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Settings&lt;/strong&gt; – This submenu lets you set the network name, admin email, registration settings, welcome emails, initial site settings, and upload settings. This is a great submenu to configure if you are using Multisite as a blog engine or social network.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Updates&lt;/strong&gt; – From this submenu, you can do network-wide updates on WordPress core, plugins, and themes.&lt;/li&gt;
&lt;/ul&gt;Next, I want to walk you through creating your first network site. If you are familiar with using WordPress, everything else should seem pretty normal, with the exception of having to go through a network dashboard to activate plugins and themes instead of a normal site dashboard.&lt;br /&gt;
&lt;h3&gt;Creating a New Site&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;From the network dashboard, navigate to &lt;strong&gt;Sites –&amp;gt; Add New&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Next, you will need to specify the site address, site title, and an admin email. The screen will look like this:  &lt;div&gt;&lt;img src=&quot;http://wptutsplus.s3.amazonaws.com/173_MultipressBasics/new_site1.jpg&quot; /&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;Once added, you will see a message at the top verifying the site’s creation. You can now visit the site’s dashboard, or edit the site’s settings from the network dashboard. Two emails will also be sent. Once will go to the network’s overall admin notifying them of the new site, and one will go to the site’s new admin, notifying them of their login credentials.&lt;/li&gt;
&lt;/ol&gt;And that’s how easy creating sites can be in WordPress MS! Now, let’s look at some plugins.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Indispensable Plugins for WordPress MS&lt;/h2&gt;Here is a list of some plugins that I suggest using on MS installs, and, as always, if you have others to add throw them in!&lt;br /&gt;
&lt;ul&gt;&lt;li&gt; &lt;h4&gt;WordPress MU Sitewide Tags Pages&lt;/h4&gt;This plugin allows you to create a specific blog on the network where ALL recent posts on the network can be found. From within the plugin, you can also specify this to be on the main site that you set up in the initial Multisite install. The max number of posts to display can be set as well.&lt;/li&gt;
&lt;li&gt; &lt;h4&gt;Multipost MU / ThreeWP Broadcast&lt;/h4&gt;This plugin allows users that create content on different blogs to &quot;broadcast&quot; their posts to other blogs on the network. In addition to post content, categories, tags, and custom fields can also be broadcasted. To ease publishing to multiple blogs, blog groups can be created.&lt;/li&gt;
&lt;li&gt; &lt;h4&gt;More Privacy Options&lt;/h4&gt;This plugin allows you to set the privacy level of each blog from within the network dashboard site’s settings panel. The options are:&lt;br /&gt;
&lt;div&gt;&lt;img src=&quot;http://wptutsplus.s3.amazonaws.com/173_MultipressBasics/more_privacy.jpg&quot; /&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt; &lt;h4&gt;Domain Mapping&lt;/h4&gt;This plugin allows users to use their own domain names on your Multisite network. This plugin does require a knowledge of adding and editing plugin files and a basic understanding of how servers work and your specific server settings. A great tutorial for setting up this plugin can be found on Otto’s blog, “&lt;a href=&quot;http://ottopress.com/2010/wordpress-3-0-multisite-domain-mapping-tutorial/&quot;&gt;WordPress 3.0 Multisite Domain Mapping Tutorial&lt;/a&gt;“.&lt;/li&gt;
&lt;li&gt; &lt;h4&gt;Multisite User Management&lt;/h4&gt;This plugin allows admins to set the default role of each, individual network blog. Once activated, a list of blogs appears on the network settings page. This plugin is different than the New Blog Defaults plugin, as it targets the individual sites as opposed to every new blog. For instance, if you want one site to allow all default users editor capabilities and another to have subscriber capabilities, then this is the plugin you are looking for.&lt;/li&gt;
&lt;li&gt; &lt;h4&gt;New Blog Defaults&lt;/h4&gt;This plugin creates defaults for any new blog created on the network. Once activated, a new menu appears under the network &lt;strong&gt;Settings&lt;/strong&gt; submenu. From here, you can edit any of the normal WordPress settings: general blog settings, reading settings, writing settings, permalink settings, discussion settings, privacy settings, and media settings. You can also choose a site’s default theme, and set other options like categories, links, and initial user settings.&lt;/li&gt;
&lt;li&gt; &lt;h4&gt;Extended Super Admins&lt;/h4&gt;This plugin allows for the creation of specific user classes with specific roles. The plugin, once activated, can be found under the main network &lt;strong&gt;Settings&lt;/strong&gt; submenu. The capabilities list is extensive.&lt;/li&gt;
&lt;/ul&gt;&lt;hr /&gt;&lt;h2&gt;Projects that Could Benefit from WordPress MS&lt;/h2&gt;Now that I’ve outlined how to install Multisite, how to create new sites, and what plugins to use, I thought it would be great to put some ideas down about possible projects that could benefit from Multisite. As always, if you have other ideas or Multisite installs that you’ve worked with before, feel free to add them in the comments.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Blog networks&lt;/li&gt;
&lt;li&gt;Social networks&lt;/li&gt;
&lt;li&gt;Internal networks for organizations or companies&lt;/li&gt;
&lt;li&gt;Educational sites&lt;/li&gt;
&lt;li&gt;Sites that span cities, customer groups, or other various groups&lt;/li&gt;
&lt;li&gt;Any other WP site that may need the option for multiple sites within one install&lt;/li&gt;
&lt;/ul&gt;&lt;hr /&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;This year holds some exciting things for Multisite, and as more and more users discover how to implement it, this currently under-used feature could soon become one of the core features WordPress is known and used for. I hope that you have learned how to install Multisite, how to navigate the network admin, and how to find plugins that can improve the functionality of your networks.  Overall, I hope that you feel more comfortable using Multisite in your projects, and that, if you’ve never used it, you’ll take the plunge and play around with it.&lt;br /&gt;
Thanks for reading!&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/5671998267206401346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/5671998267206401346'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/02/using-wordpress-multisite-network-of.html' title='Using WordPress Multisite: A Network of Websites at Your Fingertips'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-7706832710489971337</id><published>2012-02-06T15:54:00.001+08:00</published><updated>2012-02-06T15:55:03.376+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="prettyPhoto"/><category scheme="http://www.blogger.com/atom/ns#" term="Tips"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorial"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><title type='text'>How to Integrate prettyPhoto with Post Images in your Themes</title><content type='html'>&quot;prettyPhoto is a lightbox plugin made by &lt;a href=&quot;http://www.no-margin-for-errors.com/&quot;&gt;Stéphane Caron&lt;/a&gt;. Today we’re going to learn how to ship the plugin with your WordPress themes.&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Introduction &lt;/h2&gt;Giving a built-in lightbox option instead of making users download a plugin has many benefits for theme authors. For me it’s being able to theme the lightbox to suit my WordPress themes. It’s also a nice feature to have available to your theme’s users, of course you should also give them an option to disable the functionality. With that said let’s get to it.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 1 Download prettyPhoto and set up directory structure&lt;/h2&gt;Head over to &lt;a href=&quot;http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/&quot;&gt;margins for-errors.com&lt;/a&gt; and download the plugin. Once you’ve got it we’re going to create a new directory structure for the plugin to make things easier for ourselves.&lt;br /&gt;
First let’s delete a few things we don’t need. In the images folder delete everything apart from the prettyPhoto folder and it’s contents. In the root folder, delete the file xhr_response.html and index.html. Now move jquery.prettyPhoto.js from the js folder to the root plugin folder and delete the js folder.&lt;br /&gt;
Finally, rename the folder to prettyPhoto and upload the folder to your theme’s directory, you probably already have a js or scripts directory so upload to that, for this tutorial let’s presume it’s in your-theme/js&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 2 Add the scripts to your theme (Updated: See comments below)&lt;/h2&gt;Before we load up the plugin files in our theme we need to load jQuery. We’re going use the Google hosted version of jQuery using the method shared on &lt;a href=&quot;http://digwp.com/2009/06/use-google-hosted-javascript-libraries-still-the-right-way/&quot;&gt;Digging into WordPress&lt;/a&gt;, so let’s add the snippet to our functions.php.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;if (!is_admin()) {
 add_action(&quot;wp_enqueue_scripts&quot;, &quot;register_scripts&quot;, 11);
}
function register_scripts() {
 wp_deregister_script(&#39;jquery&#39;);
 wp_register_script(&#39;jquery&#39;, &quot;http&quot; . ($_SERVER[&#39;SERVER_PORT&#39;] == 443 ? &quot;s&quot; : &quot;&quot;) . &quot;://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&quot;, false, null);
 wp_enqueue_script(&#39;jquery&#39;);

 wp_register_script(&#39;prettyPhoto_script&#39;, (get_bloginfo(&#39;stylesheet_directory&#39;).&quot;/js/prettyPhoto/jquery.prettyPhoto.js&quot;));
 wp_enqueue_script(&#39;prettyPhoto_script&#39;);
 wp_register_script(&#39;customprettyPhoto_script&#39;, (get_bloginfo(&#39;stylesheet_directory&#39;).&quot;/js/prettyPhoto/customprettyPhoto.js&quot;));
 wp_enqueue_script(&#39;customprettyPhoto_script&#39;);
}
&lt;/pre&gt;You might want to consider the advantages and disadvantages of using a CDN to serve jQuery. WordPress does ship with a copy of jQuery but using Google’s hosted version may benefit your site’s performance. If you’re a theme author I would stick with using the shipped version. Check out the discussion on another &lt;a href=&quot;http://wp.tutsplus.com/tutorials/load-jquery-from-google-cdn-with-local-fallback-for-wordpress/&quot;&gt;tutorial&lt;/a&gt; to help you make up your own mind.&lt;br /&gt;
You’ll notice we’ve added another file called customprettyPhoto.js. This is where we’ll be making the plugin play nice with our post images and initialising it. So let’s create that file and put it in your prettyPhoto directory. OK, let’s initialise prettyPhoto.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;script&amp;gt;
 $(document).ready(function(){
   $(&quot;a[class^=&#39;prettyPhoto&#39;]&quot;).prettyPhoto();
 });
&amp;lt;/script&amp;gt;
&lt;/pre&gt;We need to add a line of jQuery to add the required prettyPhoto class prettyPhoto to the anchor tags that surround our post images. Since we’re talking jQuery let’s use it to accomplish this. Add the following right after $(document).ready(function(){ where we make sure the page is loaded.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;$(&#39;.entry-content a&#39;).has(&#39;img&#39;).addClass(&#39;prettyPhoto&#39;);
&lt;/pre&gt;Replace .entry-content with whatever class name or ID you’ve wrapped your post content with and you should have successfully added the class to all links that wrap your post images. If you had a look at the documentation for prettyPhoto you will see it says to use a rel attribute but instead we’ve used a class. Doing so prevents validation errors in our HTML because rel attributes can only have certain allowed values according to the HTML5 spec.&lt;br /&gt;
Next we want to enable prettyPhoto’s description option. We have to overcome one small hurdle which is that prettyPhoto wants us to add title attributes to our anchor tags that will be used for the descriptions but WordPress adds titles to image tags. To solve this we’ll write a couple lines of jQuery that will take the image title tag and set the same title on the anchor tag that wraps the image.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;$(&#39;.entry-content a img&#39;).click(function () {
 var desc = $(this).attr(&#39;title&#39;);
 $(&#39;.entry-content a&#39;).has(&#39;img&#39;).attr(&#39;title&#39;, desc);
});
&lt;/pre&gt;Here we fire a function when the user clicks on a post image. We grab the image’s title tag and attach it to the anchor. This step makes it a lot easier for your theme’s users to add descriptions. If you want to disable the functionality altogether just make sure to set each anchors title to be empty, if it’s totally missing, as in there isn’t even an empty title, prettyPhoto will just display “undefined” instead.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 3 Add the prettyPhoto CSS to your theme&lt;/h2&gt;We need to add the CSS for prettyPhoto to the theme. Back to your functions.php file and add the following line to the top:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;wp_enqueue_style(&#39;prettyPhoto&#39;, get_bloginfo(&#39;stylesheet_directory&#39;).&#39;/js/prettyPhoto/css/prettyPhoto.css&#39;);
&lt;/pre&gt;Since we kept the images and CSS in their original folders and relative to each other as they were originally we don’t need to worry about broken images.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 4 Captions and Titles&lt;/h2&gt;&lt;div&gt;&lt;img border=&quot;0&quot; src=&quot;http://wptutsplus.s3.amazonaws.com/174_IntegratePrettyPhoto/images/altandtitle.jpg&quot; /&gt;&lt;/div&gt;Let’s look at how to add captions and titles that our prettyPhoto will use. Looking at the image above we can see the relationship between the post image alt tag and link title tag we can set when adding an image to a post or page.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Finishing Up &lt;/h2&gt;And that’s it, we’ve successfully added prettyPhoto to our theme. Make sure to read the plugin documentation for more uses and options. PrettyPhoto can handle more than just images, it works with videos, ajax and more. It also ships with a handful of themes that may suit your theme out of the box or at least give you a good starting point.&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/7706832710489971337'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/7706832710489971337'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2012/02/how-to-integrate-prettyphoto-with-post.html' title='How to Integrate prettyPhoto with Post Images in your Themes'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-910534722329448513</id><published>2011-12-02T13:25:00.001+08:00</published><updated>2011-12-02T13:26:12.520+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Best Practices"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress Plugins"/><title type='text'>7 Simple Rules: WordPress Plugin Development Best Practices</title><content type='html'>&quot;We’ve been talking a lot about “&lt;a href=&quot;http://wp.tutsplus.com/articles/5-cardinal-sins-of-wordpress-theme-development/&quot;&gt;Best Practices&lt;/a&gt;” here on Wptuts lately. Today, we’ll cover some important best practices for creating a WordPress plugin. From security tips to namespacing tricks, follow these rules and you’ll do no wrong. Whether you’re a budding new plugin developer or a time-tested veteran, these simple rules and suggestions will make you a better developer (and the community will thank you for it!) &lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Rule 01: Have a Strategy&lt;/h2&gt;Yes, a strategy. Try this checklist:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Is my plugin just for fun/demonstration purposes or for everyday use in the real world?&lt;/li&gt;
&lt;li&gt;Am I writing it to contribute to the community, to promote myself or to earn income?&lt;/li&gt;
&lt;li&gt;Can I afford the time to offer support to users?&lt;/li&gt;
&lt;li&gt;Have similar plugins already been written? Check the &lt;a href=&quot;http://wordpress.org/extend/plugins/&quot;&gt;WordPress Plugin Repository&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;These questions are important because they impact on how seriously you need to take issues such as coding standards, updates, security, support and documentation. Even if you’re just writing a plugin for your own use or for the use of your colleagues, you need to think hard about how you’re going to go about it so that you don’t make a rod for your own back. &lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Rule 02: Use Consistent and Clear Coding Standards&lt;/h2&gt;Which do you prefer, this?&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;function parsefile($imagedata,$file){
if(!in_array($imagedata[&#39;mime&#39;], array(&#39;image/jpeg&#39;,&#39;image/png&#39;,&#39;image/gif&#39;))){
 $result[&#39;error&#39;]=&#39;Your image must be a jpeg, png or gif!&#39;;
 }elseif(($file[&#39;size&#39;]&amp;gt;200000)){
 $result[&#39;error&#39;]=&#39;Your image was &#39;.$file[&#39;size&#39;].&#39; bytes! It must not exceed &#39;.MAX_UPLOAD_SIZE.&#39; bytes.&#39;;
 }
 return $result;
}
&lt;/pre&gt;Or this?&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;/*
processes the uploaded image, checking against file type and file size
*/
function parse_file($image_data, $file){

 if(!in_array($image_data[&#39;mime&#39;], unserialize(TYPE_WHITELIST))){

   $result[&#39;error&#39;] = &#39;Your image must be a jpeg, png or gif!&#39;;

 }elseif(($file[&#39;size&#39;] &amp;gt; MAX_UPLOAD_SIZE)){

   $result[&#39;error&#39;] = &#39;Your image was &#39; . $file[&#39;size&#39;] . &#39; bytes! It must not exceed &#39; . MAX_UPLOAD_SIZE . &#39; bytes.&#39;;

 }

 return $result;

}
&lt;/pre&gt;Simple things like consistent spacing, indenting, informative variable naming and succinct comments are a good place to start. That’s the only difference in the examples above. WordPress has an &lt;a href=&quot;http://codex.wordpress.org/WordPress_Coding_Standards&quot;&gt;excellent guide&lt;/a&gt; to coding standards. If you code to a standard your code will be easier to understand, edit and debug. &lt;br /&gt;
&lt;h3&gt;Use Namespacing&lt;/h3&gt;There are two ways to construct a WordPress plugin: as a bunch of functions or as a class. Keep in mind that the functions in your plugin get thrown into the global namespace with all the other non-namespaced functions, which means that if you have a function named plugin_init then it’s probably going to conflict with the same function written by someone else at some point. The obvious way to fix this issue is to prefix the function name with something unique. I like to use the first letters of my plugin name, so if I had a plugin called My Great Plugin, I would call the above function mgp_plugin_init, and the same for the rest of my functions.&lt;br /&gt;
But a better way is to create a class for your plugin, that way all functions will be &lt;strong&gt;namespaced&lt;/strong&gt; under the name of the class and even better, you can now use short, common method (function) names.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;class my_class{

 function hello_world(){

   return &#39;Hello World!&#39;;

 }

 function goodbye_world(){

   return &#39;Goodbye World!&#39;;

 }

}
&lt;/pre&gt;Then you could access your class methods under the its own namespace:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;$my_new_plugin = new my_class();

echo $my_new_plugin-&amp;gt;hello_world();

echo $my_new_plugin-&amp;gt;goodbye_world();
&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Rule 03: Take Security Seriously&lt;/h2&gt;Making your plugin secure is the single most important step to take, but many developers discount security or relegate it to the status of an afterthought. Don’t make that mistake. &lt;br /&gt;
&lt;h3&gt;Sanitize inputs, escape outputs&lt;/h3&gt;You should especially make yourself familiar with:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Function_Reference/esc_url&quot;&gt;esc_url&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Function_Reference/esc_url_raw&quot;&gt;esc_url_raw&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Function_Reference/wp_filter_kses&quot;&gt;wp_filter_kses&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Function_Reference/esc_attr&quot;&gt;esc_attr&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Function_Reference/esc_html&quot;&gt;esc_html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Function_Reference/esc_textarea&quot;&gt;esc_textarea&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;If you use a function such as &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/wp_insert_post&quot;&gt;wp_insert_post&lt;/a&gt;, WordPress will sanitize that data for you. Similarly, if you use the database methods $wpdb-&amp;gt;insert or $wpdb-&amp;gt;update, WordPress will sanitize the data. But if you choose to access the database more directly with something like $wpdb-&amp;gt;get_result, then you should use wpdb-&amp;gt;prepare to prevent sql injections of malicious code.&lt;br /&gt;
Instead of:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;$admin_posts = $wpdb-&amp;gt;get_results(
 &quot;SELECT ID, post_title FROM $wpdb-&amp;gt;posts WHERE post_status = &#39;publish&#39; AND post_author = 1&quot;
 );
&lt;/pre&gt;You would use:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;$admin_posts = $wpdb-&amp;gt;get_results($wpdb-&amp;gt;prepare(
 &quot;SELECT ID, post_title FROM $wpdb-&amp;gt;posts WHERE post_status = %s AND post_author = %d&quot;,
 &#39;publish&#39;, 1
 ));
&lt;/pre&gt;In the above example, %s is a placeholder for string input (publish) and %d is a placeholder for numeric input (1). You can use as many placeholders as you need.&lt;br /&gt;
&lt;h3&gt;Use Nonces for Form and URL Verification&lt;/h3&gt;It’s important to know that when a form or url is posted back to WordPress, that it was your WordPress site that actually generated it and not some third party or malicious agent. To take care of this aspect of security, we use &lt;a href=&quot;http://codex.wordpress.org/WordPress_Nonces&quot;&gt;nonces&lt;/a&gt;. A nonce is a number used once.&lt;br /&gt;
For a form, we generate a nonce field using &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/wp_nonce_field&quot;&gt;wp_nonce_field&lt;/a&gt; that will be included in our form as a hidden field:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;wp_nonce_field(&#39;my_nonce&#39;, &#39;my_nonce_submit&#39;);
&lt;/pre&gt;Because it’s now a hidden field in our form, it’ll come back to us when the form is submitted. We can then check that the nonce is valid using &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/wp_verify_nonce&quot;&gt;wp_verify_nonce&lt;/a&gt;:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;wp_verify_nonce($_POST[&#39;my_nonce_submit&#39;], &#39;my_nonce&#39;) )
&lt;/pre&gt;That will return true if the nonce verifies.&lt;br /&gt;
For a url (links in emails, browser urls), you can create a nonced url with &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/wp_nonce_url&quot;&gt;wp_nonce_url&lt;/a&gt;:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;$nonced_url = wp_nonce_url(&#39;http://my_site.com?action=register&amp;amp;id=123456&#39;, &#39;register_nonce&#39;);
&lt;/pre&gt;That would create a url like this…&lt;br /&gt;
&lt;code&gt;http://my_site.com?action=register&amp;amp;id=123456&amp;amp;_wpnonce=250d696dc6&lt;/code&gt;&lt;br /&gt;
…which you could send in a registration confirmation email. You would then check the incoming url for a nonce with the same id using the &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/&quot;&gt;check_admin_referer&lt;/a&gt; function and proceed with verification if true.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;if($_GET[&#39;action&#39;] == &#39;register&#39;){

 if(check_admin_referer(&#39;register_nonce&#39;)){

   if(verify_id($_GET[&#39;id&#39;])){

     echo &#39;Registration verified!&#39;;

   }

 }else{

   echo &#39;Registration verification FAILED!&#39;;

 }
}
&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Rule 04: Access Web Services Intelligently&lt;/h2&gt;The internet is full of web services providing us with everything from weather forecasts to stock quotes to the latest tweets from Twitter. The most efficient way for a plugin to access remote data is to use the &lt;a href=&quot;http://codex.wordpress.org/HTTP_API&quot;&gt;HTTP API&lt;/a&gt; which will handle your request in the background, using the most efficient of the five possible remote methods that PHP exposes. It’s like a one-stop shop for webservice access.&lt;br /&gt;
This uses the &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/wp_remote_get&quot;&gt;wp_remote_get&lt;/a&gt; method (a wrapper function of the HTTP class) to get a page body:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;$page_data = wp_remote_get(&#39;http://site.com/page&#39;);

if($page_data[&#39;response&#39;][&#39;code&#39;] == 200){

 $body = $page_data[&#39;body&#39;];

}
&lt;/pre&gt;Same with &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/wp_remote_post&quot;&gt;wp_remote_post&lt;/a&gt; to login:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;$args = array(
 &#39;login&#39; =&amp;gt; &#39;login_name&#39;,
 &#39;password&#39; =&amp;gt; &#39;my_password&#39;
 );

$response = wp_remote_post(&#39;http://site.com/login&#39;, $args);
&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Rule 05: Internationalization&lt;/h2&gt;This doesn’t have to be a big deal but is essential if you want to reach the widest audience possible. At a minimum all you need do is prepare your plugin with the _e() and __() functions and worry about the texdomain afterwards.&lt;br /&gt;
It’s all explained very well in &lt;a href=&quot;http://wp.tutsplus.com/tutorials/how-to-localize-wordpress-themes-and-plugins/&quot;&gt;this wp.tutsplus article&lt;/a&gt; by Tom McFarlin and &lt;a href=&quot;http://codex.wordpress.org/I18n_for_WordPress_Developers&quot;&gt;here at the WordPress codex&lt;/a&gt;.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Rule 06: Load Only What You Need&lt;/h2&gt;When you go away overnight, you don’t take as much with you as you would if you were going on vacation for a month. So treat your plugin the same way: only load the stylesheets, javascript and other scripts that you need for that page or section of the site. At the very least, don’t load admin scripts on the frontend and vice-versa.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;if(is_admin()){

 //load my plugin stuff for the admin pages

}else{

 //load my plugin stuff for the frontend

}
&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Rule 07: Tidy Up After Yourself&lt;/h2&gt;When you activate a plugin, you will see a deactivate link appear in the plugins admin page. But deactivating only stops the plugin from functioning. After deactivation, you then get a delete link. The delete link is the key to tidying up after yourself. It should really be called uninstall.&lt;br /&gt;
If you create a file named uninstall.php in the same directory as you plugin, the code in this file will be run when the user clicks delete.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;if(defined(&#39;WP_UNINSTALL_PLUGIN&#39;) ){

 //delete options, tables or anything else

}
&lt;/pre&gt;The above code checks for the WP_UNINSTALL_PLUGIN constant which WordPress sets when you hit delete. Then you can proceed to delete any options or custom tables that your plugin created when it was activated.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Bonus Tips&lt;/h2&gt;&lt;h3&gt;Turn on debug&lt;/h3&gt;The WordPress debugger will find errors in your code that while they may not crash you plugin should still be corrected to make sure that you’re doing things correctly. So, turn on WordPress debug by placing this in your /wp-config.php:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;define(&#39;WP_DEBUG&#39;, TRUE);
&lt;/pre&gt;&lt;h3&gt;Study the WordPress function library&lt;/h3&gt;WordPress often has functions that will solve a programming task in one function that you may have written many lines of code to achieve. Check out the &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/&quot;&gt;function library&lt;/a&gt; to make sure you’re not writing more code than you need to.&lt;br /&gt;
&lt;h3&gt;Get some peer review&lt;/h3&gt;Getting others to look at your code is a strong form of quality control. Other users will find faults that you haven’t noticed in your own testing. Don’t be afraid to post your code: everyone makes mistakes.&lt;br /&gt;
&lt;h3&gt;Don’t use deprecated functions!&lt;/h3&gt;WordPress is full of outdated functions that while still supported for current versions may not be in future releases. You may have used code from an old tutorial. Look it up in the &lt;a href=&quot;http://codex.wordpress.org/&quot;&gt;WordPress codex&lt;/a&gt; to see if it is marked as deprecated. There will be a link to the newer function.&lt;br /&gt;
&lt;h3&gt;Use a good WordPress code forum&lt;/h3&gt;If you have a problem, ask others. There are plenty of forums for WordPress solutions. One of my favorites is &lt;a href=&quot;http://wordpress.stackexchange.com/&quot;&gt;WordPress Answers&lt;/a&gt; from the wonderful Stack Exchange network.&lt;br /&gt;
&lt;h3&gt;Take some pride in your work!&lt;/h3&gt;It’s easy to release a plugin with a rider that you take no responsibility for the effects of your code. Now, that’s a necessary given: you can’t be responsible for how your plugin will be used. But you can take a professional pride in how you go about your work. Always do your best. Your reputation will be the better for it.&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/910534722329448513'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/910534722329448513'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2011/12/7-simple-rules-wordpress-plugin.html' title='7 Simple Rules: WordPress Plugin Development Best Practices'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-3239226478396565452</id><published>2011-12-02T13:17:00.001+08:00</published><updated>2011-12-02T13:17:46.156+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Changing Fonts"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorial"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress Themes"/><title type='text'>Changing the Fonts of Your WordPress – Part 2: Theme Integration</title><content type='html'>&quot;WordPress continually proves itself time, time, and again that it has very few limitations, and is rapidly pushing itself to being, if not the best, but certainly the most versatile CMS available. Out of the box it is certainly not perfect, but you can change it however you want. In the &lt;a href=&quot;http://wp.tutsplus.com/tutorials/changing-the-fonts-of-your-wordpress-site-part-1-using-a-plugin/&quot;&gt;previous tutorial&lt;/a&gt;, we went over how to add fonts to your theme via a plugin. Now, we’ll integrate font options directly into the theme’s options.&lt;br /&gt;
&lt;br /&gt;
Again, we will be using Google Web Fonts because it’s easy, fast and, most importantly, free. With Google Web Fonts there is no need to worry about using the proper &lt;a href=&quot;http://www.smashingmagazine.com/2011/03/02/the-font-face-rule-revisited-and-useful-tricks/&quot;&gt;font formats&lt;/a&gt;, everything is handled by Google. &lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 1 Add a Settings Page&lt;/h2&gt;First, make sure you have a theme options page. If you don’t know how to make one, I suggest reading &lt;a href=&quot;http://wp.tutsplus.com/tutorials/theme-development/create-a-settings-page-for-your-wordpress-theme/&quot;&gt;Create a Settings Page&lt;/a&gt; by Jarkko Laine. In this tutorial, I’m going to assume that you know the basics and build from there. So let’s go into our functions.php file and add a simple typography settings page:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;add_action( &#39;admin_menu&#39;, &#39;my_fonts&#39; );
function my_fonts() {
   add_theme_page( &#39;Fonts&#39;, &#39;Fonts&#39;, &#39;edit_theme_options&#39;, &#39;fonts&#39;, &#39;fonts&#39; );
}
&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Step 2 Add the Form&lt;/h2&gt;Now that we’ve added a settings page, we have to code the callback function we’re using to render the page itself, which would be &lt;i&gt;typography&lt;/i&gt;. All we need is a basic form that shows a dropdown of all the fonts that users can choose from and allow them to change it.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;function fonts() {
?&amp;gt;
   &amp;lt;div class=&quot;wrap&quot;&amp;gt;
       &amp;lt;div&amp;gt;&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;
       &amp;lt;h2&amp;gt;Fonts&amp;lt;/h2&amp;gt;

       &amp;lt;form method=&quot;post&quot; action=&quot;options.php&quot;&amp;gt;
           &amp;lt;?php wp_nonce_field( &#39;update-fonts&#39; ); ?&amp;gt;
           &amp;lt;?php settings_fields( &#39;fonts&#39; ); ?&amp;gt;
           &amp;lt;?php do_settings_sections( &#39;fonts&#39; ); ?&amp;gt;
           &amp;lt;?php submit_button(); ?&amp;gt;
       &amp;lt;/form&amp;gt;
   &amp;lt;/div&amp;gt;
&amp;lt;?php
}
&lt;/pre&gt;Okay, we’ve added our fonts form to the page, just some basic &lt;i&gt;settings_fields&lt;/i&gt;, but WordPress has no idea. Now we use the &lt;i&gt;admin_init&lt;/i&gt; action to initialize our settings and add the callbacks:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;add_action( &#39;admin_init&#39;, &#39;font_init&#39; );
function font_init() {
   register_setting( &#39;fonts&#39;, &#39;fonts&#39; );

   // Settings fields and sections
   add_settings_section( &#39;font_section&#39;, &#39;Typography Options&#39;, &#39;font_description&#39;, &#39;fonts&#39; );
   add_settings_field( &#39;body-font&#39;, &#39;Body Font&#39;, &#39;body_font_field&#39;, &#39;fonts&#39;, &#39;font_section&#39; );
}
&lt;/pre&gt;All we’re doing here is creating a settings section for our fonts forms and the field for a single font, you can add more if you want, in this tutorial I’m only going over the body tag. Just add more by copying that field and replace body with something else like h1. We also now have a setting called fonts, where we will be storing our font data/options. Let’s go ahead and define the callback functions, &lt;i&gt;font_description&lt;/i&gt; and &lt;i&gt;body_font_field&lt;/i&gt;.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;function font_description() {
   echo &#39;Use the form below to change fonts of your theme.&#39;;
}
function body_font_field() {
   $options = (array) get_option( &#39;fonts&#39; );
   $fonts = get_fonts();

   if ( isset( $options[&#39;body-font&#39;] ) )
       $current = $options[&#39;body-font&#39;];
   else
    $current = &#39;arial&#39;;

   ?&amp;gt;
       &amp;lt;select name=&quot;fonts[body-font]&quot;&amp;gt;
       &amp;lt;?php foreach( $fonts as $key =&amp;gt; $font ): ?&amp;gt;
           &amp;lt;option &amp;lt;?php if($key == $current) echo &quot;SELECTED&quot;; ?&amp;gt; value=&quot;&amp;lt;?php echo $key; ?&amp;gt;&quot;&amp;gt;&amp;lt;?php echo $font[&#39;name&#39;]; ?&amp;gt;&amp;lt;/option&amp;gt;
       &amp;lt;?php endforeach; ?&amp;gt;
       &amp;lt;/select&amp;gt;
   &amp;lt;?php
}
&lt;/pre&gt;We have to get the font options that we just made in the init action and the fonts we have available, &lt;i&gt;get_fonts()&lt;/i&gt;. Set the current font in the form to whatever is in the options, otherwise it’ll default to Arial. Then, use a foreach loop to go through our array of available fonts. You can also add a description or make it a brief tutorial on how to use it.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 3 Getting the Fonts&lt;/h2&gt;As you noticed in the previous snippet of code, we need to define the &lt;i&gt;get_fonts()&lt;/i&gt; function to retrieve the fonts we need. You can either include the Google Webfonts or just stick with the basic CSS fonts. We’ll just use an array to store all of the fonts, and then distinguish them by their font name. You can do this with any fonts, but for the purposes of this tutorial, we’ll just be using Arial, Ubuntu and Lobster.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;function get_fonts() {
   $fonts = array(
       &#39;arial&#39; =&amp;gt; array(
           &#39;name&#39; =&amp;gt; &#39;Arial&#39;,
           &#39;font&#39; =&amp;gt; &#39;&#39;,
           &#39;css&#39; =&amp;gt; &quot;font-family: Arial, sans-serif;&quot;
       ),
       &#39;ubuntu&#39; =&amp;gt; array(
           &#39;name&#39; =&amp;gt; &#39;Ubuntu&#39;,
           &#39;font&#39; =&amp;gt; &#39;@import url(http://fonts.googleapis.com/css?family=Ubuntu);&#39;,
           &#39;css&#39; =&amp;gt; &quot;font-family: &#39;Ubuntu&#39;, sans-serif;&quot;
       ),
       &#39;lobster&#39; =&amp;gt; array(
           &#39;name&#39; =&amp;gt; &#39;Lobster&#39;,
           &#39;font&#39; =&amp;gt; &#39;@import url(http://fonts.googleapis.com/css?family=Lobster);&#39;,
           &#39;css&#39; =&amp;gt; &quot;font-family: &#39;Lobster&#39;, cursive;&quot;
       )
   );

   return apply_filters( &#39;get_fonts&#39;, $fonts );
}
&lt;/pre&gt;&lt;strong&gt;Note:&lt;/strong&gt; You are not limited to only using Google Webfonts. If you want to use a custom font that is hosted on your FTP or on Amazon S3, then replace &lt;b&gt;@import&lt;/b&gt; with &lt;b&gt;@font-face&lt;/b&gt; and change the url to where your font file is hosted. &lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Step 4 Add the CSS&lt;/h2&gt;Before you apply any of fonts in your CSS, you should remove all instances of Google Webfonts of in your CSS files. This way when we make the import call to get the Ubuntu font, we’re not wasting an extra 100 ms getting the Lobster font too.&lt;br /&gt;
Now that we have all of our fonts set, we have to create a &lt;i&gt;wp_head&lt;/i&gt; action that adds the styling to your WordPress. If you are using this script for multiple tags, simply duplicate the code, just changing “body” to whichever tag you’re editing.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;add_action( &#39;wp_head&#39;, &#39;font_head&#39; );
function font_head() {
   $options = (array) get_option( &#39;fonts&#39; );
   $fonts = get_fonts();
   $body_key = &#39;arial&#39;;

   if ( isset( $options[&#39;body-font&#39;] ) )
       $body_key = $options[&#39;body-font&#39;];

   if ( isset( $fonts[ $body_key ] ) ) {
       $body_font = $fonts[ $body_key ];

       print_ &#39;&amp;lt;style&amp;gt;&#39;;
       echo $body_font[&#39;font&#39;];
       echo &#39;body { &#39; . $body_font[&#39;css&#39;] . &#39; } &#39;;
       echo &#39;&amp;lt;/style&amp;gt;&#39;;
   }
}
&lt;/pre&gt;We start by checking if a font is chosen in our options, if not, then set the font to our default, Arial. Now we print out the style tag, the import statement and our CSS code. &lt;br /&gt;
&lt;h3&gt;What You Get in the End&lt;/h3&gt;This is what you should’ve ended up with:&lt;br /&gt;
&lt;div&gt;&lt;img src=&quot;http://wptutsplus.s3.amazonaws.com/120_CustomTypeographyPt.2/ss.png&quot; /&gt;&lt;/div&gt;The final font options page. &lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Full Source Code&lt;/h2&gt;For anyone who is having some trouble putting it all together. Here is the full source code, ready to just paste into the functions.php file:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?
// Changing the Fonts of Your WordPress - Part 2: Theme Integration
// Tutorial on WP Tuts
// by Fouad Matin
// Please credit this tutorial, by putting a link back to http://wp.tutsplus.com/tutorials/changing-the-fonts-of-your-wordpress-site-part-2-theme-integration/
// Enjoy!
add_action( &#39;admin_menu&#39;, &#39;my_fonts&#39; );
function my_fonts() {
   add_theme_page( &#39;Fonts&#39;, &#39;Fonts&#39;, &#39;edit_theme_options&#39;, &#39;fonts&#39;, &#39;fonts&#39; );
}
function fonts() {
?&amp;gt;
   &amp;lt;div class=&quot;wrap&quot;&amp;gt;
       &amp;lt;div&amp;gt;&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;
       &amp;lt;h2&amp;gt;Fonts&amp;lt;/h2&amp;gt;

       &amp;lt;form method=&quot;post&quot; action=&quot;options.php&quot;&amp;gt;
           &amp;lt;?php wp_nonce_field( &#39;update-fonts&#39; ); ?&amp;gt;
           &amp;lt;?php settings_fields( &#39;fonts&#39; ); ?&amp;gt;
           &amp;lt;?php do_settings_sections( &#39;fonts&#39; ); ?&amp;gt;
           &amp;lt;?php submit_button(); ?&amp;gt;
           &amp;lt;/form&amp;gt;
       &amp;lt;img style=&quot;float:right; border:0;&quot; src=&quot;http://i.imgur.com/1qqJG.png&quot; /&amp;gt;
   &amp;lt;/div&amp;gt;
&amp;lt;?php
}

add_action( &#39;admin_init&#39;, &#39;my_register_admin_settings&#39; );
function my_register_admin_settings() {
   register_setting( &#39;fonts&#39;, &#39;fonts&#39; );
   add_settings_section( &#39;font_section&#39;, &#39;Font Options&#39;, &#39;font_description&#39;, &#39;fonts&#39; );
   add_settings_field( &#39;body-font&#39;, &#39;Body Font&#39;, &#39;body_font_field&#39;, &#39;fonts&#39;, &#39;font_section&#39; );
   add_settings_field( &#39;h1-font&#39;, &#39;Header 1 Font&#39;, &#39;h1_font_field&#39;, &#39;fonts&#39;, &#39;font_section&#39; );
}
function font_description() {
   echo &#39;Use the form below to change fonts of your theme.&#39;;
}
function get_fonts() {
   $fonts = array(
       &#39;arial&#39; =&amp;gt; array(
           &#39;name&#39; =&amp;gt; &#39;Arial&#39;,
           &#39;font&#39; =&amp;gt; &#39;&#39;,
           &#39;css&#39; =&amp;gt; &quot;font-family: Arial, sans-serif;&quot;
       ),
       &#39;ubuntu&#39; =&amp;gt; array(
           &#39;name&#39; =&amp;gt; &#39;Ubuntu&#39;,
           &#39;font&#39; =&amp;gt; &#39;@import url(http://fonts.googleapis.com/css?family=Ubuntu);&#39;,
           &#39;css&#39; =&amp;gt; &quot;font-family: &#39;Ubuntu&#39;, sans-serif;&quot;
       ),
       &#39;lobster&#39; =&amp;gt; array(
           &#39;name&#39; =&amp;gt; &#39;Lobster&#39;,
           &#39;font&#39; =&amp;gt; &#39;@import url(http://fonts.googleapis.com/css?family=Lobster);&#39;,
           &#39;css&#39; =&amp;gt; &quot;font-family: &#39;Lobster&#39;, cursive;&quot;
       )
   );

   return apply_filters( &#39;get_fonts&#39;, $fonts );
}
function body_font_field() {
   $options = (array) get_option( &#39;fonts&#39; );
   $fonts = get_fonts();
   $current = &#39;arial&#39;;

   if ( isset( $options[&#39;body-font&#39;] ) )
       $current = $options[&#39;body-font&#39;];
   ?&amp;gt;
       &amp;lt;select name=&quot;fonts[body-font]&quot;&amp;gt;
       &amp;lt;?php foreach( $fonts as $key =&amp;gt; $font ): ?&amp;gt;
           &amp;lt;option &amp;lt;?php if($key == $current) echo &quot;SELECTED&quot;; ?&amp;gt; value=&quot;&amp;lt;?php echo $key; ?&amp;gt;&quot;&amp;gt;&amp;lt;?php echo $font[&#39;name&#39;]; ?&amp;gt;&amp;lt;/option&amp;gt;
       &amp;lt;?php endforeach; ?&amp;gt;
       &amp;lt;/select&amp;gt;
   &amp;lt;?php
}
function h1_font_field() {
   $options = (array) get_option( &#39;fonts&#39; );
   $fonts = get_fonts();
   $current = &#39;arial&#39;;

   if ( isset( $options[&#39;h1-font&#39;] ) )
       $current = $options[&#39;h1-font&#39;];

   ?&amp;gt;
       &amp;lt;select name=&quot;fonts[h1-font]&quot;&amp;gt;
       &amp;lt;?php foreach( $fonts as $key =&amp;gt; $font ): ?&amp;gt;
           &amp;lt;option &amp;lt;?php if($key == $current) echo &quot;SELECTED&quot;; ?&amp;gt; value=&quot;&amp;lt;?php echo $key; ?&amp;gt;&quot;&amp;gt;&amp;lt;?php echo $font[&#39;name&#39;]; ?&amp;gt;&amp;lt;/option&amp;gt;
       &amp;lt;?php endforeach; ?&amp;gt;
       &amp;lt;/select&amp;gt;
   &amp;lt;?php
}

add_action( &#39;wp_head&#39;, &#39;font_head&#39; );
function font_head() {
   $options = (array) get_option( &#39;fonts&#39; );
   $fonts = get_fonts();
   $body_key = &#39;arial&#39;;

   if ( isset( $options[&#39;body-font&#39;] ) )
       $body_key = $options[&#39;body-font&#39;];

   if ( isset( $fonts[ $body_key ] ) ) {
       $body_font = $fonts[ $body_key ];

       echo &#39;&amp;lt;style&amp;gt;&#39;;
       echo $body_font[&#39;font&#39;];
       echo &#39;body  { &#39; . $body_font[&#39;css&#39;] . &#39; } &#39;;
       echo &#39;&amp;lt;/style&amp;gt;&#39;;
   }

   $h1_key = &#39;arial&#39;;

   if ( isset( $options[&#39;h1-font&#39;] ) )
       $h1_key = $options[&#39;h1-font&#39;];

   if ( isset( $fonts[ $h1_key ] ) ) {
       $h1_key = $fonts[ $h1_key ];

       echo &#39;&amp;lt;style&amp;gt;&#39;;
       echo $h1_key[&#39;font&#39;];
       echo &#39;h1  { &#39; . $h1_key[&#39;css&#39;] . &#39; } &#39;;
       echo &#39;&amp;lt;/style&amp;gt;&#39;;
   }
}
?&amp;gt;
&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;By now, you should know how to add a font settings page, get fonts from the Google Webfonts directory, and apply those fonts to the theme. If you have any additional suggestions or questions regarding custom typography, feel free to leave a comment!&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/3239226478396565452'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/3239226478396565452'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2011/12/changing-fonts-of-your-wordpress-part-2.html' title='Changing the Fonts of Your WordPress – Part 2: Theme Integration'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-8466638696314814455</id><published>2011-11-18T10:42:00.001+08:00</published><updated>2011-11-18T10:42:51.832+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CodeCanyon"/><category scheme="http://www.blogger.com/atom/ns#" term="November Edition"/><category scheme="http://www.blogger.com/atom/ns#" term="Showcase"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress Plugins"/><title type='text'>Top WordPress Plugins from CodeCanyon: November Edition</title><content type='html'>&quot;WordPress is a powerful content management system, and the vast array of plugins available certainly helps. CodeCanyon has long been a great place to find &lt;a href=&quot;http://codecanyon.net/category/plugins/wordpress&quot;&gt;top WordPress plugins&lt;/a&gt;. From content and security to galleries and sliders, there’s plenty to choose from. Here’s a quick rundown of some of the &lt;a href=&quot;http://codecanyon.net/category/plugins/wordpress?sort_by=sales_count&amp;amp;page=1&amp;amp;categories=plugins%2Fwordpress&quot;&gt;most popular WordPress plugins&lt;/a&gt; available at CodeCanyon.&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt; 1. &lt;a href=&quot;http://codecanyon.net/item/ubermenu-wordpress-mega-menu-plugin/154703&quot;&gt;UberMenu&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/ubermenu-wordpress-mega-menu-plugin/154703&quot;&gt; &lt;img alt=&quot;UberMenu - WordPress Mega Menu Plugin - CodeCanyon Item for Sale&quot; src=&quot;http://0.s3.envato.com/files/1967560/megamenupreview.1.1.2.jpg&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;UberMenu is a user-friendly, highly customizable mega menu ( or mega drop down menu ) WordPress plugin. It works out of the box with the WordPress 3 Menu Management System, making it simple to get started but powerful enough to create highly customized and creative mega menu configurations.&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 2. &lt;a href=&quot;http://codecanyon.net/item/ubillboard-premium-slider-for-wordpress/124783&quot;&gt;uBillboard Slider&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/ubillboard-premium-slider-for-wordpress/124783&quot;&gt; &lt;img alt=&quot;uBillboard - Premium Slider for WordPress - CodeCanyon Item for Sale&quot; src=&quot;http://1.s3.envato.com/files/4746524/preview.jpg&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;uBillboard is a Premium Slider for WordPress. It is a jQuery based slider with a multitude of transitions and options for you to be able to customize it to your needs while not overwhelming you with options you never wanted or needed. Version 3 is a revolutionary release with most of the codebase rewritten from scratch. This has enabled us to integrate many features that you have been requesting during the first year. &lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 3. &lt;a href=&quot;http://codecanyon.net/item/video-gallery-wordpress-plugin-w-youtube-vimeo-/157782&quot;&gt;WordPress Video Gallery&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/video-gallery-wordpress-plugin-w-youtube-vimeo-/157782&quot;&gt; &lt;img alt=&quot;Video Gallery WordPress Plugin /w YouTube, Vimeo  - CodeCanyon Item for Sale&quot; src=&quot;http://2.s3.envato.com/files/2176087/preview-wordpress-youtube-video-gallery.jpg&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;The most advanced stock video gallery in the world! Now as a WordPress plugin!&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 4. &lt;a href=&quot;http://codecanyon.net/item/styles-with-shortcodes-for-wordpress/142221&quot;&gt;Styles with Shortcodes&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/styles-with-shortcodes-for-wordpress/142221&quot;&gt; &lt;img alt=&quot;Styles with Shortcodes for WordPress - CodeCanyon Item for Sale&quot; src=&quot;http://2.s3.envato.com/files/7785036/01-styles-with-shortcodes-1-7-6-preview.jpg&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;This plugin lets you customize content faster and easier than ever before by using Shortcodes. Choose from 100 built in Shortcodes!&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 5. &lt;a href=&quot;http://codecanyon.net/item/lightbox-evolution-for-wordpress/119478&quot;&gt;Lightbox Evolution&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/lightbox-evolution-for-wordpress/119478&quot;&gt; &lt;img alt=&quot;Lightbox Evolution for WordPress - CodeCanyon Item for Sale&quot; src=&quot;http://2.s3.envato.com/files/1638942/1.__large_preview.jpg&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;Lightbox Evolution is a tool for displaying images, html content, maps, and videos in a “lightbox” style that floats overtop of web page. Using Lightbox Evolution, website authors can showcase a wide assortment of media in all major browsers without navigating users away from the linking page.&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 6. &lt;a href=&quot;http://codecanyon.net/item/font-uploader/110175&quot;&gt;Font Uploader&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/font-uploader/110175&quot;&gt; &lt;img alt=&quot;Font Uploader - CodeCanyon Item for Sale&quot; src=&quot;http://0.s3.envato.com/files/1531976/01-screenshot.png&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;This plugin lets you upload your own font files and apply them to any element of your website without requiring a knowledge of html or css. &lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 7. &lt;a href=&quot;http://codecanyon.net/item/custom-backgrounds-for-wordpress/121983&quot;&gt;Custom Backgrounds&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/custom-backgrounds-for-wordpress/121983&quot;&gt; &lt;img alt=&quot;Custom Backgrounds for WordPress - CodeCanyon Item for Sale&quot; src=&quot;http://3.s3.envato.com/files/6222530/01-custom-backgrounds-3-1-2-preview.jpg&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;With WordPress 3.0 a new feature was introduced called custom backgrounds for WordPress themes. This feature gives you the ability to add custom backgrounds on your site, which will give your site a unique touch.&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 8. &lt;a href=&quot;http://codecanyon.net/item/wordpress-email-newsletter-plugin/149180&quot;&gt;WordPress Email Newsletter&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/wordpress-email-newsletter-plugin/149180&quot;&gt; &lt;img alt=&quot;WordPress Email Newsletter Plugin - CodeCanyon Item for Sale&quot; src=&quot;http://3.s3.envato.com/files/1545822/1preview-wp-newsletter.__large_preview.jpg&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;Easily send mass emails to your existing wordpress user database.&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 9. &lt;a href=&quot;http://codecanyon.net/item/5sec-google-maps/152372&quot;&gt;5 Second Google Maps&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/5sec-google-maps/152372&quot;&gt; &lt;img alt=&quot;5sec Google Maps - CodeCanyon Item for Sale&quot; src=&quot;http://2.s3.envato.com/files/1645706/5sec-google-maps-preview.jpg&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;Simple Google Maps integration with no API keys, no setup and no code editing.&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 10. &lt;a href=&quot;http://codecanyon.net/item/special-recent-posts-pro/552356&quot;&gt;Special Recent Posts&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/special-recent-posts-pro/552356&quot;&gt; &lt;img alt=&quot;Special Recent Posts PRO - CodeCanyon Item for Sale&quot; src=&quot;http://3.s3.envato.com/files/6404801/srppro-590x300.jpg&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;It’s the perfect solution for online magazines or simple blogs and it comes with more than 60+ customization options.&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 11. &lt;a href=&quot;http://codecanyon.net/item/security-ninja/577696&quot;&gt;Security Ninja&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/security-ninja/577696&quot;&gt; &lt;img alt=&quot;Security Ninja - CodeCanyon Item for Sale&quot; src=&quot;http://2.s3.envato.com/files/7407426/security-ninja-preview-11.png&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;Years of industry’s best practices on security combined in one plugin! Perform 25+ security tests including brute-force attacks.&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 12. &lt;a href=&quot;http://codecanyon.net/item/visual-composer-for-wordpress/242431&quot;&gt;Visual Composer&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/visual-composer-for-wordpress/242431&quot;&gt; &lt;img alt=&quot;Visual Composer for WordPress - CodeCanyon Item for Sale&quot; src=&quot;http://2.s3.envato.com/files/2474512/preview.jpg&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;Add columns/elements with one click, then use your mouse to drag elements around to re-arrange them. Control element width with simple mouse clicking.&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 13. &lt;a href=&quot;http://codecanyon.net/item/foobar-wordpress-notification-bars/411466&quot;&gt;Foobar Notification Bars&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/foobar-wordpress-notification-bars/411466&quot;&gt; &lt;img alt=&quot;Foobar - WordPress Notification Bars - CodeCanyon Item for Sale&quot; src=&quot;http://1.s3.envato.com/files/7228309/foobar-WP-590x300.png&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;A WordPress plugin for adding great looking notification bars to your site.&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 14. &lt;a href=&quot;http://codecanyon.net/item/socialpop-a-social-media-plugin-for-wordpress/110958&quot;&gt;SocialPop&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/socialpop-a-social-media-plugin-for-wordpress/110958&quot;&gt; &lt;img alt=&quot;SocialPop: A Social Media Plugin for WordPress - CodeCanyon Item for Sale&quot; src=&quot;http://3.s3.envato.com/files/2660994/preview-template.jpg&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;This plug-in adds social media sharing options under the content section on WordPress Posts and Pages. Currently supports sharing for 26 of some of the most popular social media sites.&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 15. &lt;a href=&quot;http://codecanyon.net/item/estro-jquery-ken-burns-slider-wordpress-plugin/356713&quot;&gt;Estro Slider&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/estro-jquery-ken-burns-slider-wordpress-plugin/356713&quot;&gt; &lt;img alt=&quot;Estro - jQuery Ken Burns slider - wordpress plugin - CodeCanyon Item for Sale&quot; src=&quot;http://3.s3.envato.com/files/4252686/Estro_KenBurns_Slideshow_Wordpress_Premium_Plugin.jpg&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;We have added a custom admin panel which will allow you to customise all aspects of your slider without having to touch a line of code. Drag n drop arranging of your slides, multiple slider insertion, skin selection, Ken Burns customisation, you name it, we’ve included it.&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 16. &lt;a href=&quot;http://codecanyon.net/item/premium-pricing-tables-plugin/163730&quot;&gt;Premium Pricing Tables&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/premium-pricing-tables-plugin/163730&quot;&gt; &lt;img alt=&quot;Premium Pricing Tables Plugin - CodeCanyon Item for Sale&quot; src=&quot;http://3.s3.envato.com/files/2485904/01_table.png&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;WP Mega Tables are the perfect solution for those who are in need of a well designed and more importantly a easy to use pricing table in there wordpress themes.&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 17. &lt;a href=&quot;http://codecanyon.net/item/flip-book-wordpress-plugin/152641&quot;&gt;Flip Book&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/flip-book-wordpress-plugin/152641&quot;&gt; &lt;img alt=&quot;Flip Book WordPress Plugin - CodeCanyon Item for Sale&quot; src=&quot;http://2.s3.envato.com/files/1552092/inline.jpg&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;Flip Book WordPress Pluginis based is on XML Flip Book / AS3 one of the three top selling items of all times on ActiveDen . It has been built from scratch. Almost everything you see on the page is easily customizable through the WordPress administration panel – easy installation, no coding skills required.&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 18. &lt;a href=&quot;http://codecanyon.net/item/jgallery/109241&quot;&gt;jGallery&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/jgallery/109241&quot;&gt; &lt;img alt=&quot;jGallery - CodeCanyon Item for Sale&quot; src=&quot;http://2.s3.envato.com/files/8095261/1_demo_image.jpg&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;The jGallery WordPress Plugin gives you a simple and customizable way to create a gallery on any post, page, or sidebar. You have the option to use widgets, shortcodes, or to manually insert your gallery directory into the template files.&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 19. &lt;a href=&quot;http://codecanyon.net/item/ninety-ajax-loginregister-for-wordpress/158711&quot;&gt;Ninety Ajax Login/Register&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/ninety-ajax-loginregister-for-wordpress/158711&quot;&gt; &lt;img alt=&quot;Ninety Ajax Login/Register for WordPress - CodeCanyon Item for Sale&quot; src=&quot;http://3.s3.envato.com/files/1531193/1_overview.jpg&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;Our Sidebar Login/Register plugin for WordPress does exactly what it says on the tin; Logins and Registrations with a touch of AJAX magic. Simple! It also has a nice ‘logged in’ view, and a lost password form for those forgetful folk.&lt;/blockquote&gt;&lt;hr /&gt;&lt;h2&gt; 20. &lt;a href=&quot;http://codecanyon.net/item/slider-evolution-for-wordpress/244096&quot;&gt;Slider Evolution&lt;/a&gt; &lt;/h2&gt;&lt;div&gt;&lt;a href=&quot;http://codecanyon.net/item/slider-evolution-for-wordpress/244096&quot;&gt; &lt;img alt=&quot;Slider Evolution for WordPress - CodeCanyon Item for Sale&quot; src=&quot;http://2.s3.envato.com/files/2490729/preview.jpg&quot; /&gt; &lt;/a&gt; &lt;/div&gt;&lt;blockquote&gt;Slider Evolution is a JQuery plugin that lets you easily create powerful javascript sliders with very nice transition effects. Enhance your website by adding a unique and attractive slider!&quot;&lt;/blockquote&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/8466638696314814455'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/8466638696314814455'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2011/11/top-wordpress-plugins-from-codecanyon.html' title='Top WordPress Plugins from CodeCanyon: November Edition'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-2054536673473886458</id><published>2011-11-18T10:19:00.001+08:00</published><updated>2011-11-18T10:20:12.904+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Conditional Statements"/><category scheme="http://www.blogger.com/atom/ns#" term="Tags"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorial"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><title type='text'>PHP for WordPress: Mastering Conditional Statements and Tags</title><content type='html'>&quot;The conditional statements feature is an extremely useful and powerful feature in WordPress; still it remains unused in the development process. You can achieve many things by the simple and smart use of these statements. Sometimes when you need specific text or a unique image to appear on a specific page and not on any other pages in your site, by using conditional statements along with WordPress conditional tags you can achieve this easily without creating multiple pages or templates.&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;What are Conditional Statements?&lt;/h2&gt;PHP “&lt;strong&gt;If&lt;/strong&gt;” statements are generally known as &lt;strong&gt;conditional &lt;/strong&gt;statements. These statements are used within WordPress Theme files along with certain WordPresss functions defining  the logic to inform the WordPress database what and how the content should be  displayed based on a given criteria. These statements are very important in  defining WordPress themes and are similar to creating &lt;a href=&quot;http://wp.tutsplus.com/articles/wordpress-cheat-sheets-template-heirarchy-map/&quot;&gt;template hierarchy&lt;/a&gt;. &lt;br /&gt;
Basic Conditional Statements look like this:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php if ( ) { ?&amp;gt;......&amp;lt;?php  } ?&amp;gt;
&lt;/pre&gt;In layman’s terms, this is pretty simple:&lt;br /&gt;
&lt;blockquote&gt;If “something” exists/happens/etc., Do something.&lt;/blockquote&gt;You can (and probably will) use this type of general “if” statement inside WordPress all the time. WordPress has it’s own set of conditional statements as well though, so let’s take a peek at what those look like:&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;A List of Important WordPress Conditional Tags&lt;/h2&gt;Different  types of Conditional Tags exist within Conditional Statements. These tags fetch  particular information from the WordPress database. These conditional tags are  defined for many different items in WordPress e.g. posts, tags, texts, images,  categories etc. &lt;br /&gt;
Some of the most popular ones are-&lt;br /&gt;
1.&lt;strong&gt;is_page()  -&lt;/strong&gt; If you want to apply a certain condition to one of your specific page, e.g.  “Contact Us” page. You can use this tag to refer  to that page using its &lt;strong&gt;database ID  number&lt;/strong&gt; or &lt;strong&gt;title&lt;/strong&gt; or &lt;strong&gt;slug/name&lt;/strong&gt;. For instance:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;is_page(’2&#39;)
or
is_page(‘Contact”)&lt;/pre&gt;2. &lt;strong&gt;is_category()&lt;/strong&gt; –  If you want to apply a certain condition to a specific category page e.g. Books,  then this tag can be used to refer to that page using its &lt;strong&gt;database ID number&lt;/strong&gt; or &lt;strong&gt;title&lt;/strong&gt; or &lt;strong&gt;slug/name&lt;/strong&gt;. For instance:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;is_category(“4”) &lt;/pre&gt;3. &lt;strong&gt;is_home()&lt;/strong&gt; –  This is used to refer to your home page.&lt;br /&gt;
4. &lt;strong&gt;is_single()&lt;/strong&gt; –  This is used for single page blogs, single posts or attachments.&lt;br /&gt;
5. &lt;strong&gt;is_tag()&lt;/strong&gt; –  This is used to refer to a tag archive page. It works similar to category page.&lt;br /&gt;
6..&lt;strong&gt;is_archive()&lt;/strong&gt; –  This is used to refer to archived pages.&lt;br /&gt;
7.&lt;strong&gt; is_search()&lt;/strong&gt; –  This is used to refer to search results pages.&lt;br /&gt;
8. &lt;strong&gt;is_404()&lt;/strong&gt; –  This is used to refer to a &lt;em&gt;HTTP 404: Not Found&lt;/em&gt; error page.&lt;br /&gt;
9. &lt;strong&gt;is_author()  – &lt;/strong&gt;This  is used to refer to an author archived page.&lt;br /&gt;
10&lt;strong&gt;. is_comments_popup()  – &lt;/strong&gt;This  is used to refer to a comment popup window.&lt;br /&gt;
You  can get the complete list of tags on the WordPress &lt;a href=&quot;http://codex.wordpress.org/Conditional_Tags&quot;&gt;Codex&lt;/a&gt; page.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Learning by Example&lt;/h2&gt;This is all fine and well in theory, but let’s dig into some practical code examples of these conditional statements in action.&lt;br /&gt;
&lt;h3&gt;Example #1:&lt;/h3&gt;What should be the code to &lt;strong&gt;display an image on your first page, nothing on the second and some text on the third page?&lt;/strong&gt; (These pages are hypothetical, you can replace them with your own page names, like Contact Us, About, Information, etc…)&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php  if ( is_page(&#39;First_Page&#39;) ) { ?&amp;gt;
 &amp;lt;img src=&quot;image.gif&quot; /&amp;gt;
 &amp;lt;?php  } elseif ( is_page(&#39;Third_Page&#39;) ) { ?&amp;gt;
 &amp;lt;p&amp;gt;Here is some text….&amp;lt;/p&amp;gt;
 &amp;lt;?php  } else { ?&amp;gt;
 &amp;lt;?php  } ?&amp;gt; &lt;/pre&gt;&lt;strong&gt;Please Note&lt;/strong&gt;-&lt;br /&gt;
These codes should be written in your writable theme editor on the &lt;strong&gt;page.php&lt;/strong&gt; file where you want the conditional content to appear.&lt;br /&gt;
&lt;strong&gt;Extra Note:&lt;/strong&gt; This is a multi-conditional statement (see the multiple “if, elseif, else…” running logic?) This code checks for the appropriate page using the tags and then displays the items accordingly. You can use unlimited conditions within a code.&lt;br /&gt;
&lt;em&gt;is_page(array(‘First_Page’,’Second_Page’))&lt;/em&gt; can be used to display something on both the pages.&lt;br /&gt;
&lt;hr /&gt;&lt;h3&gt;Example #2:&lt;/h3&gt;How to display a text on either a single post OR a particular category page?&lt;br /&gt;
Here  you need to use the “||” symbol to display something if any one of the given condition is met. If no condition is satisfied, it displays nothing.&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php  if(is_category(Category_Page) ) || ( is_single(Single_Page))  { ?&amp;gt;
 &amp;lt;p&amp;gt;Display  this text….&amp;lt;/p&amp;gt;
 &amp;lt;?php  } else { ?&amp;gt;
 &amp;lt;?php  } ?&amp;gt;
 &lt;/pre&gt;&lt;strong&gt;Extra Note:&lt;/strong&gt; We used the “||” here, which checks for any of the conditions… Alternatively, we could use the “&amp;amp;&amp;amp;” to create an AND condition, in which both the condition &lt;strong&gt;must &lt;/strong&gt;be met in order to display the item. The “!” is used for excluding something from the list. &lt;br /&gt;
E.g. &lt;em&gt;!( is_page(Excluded_PageName))&lt;/em&gt;. You can also use variables to refer to the sub pages of a parent page. E.g.&lt;em&gt; post-&amp;gt;post_parent==&quot;Parent_Page_Name&lt;/em&gt;&quot;&lt;br /&gt;
&lt;hr /&gt;&lt;h3&gt;Example #3:  &lt;/h3&gt;&lt;h5&gt;How to load other items like CSS files, Java Script files in one of my pages?&lt;/h5&gt;This code snippet will show you how to display contact form files only on your  Contact Us page. &lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php  if ( is_page( &#39;contact_us_page&#39; ) ) {   ?&amp;gt;
 &amp;lt;link  rel=&#39;stylesheet&#39; href=&#39;/contactusform.css&#39; type=&#39;text/css&#39; media=&#39;all&#39; /&amp;gt;
 &amp;lt;script  type=&#39;text/javascript&#39; src=k&#39;/jqueryform.js&#39;&amp;gt;&amp;lt;/script&amp;gt;
 &amp;lt;script  type=&#39;text/javascript&#39; src=&#39;/spec_forms.js&#39;&amp;gt;&amp;lt;/script&amp;gt;
 &amp;lt;?php  } ?&amp;gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Example #4:  &lt;/h3&gt;&lt;h5&gt;How to use conditional tags in your custom post types?&lt;/h5&gt;The mixture of custom post types and conditional tags makes a smart way to display information to the users. The following code snippet will enable you to display contact information at the end of your review posts. &lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php  if ( review_entry&#39; == get_post_type() ) { ?&amp;gt;
 &amp;lt;div  id=&quot;reviewcontact&quot;&amp;gt;
 &amp;lt;p&amp;gt;If  you&#39;re impressed by the  reviews, kindly  contact us asap. Give us a call or &amp;lt;a href=&quot;/contact&quot;  title=&quot;Contact Us&quot;&amp;gt;CLICK HERE&amp;lt;/a&amp;gt; to send us a message!&amp;lt;/p&amp;gt;
 &amp;lt;/div&amp;gt;
 &amp;lt;?php  } ?&amp;gt;&lt;/pre&gt;&lt;hr /&gt;&lt;h3&gt;Example #5:  &lt;/h3&gt;&lt;h5&gt;How to check if a “post thumbnail” image has been uploaded or not?&lt;/h5&gt;The following code checks for an image and display another if not found.  &lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php  if(posted_thumbnail()) {
 show_thumbnail();
 }  else {?&amp;gt;
 &amp;lt;img src=&quot;&amp;lt;?php  bloginfo(&#39;template_directory&#39;);?&amp;gt;/images/default_Image.gif&quot; alt=&quot;Image not Displayed&quot;&amp;gt;
 &amp;lt;?php  }?&amp;gt;
&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;Thus by mastering these little conditional tags and mixing them with php conditional  statements, you can write less and do more in your WordPress site. This not only helps you during the maintenance of your site but it also helps to take advantage of the highly useful WordPress database architecture. &lt;br /&gt;
If you guys want to see more of these “basic PHP” tutorials for WordPress, let us know in the comments!&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/2054536673473886458'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/2054536673473886458'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2011/11/php-for-wordpress-mastering-conditional.html' title='PHP for WordPress: Mastering Conditional Statements and Tags'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-7611324442703216622</id><published>2011-11-17T12:30:00.000+08:00</published><updated>2011-11-17T12:30:46.258+08:00</updated><title type='text'>Load jQuery From Google CDN With Local Fallback For WordPress</title><content type='html'>&quot;In this tutorial we are going to cover why loading jQuery from the Google CDN with a local file fallback is important, and how to set this up for WordPress. If you’re still trying to self-host your own copy of jQuery (or lots of other script libraries for that matter!), this is a great way to quickly improve your workflow.

&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;When I first took a look at &lt;a href=&quot;http://html5boilerplate.com/&quot; title=&quot;HTML5 Boilerplate&quot;&gt;HTML5 Boilerplate&lt;/a&gt; there was this great code snippet for loading jQuery from the Google CDN with a&lt;strong&gt; local file fallback&lt;/strong&gt;.&lt;/p&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;script src=&quot;//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script&amp;gt;window.jQuery || document.write(&quot;&amp;lt;script src=&#39;js/libs/jquery-1.6.4.min.js&#39;&amp;gt;\x3C/script&amp;gt;&quot;)&amp;lt;/script&amp;gt;
&lt;/pre&gt;
&lt;p&gt;This was the greatest thing I’d seen on the topic of loading scripts for a while… Unfortunately, this doesn’t play well with WordPress, because we should be loading our JavaScripts using &lt;strong&gt;wp_enqueue_script&lt;/strong&gt;, which we recently looked at in &lt;a href=&quot;http://wp.tutsplus.com/tutorials/the-ins-and-outs-of-the-enqueue-script-for-wordpress-themes-and-plugins/&quot;&gt;this article on using enqueue&lt;/a&gt; to properly load scripts inside WordPress.&lt;/p&gt;
&lt;p&gt;So, here’s a way to accomplish the same thing in WordPress.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt; Why Use a Local Fallback File?&lt;/h2&gt;
&lt;p&gt;Why would I use a local fallback file at all?&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;first&lt;/strong&gt; reason for using a local file fallback is for your local development environment. Internet access isn’t always available when you’re working on your project. Let’s say you work for a web development firm and the companies internet server goes down. If you’ve been working on a script that is jQuery dependent, and you’ve been calling jQuery from the Google CDN. Well, you’re out of luck. Even if you have jQuery cached, eventually you’ll have to clear the cache to make sure the site is rendering properly, or switch to another browser to check cross compatibility.&lt;/p&gt;
&lt;p&gt;At that point, you might as well take a long lunch. Which I’m sure your manager won’t be too pleased with. If you’re getting paid by the hour, no internet access isn’t an excuse for not working.
&lt;/p&gt;
&lt;p&gt;The same could be said if you were at home and the internet went down… or if you traveled to the latest WordCamp and couldn’t get internet access in your hotel. There’s nothing more annoying than being in the zone and having to stop just because you can’t load jQuery.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;second&lt;/strong&gt; reason is what if Google goes down. Besides the usual rioting in the streets, airplanes falling from the sky, and a plague of frogs. Your site will break, and we can’t have that. The rest we can deal with. Just find a, out of the way, cave and cook up some frog legs.&lt;/p&gt;
&lt;p&gt;Seriously though, it’s not likely that Google will ever go down. Google is so big that I’m sure they have backup servers for their backup servers, but you never know. Isn’t better to have a backup of you own, just in case?&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt; &lt;span&gt;Step 1&lt;/span&gt; Where to Start &lt;/h2&gt;
&lt;p&gt;The script is going to be placed in you functions.php file.&lt;/p&gt;
&lt;p&gt;The first thing we need to do is define some variables&lt;/p&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php
$url = &#39;http://ajax.googleapis.com/ajax/libssss/jquery/1.6.4/jquery.min.js&#39;; // the URL to check against
$test_url = @fopen($url,&#39;r&#39;); // test parameters
?&amp;gt;
&lt;/pre&gt;
&lt;p&gt;$url is the URL the script is going to use to test against. In this case, we’re testing is the jQuery file on the Google CDN.&lt;/p&gt;
&lt;p&gt;$test_url is setting up the parameters for the test.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt; &lt;span&gt;Step 2&lt;/span&gt; Setting up the Test &lt;/h2&gt;
&lt;p&gt;Now, let’s set up the main part of the test&lt;/p&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php
if($test_url !== false) { // test if the URL exists
   //load the external script
} else {
   //load the local script
}?&amp;gt;
&lt;/pre&gt;
&lt;p&gt;if($test_url !== false) is testing to see if it can open the URL we defined in the variable $url. If it can it will load the external script on the CDN. Else, if can’t open the URL it loads the local script on your server. &lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt; &lt;span&gt;Step 3&lt;/span&gt; Loading the External Script Function &lt;/h2&gt;
&lt;p&gt;Here we add the function to load the external CDN file&lt;/p&gt;
&lt;pre name=&quot;code&quot;&gt;if($test_url !== false) { // test if the URL exists
   function load_external_jQuery() { // load external file
       wp_deregister_script( &#39;jquery&#39; ); // deregisters the default WordPress jQuery
       wp_register_script(&#39;jquery&#39;, &#39;http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js&#39;); // register the external file
       wp_enqueue_script(&#39;jquery&#39;); // enqueue the external file
   }
 add_action(&#39;wp_enqueue_scripts&#39;, &#39;load_external_jQuery&#39;); // initiate the function
}
&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;wp_deregister_script deregisters the default jQuery that comes with WordPress. It’s usually an older version, so I like to use the the most recent version.&lt;/li&gt;
&lt;li&gt;wp_register_script registers the external CDN jQuery with WordPress.&lt;/li&gt;
&lt;li&gt;wp_enqueue_script will enqueue the newly register version.&lt;/li&gt;
&lt;li&gt;add_action will initiate the function.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h2&gt; &lt;span&gt;Step 4&lt;/span&gt; Loading the Local Script Function &lt;/h2&gt;
&lt;p&gt; An else statement is used to load the local file is the test isn’t able to open the external CDN file&lt;/p&gt;
&lt;pre name=&quot;code&quot;&gt;else {
   function load_local_jQuery() {
       wp_deregister_script(&#39;jquery&#39;); // deregisters the default WordPress jQuery
       wp_register_script(&#39;jquery&#39;, bloginfo(&#39;template_url&#39;).&#39;/js/libs/jquery-1.6.1.min.js&#39;, __FILE__, false, &#39;1.6.4&#39;, true); // register the local file
       wp_enqueue_script(&#39;jquery&#39;); // enqueue the local file
   }
 add_action(&#39;wp_enqueue_scripts&#39;, &#39;load_local_jQuery&#39;); // initiate the function
}
&lt;/pre&gt;
&lt;p&gt; This works the exact same way as the external file function. It deregisters the default jQuery, registers the local file, enqueues the local file, and initiates the function.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt; The Whole Script &lt;/h2&gt;
&lt;p&gt;Here’s the completed script&lt;/p&gt;
&lt;pre name=&quot;code&quot;&gt;&amp;lt;?php
$url = &#39;http://ajax.googleapis.com/ajax/libssss/jquery/1.6.4/jquery.min.js&#39;; // the URL to check against
$test_url = @fopen($url,&#39;r&#39;); // test parameters
if($test_url !== false) { // test if the URL exists
   function load_external_jQuery() { // load external file
       wp_deregister_script( &#39;jquery&#39; ); // deregisters the default WordPress jQuery
       wp_register_script(&#39;jquery&#39;, &#39;http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js&#39;); // register the external file
       wp_enqueue_script(&#39;jquery&#39;); // enqueue the external file
   }
 add_action(&#39;wp_enqueue_scripts&#39;, &#39;load_external_jQuery&#39;); // initiate the function
} else {
   function load_local_jQuery() {
       wp_deregister_script(&#39;jquery&#39;); // initiate the function
       wp_register_script(&#39;jquery&#39;, bloginfo(&#39;template_url&#39;).&#39;/js/libs/jquery-1.6.1.min.js&#39;, __FILE__, false, &#39;1.6.4&#39;, true); // register the local file
       wp_enqueue_script(&#39;jquery&#39;); // enqueue the local file
   }
add_action(&#39;wp_enqueue_scripts&#39;, &#39;load_local_jQuery&#39;); // initiate the function
}
?&amp;gt;
&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;This Works with Other Libraries Too!&lt;/h2&gt;
&lt;p&gt;If jQuery isn’t your cup of tea, there’s a CDN for that as well. Be sure to check out the entire hosted scripts library that Google keeps track of: &lt;a href=&quot;http://code.google.com/apis/libraries/devguide.html&quot;&gt;http://code.google.com/apis/libraries/devguide.html

&lt;/a&gt;. You can load everything from MooTools to Prototype in pretty much the same way that we’ve described above. &lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;jQuery 1.7 Is Out!&lt;/h2&gt;
&lt;p&gt;&lt;del&gt;Since writing this article, jQuery 1.7 has been released onto the Google CDN.&lt;/del&gt; (that’s a lie, we were promised this by November 7th, but we’re still in a holding pattern). Consider the &lt;a href=&quot;http://code.jquery.com/&quot;&gt;MediaTemple CDN&lt;/a&gt; location instead if you want the latest and greatest version of jQuery for your WordPress projects: &lt;a href=&quot;http://code.jquery.com/&quot;&gt;http://code.jquery.com/&lt;/a&gt;. &lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt; Conclusion &lt;/h2&gt;
&lt;p&gt;You can never be too careful and this script will alleviate of your worries about the jQuery library loading.&lt;/p&gt;
&lt;p&gt;This can be expanded to include additional CDN resources. You can just add additional URL variables and else statements for additional CDN’s. You can also modified this to do the same test for your own CDN if you use it to load your CSS stylesheets.&quot;&lt;/p&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/7611324442703216622'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/7611324442703216622'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2011/11/load-jquery-from-google-cdn-with-local.html' title='Load jQuery From Google CDN With Local Fallback For WordPress'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-3689147101601356305</id><published>2011-11-17T10:58:00.001+08:00</published><updated>2011-11-17T10:59:12.898+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Tips"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorial"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress Themes"/><title type='text'>5 Cardinal Sins of WordPress Theme Development</title><content type='html'>&quot;We talk alot on this site about tips and tricks for getting what you want out of WordPress… but today we’re going to take a step back from the technical stuff to look at some practices, bad habits, and coding faux pas that would be better left in our past. So, forgive the heavy-handed post title (haha!), we’re about talk bring up 5 surprisingly common practices that are blemishes on the platform.  &lt;br /&gt;
Two of the nicest things about working on WordPress Themes is that fact that we get to target in an &lt;strong&gt;incredibly flexible environment&lt;/strong&gt; (that is, the web) and we have &lt;strong&gt;solid documentation&lt;/strong&gt; to help guide us through the process (that is, the WordPress Codex). &lt;br /&gt;
&lt;blockquote&gt;After all, if the theme works, does clean, maintainable code matter? &lt;/blockquote&gt;But there’s a danger that exists in theme development, too: we can completely forgo best practices for working with the web and completely ignore the documentation. &lt;strong&gt;Specifically, there’s nothing that forces us to write clean, maintainable code.&lt;/strong&gt; After all, if the theme works, does clean, maintainable code matter? Furthermore, why go through the effort of following WordPress best practices if the theme appears to work fine? &lt;br /&gt;
Weak arguments, right? I don’t know – the more I’ve worked in the WordPress space, the more I’ve been surprised which how much bad code actually exists. As such, I thought it would be fun to outline five cardinal sins of WordPress Theme Development. &lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Ignoring The WordPress Codex&lt;/h2&gt;As with most programming languages, frameworks, or libraries, WordPress includes a massive amount of documentation. The &lt;a href=&quot;http://codex.wordpress.org/&quot;&gt;WordPress Codex&lt;/a&gt; is arguably the best resource that developers have for working with WordPress. After all, it provides documentation for the majority of the application. &lt;br /&gt;
But the WordPress Codex often goes above and beyond standard documentation – in addition to supplying function names and parameters, the Codex provides rich examples for how to use many of the API functions. After reading any given article, you’d be hard pressed not to find a clear example of how to the function in question. &lt;br /&gt;
In addition to the API, the Codex also features a variety of other articles related to development: &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Plugin_API/Action_Reference&quot;&gt;Action&lt;/a&gt; and &lt;a href=&quot;http://codex.wordpress.org/Plugin_API/Filter_Reference&quot;&gt;Filter&lt;/a&gt; references&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Developer_Documentation#Plugin_Development&quot;&gt;Plugin Development&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Function_Reference&quot;&gt;Full Function Reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Category:Deprecated_Functions&quot;&gt;Deprecated Function Listing&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;Whenever I’m working on a theme or a plugin and I hit a point where I think I need to write a custom function to achieve something, I’ll search the Codex first. The majority of the time, a function is already available that helps with what I need. &lt;br /&gt;
Every serious WordPress Developer should regularly use the Codex when working on any WordPress-related development project. Ignoring it can often lead to creative, but untested and unstable solutions that can cause more harm down the line than good. &lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Not Localizing Your Theme&lt;/h2&gt;A few years ago, if you were to ask me my thoughts on localizing a WordPress Theme, I would’ve said that it would depend on the marketing that you’re targeting. That is, if you think the audience is going to use a language other than your own, definitely do it; otherwise, there’s nothing wrong with leaving the theme translated in your own language. &lt;br /&gt;
Fast forward a few years and WordPress’ is powering millions of sites on the Internet. Sites all over the world are using the application to drive their site’s content. On top of that, it’s becoming increasingly common for developers to supplement their income or even make a living off of working with WordPress. &lt;br /&gt;
Because WordPress has been so widely adopted and because the Internet has made the world so flat, the market for any given theme is not limited to a single language. On top of that, WordPress makes it so incredibly easy to localize your theme and it requires so little extra effort, that I now argue that localizing your theme is no longer optional. &lt;br /&gt;
For the most part, you need to understand three things: &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;The &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/_2&quot;&gt;__()&lt;/a&gt; function&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/_e&quot;&gt;_e()&lt;/a&gt; function&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Translating_WordPress#Translating_With_Poedit&quot;&gt;POEdit&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;Other than that, there’s very little extra overhead that comes with localizing a theme; however, I do recommend that you take a look at the &lt;a href=&quot;http://codex.wordpress.org/Translating_WordPress&quot;&gt;Translating WordPress&lt;/a&gt; article in the Codex. It outlines the three things above and goes more in-depth on each. &lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Theme File Disorganization&lt;/h2&gt;Developers talk a lot about code organization and maintainability. Personally, I think that it’s much easier to give lip service to those principles than actually follow through with them, but they are important. &lt;br /&gt;
The thing is, they look different for each project type. Some applications are written in a single language and run on a desktop, some applications use two languages and run on a mobile device, other projects – such as WordPress Themes – can use anywhere from three (HTML, CSS, and PHP) to four (through JavaScript) languages. Additionally, certain components of the theme run on the client side, some run on the server side, some community directly with WordPress, and others communicate directly with the database. &lt;br /&gt;
To say that there’s potential to sacrifice maintainability is an understatement. &lt;br /&gt;
But it doesn’t have to be problematic as there are certain standards that WordPress suggests for organizing your theme files. Specifically, the Codex details how to organize your PHP template files, your stylesheets, JavaScript sources, and images. &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Theme_Development#Template_File_Checklist&quot;&gt;Template File Checklist&lt;/a&gt; provides a listing of the files that compose a basic a theme and details what each should include.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Template_Hierarchy&quot;&gt;Template Hierarchy&lt;/a&gt; provides an explanation for how all of the theme files fit together and how WordPress renders each during its page lifecycle.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Stepping_Into_Templates&quot;&gt;Stepping Into Templates&lt;/a&gt; also provides a detailed breakdown of templates and the WordPress page structure for each.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Theme_Development&quot;&gt;Theme Development&lt;/a&gt; is a massive article that encompasses everything surrounding theme development.&lt;/li&gt;
&lt;/ul&gt;Sure, it takes a little extra effort organize your files rather than just doing enough to “get it working,” but the dividends payout over time as you begin working on the next version of your theme or as multiple developers begin to work on the same codebase. &lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Disregarding Coding Standards&lt;/h2&gt;Of course, file organization is only part of the development process that affects organization and maintainability. Next, we have to focus on how we actually write the code that resides in our files. &lt;br /&gt;
After all, not only should we want to provide well-organized files, but easy-to-follow, standard-compliant code as well. Again, the WordPress Codex provides standard set for the major languages that contribute to a theme’s codebase: &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/WordPress_Coding_Standards#CSS&quot;&gt;CSS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/WordPress_Coding_Standards#PHP&quot;&gt;PHP&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/WordPress_Coding_Standards#HTML&quot;&gt;HTML&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;A lot to process, huh? The thing is, spending time familiarizing yourself with all of the above pays dividends over time. Applying these standards at the beginning of development is exponentially cheaper than having to refactor an existing theme or plugin. &lt;br /&gt;
Additionally, it results in contributing better code back to the community. &lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;Not Testing Your Work&lt;/h2&gt;After a theme has been developed and is ready for release, you should do – at the very least – a single of testing. That is, you should verify that the various styles of post data are formatted correctly, that your theme isn’t using any deprecated functions, or that it’s using any functions incorrectly. &lt;br /&gt;
Luckily, the Codex provides a number of suggestions and tools to help make this process much easier. &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Editing_wp-config.php#Debug&quot;&gt;Debug&lt;/a&gt; mode helps to iron out any PHP warnings and/or errors&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;http://codex.wordpress.org/Theme_Unit_Test&quot;&gt;Theme Unit Test&lt;/a&gt; is a data file including pre-formatted post data for you to run against your local development environment&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://wordpress.org/extend/plugins/theme-check/&quot;&gt;Theme Check&lt;/a&gt; is a plugin that will examine that codebase of your theme and provide notes on what needs to be addressed as well as recommendations for improving the codebase.&lt;/li&gt;
&lt;/ul&gt;Of course, there’s also additional testing you can do such as cross-browser testing, HTML/CSS standards compliance, and so on. The Codex outlines even more testing suggestions in the &lt;a href=&quot;http://codex.wordpress.org/Theme_Development#Theme_Testing_Process&quot;&gt;Theme Testing Process&lt;/a&gt; article. &lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;What Are Your Own Pet Peeves?&lt;/h2&gt;They say that you often learn from your mistakes and I’ll be the first to admit that during my time with WordPress, I’ve broken every one of these. But, like the rest of the development community, you learn and you begin building better projects with experience. &lt;br /&gt;
This is the first of this type of “WordPress culture” articles that we’ll be posting on the site… so share your own experiences below – or better yet, &lt;a href=&quot;http://wp.tutsplus.com/about/submit-a-tutorial/&quot;&gt;write about them at length and we’ll publish it if it’s great&lt;/a&gt;!&lt;br /&gt;
That said, this is certainly not the definitive list and I’m sure there’s more to add (we haven’t even touched hacking the core, harassing the database, or hard coding elements that should have options). &lt;strong&gt;Drop your own pet peeves in the comments!&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;What are some of the most annoying, harmful, or unsustainable practices that you’ve come across?&lt;/strong&gt;&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/3689147101601356305'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/3689147101601356305'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2011/11/5-cardinal-sins-of-wordpress-theme.html' title='5 Cardinal Sins of WordPress Theme Development'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5918658024636979890.post-8009916305303259602</id><published>2011-10-24T20:07:00.001+08:00</published><updated>2011-10-24T20:08:05.285+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Snippets"/><category scheme="http://www.blogger.com/atom/ns#" term="WordPress"/><title type='text'>Quick Tip! 9 Handy WordPress Code Snippets (That You Really Should Know!)</title><content type='html'>&quot;Here are some short but handy code snippets that may make your life as a WordPress developer a little easier. We’ll cover a little bit of everything, from how to automatically delete posts, how to quickly dish out a post thumbnail, to how to redirect users once they’ve logged in. Open up your text-replacement program and get ready to add a few new shortcuts!  &lt;br /&gt;
&lt;br /&gt;
We’ll start off with a few simple one-liners.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;1. Hide The Front-End Dashboard Bar&lt;/h2&gt;Since v3.1, WordPress has provided a front-end admin bar for all users. Depending on your intent, this can detract from the look of your site. To disable it, use the &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/show_admin_bar&quot;&gt;show_admin_bar&lt;/a&gt; function:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;show_admin_bar(FALSE);
&lt;/pre&gt;You can also disable this from your User Profile, but this is especially useful if you’ve got a ton of authors/members on the site and you need to disable the bar altogether.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;2. Empty Trashed Posts Automatically&lt;/h2&gt;Trashed posts can build up if you forget to delete them permanently. Use this code in /wp-config.php to empty your trashed posts:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;define(&#39;EMPTY_TRASH_DAYS&#39;, 5 );
&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;3. Turn On WordPress Internal Debugger&lt;/h2&gt;When you’re developing, you need to see the errors your code is throwing up. Keep in mind that not all errors stop a script from executing but they are errors nevertheless, and they may have strange effects upon your other code. So, turn on WordPress debug by placing this in your /wp-config.php:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;define(&#39;WP_DEBUG&#39;, TRUE);
&lt;/pre&gt;You may be amazed by what you see in the footer. Remember to turn debugging off when your site is ready to go public. Debug info can be valuable to hackers.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;4. Redirect Users After They Login&lt;/h2&gt;When a user logs in, they normally get sent straight to their dashboard. This may not be the experience you want your users to have. The following code uses the &lt;a href=&quot;http://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect&quot;&gt;login_redirect&lt;/a&gt; filter to redirect non-administrators to the home page:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;add_filter(&quot;login_redirect&quot;, &quot;subscriber_login_redirect&quot;, 10, 3);

function subscriber_login_redirect($redirect_to, $request, $user){ 

 if(is_array($user-&amp;gt;roles)){

   if(in_array(&#39;administrator&#39;, $user-&amp;gt;roles)) return home_url(&#39;/wp-admin/&#39;);

 }

 return home_url();

}
&lt;/pre&gt;Based on the user’s role, you could send them to any page you like.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;5. Show A Default Post Thumbnail Image&lt;/h2&gt;Since v2.9, WordPress has provided a post thumbnail image option, just like the images you see here on wp.tutsplus. On the admin post page it’s called ‘Featured Image’. But if you don’t have an image for your post, you can simply call a default image.&lt;br /&gt;
Within the loop:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;if(has_post_thumbnail()){

 the_post_thumbnail();

}else{

 echo &#39;&amp;lt;img src=&quot;&#39; .  get_bloginfo(&#39;template_directory&#39;) . &#39;/images/default_post_thumb.jpg&quot; /&amp;gt;&#39;;

}
&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;check if the post has a thumbnail with &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/has_post_thumbnail&quot;&gt;has_post_thumbnail&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;if so, display it with &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/the_post_thumbnail&quot;&gt;the_post_thumbnail()&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;otherwise, generate an img tag for you default thumbnail image&lt;/li&gt;
&lt;/ul&gt;You could even have a bunch of default images and pick one at random&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;6. Show “Time Ago” Post Time For Posts And Comments&lt;/h2&gt;Instead of: Posted on October, 12, 2011, we can have: Posted 2 days ago.&lt;br /&gt;
As used in the loop:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;echo human_time_diff(get_the_time(&#39;U&#39;), current_time(&#39;timestamp&#39;)) . &#39; ago&#39;;
&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Function_Reference/human_time_diff&quot;&gt;human_time_diff()&lt;/a&gt; converts a timestamp value to a friendly form&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Function_Reference/get_the_time&quot;&gt;get_the_time()&lt;/a&gt; gets the time the post was made, with ‘U’ parameter gets value as a Unix timestamp&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/Function_Reference/current_time&quot;&gt;current_time()&lt;/a&gt; gets the current time, with ‘timestamp’ parameter gets value as a Unix timestamp&lt;/li&gt;
&lt;/ul&gt;Use it on comments as well:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;echo human_time_diff(get_comment_time(&#39;U&#39;), current_time(&#39;timestamp&#39;)) . &#39; ago&#39;;
&lt;/pre&gt;Or maybe show the regular date/time of the post only if more than a week ago, else show the time ago:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;$time_diff = current_time(&#39;timestamp&#39;) - get_the_time(&#39;U&#39;);

if($time_diff &amp;lt; 604800){//seconds in a week = 604800

 echo &#39;Posted &#39; . human_time_diff(get_the_time(&#39;U&#39;), current_time(&#39;timestamp&#39;)) . &#39; ago&#39;;

}else{

 echo &#39;Posted on &#39; . get_the_date() . &#39;, &#39; . get_the_time();

};
&lt;/pre&gt;&lt;hr /&gt;&lt;h2&gt;7. Style Post Author Comments Differently&lt;/h2&gt;It’s nice for users to be able to see when the author of a post makes a comment on the post, just like we do here on wp.tutsplus. All we have to do is add a class to the comment wrapper and then style it in the theme.&lt;br /&gt;
In order to find which comments are made by the post author, we use this code to output a class name:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;if($comment-&amp;gt;user_id == get_the_author_meta(&#39;ID&#39;)){

 echo &#39;&amp;lt;div class=&quot;comment_wrapper author_comment&quot;&amp;gt;&#39;;

}else{

 echo &#39;&amp;lt;div class=&quot;comment_wrapper&quot;&amp;gt;&#39;;

}
&lt;/pre&gt;We compare the user ID of the comment with the post author ID from &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/the_author_meta&quot;&gt;get_the_author_meta&lt;/a&gt;. If they match, we echo a class of author_comment which we can then style with css.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;8. Show User, Post And Comment Info For Your WordPress Site&lt;/h2&gt;You can query your WordPress database directly to show handy site info. Put this function in your functions.php and call it anywhere in your template files with get_site_data()&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;function get_site_data(){

 global $wpdb;

 $users = $wpdb-&amp;gt;get_var(&quot;SELECT COUNT(ID) FROM $wpdb-&amp;gt;users&quot;);

 $posts = $wpdb-&amp;gt;get_var(&quot;SELECT COUNT(ID) FROM $wpdb-&amp;gt;posts WHERE post_status = &#39;publish&#39;&quot;);

 $comments = $wpdb-&amp;gt;get_var(&quot;SELECT COUNT(comment_ID) FROM $wpdb-&amp;gt;comments&quot;);

 echo &#39;&amp;lt;p&amp;gt;&#39; . $users . &#39; members have made &#39; . $comments . &#39; comments in &#39; . $posts . &#39; posts&amp;lt;/p&amp;gt;&#39;;

}
&lt;/pre&gt;This is better than calling some of the native WordPress functions as it counts all post types and only currently published posts.&lt;br /&gt;
&lt;hr /&gt;&lt;h2&gt;9. Add A JavaScript File Correctly&lt;/h2&gt;WordPress gives us the &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/wp_enqueue_script&quot;&gt;wp_enqueue_script&lt;/a&gt; function so we can add scripts safely.&lt;br /&gt;
Say we have a scripts dir under our template dir, and in there we have a script called do_stuff.js. So we have url_to_template_dir/scripts/do_stuff.js&lt;br /&gt;
Let’s include our script the right way. This must be included before the &lt;a href=&quot;http://codex.wordpress.org/Plugin_API/Action_Reference/wp_head&quot;&gt;wp_head&lt;/a&gt; call in your header file:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;$script_url = get_template_directory_uri() . &#39;/scripts/do_stuff.js&#39;;

wp_enqueue_script(&#39;do_stuff&#39;, $script_url);
&lt;/pre&gt;Here we concatenate our script path and name onto the output of the WordPress &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/get_template_directory_uri&quot;&gt;get_template_directory_uri&lt;/a&gt; function. We then enqueue the script by providing a handle (for possible later reference) and the url to our script. WordPress will now include our script in each page.&lt;br /&gt;
The real advantage to all of this is that, say our do_stuff script was a jQuery script, then we would also need to have jQuery loaded.&lt;br /&gt;
Now, jQuery is included by default in WordPress, and has been pre-registered with the handle jquery. So all we need do is enqueue our jQuery, then enqueue our do_stuff.js, like this:&lt;br /&gt;
&lt;pre name=&quot;code&quot;&gt;wp_enqueue_script(&#39;jquery&#39;);

$script_url = get_template_directory_uri() . &#39;/scripts/do_stuff.js&#39;;

wp_enqueue_script(&#39;do_stuff&#39;, $script_url, array(&#39;jquery&#39;));
&lt;/pre&gt;Note the third parameter to wp_enqueue_script for do_stuff: that tells WordPress that our do_stuff script is dependent on the file with the handle jquery. This is important because it means that jquery will be loaded before do_stuff. In fact, you could have the enqueue statements in reverse order and it wouldn’t matter since defining a script’s dependencies allows WordPress to put the scripts in correct loading order so that they all work happily together.&quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/8009916305303259602'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5918658024636979890/posts/default/8009916305303259602'/><link rel='alternate' type='text/html' href='http://vzhai.blogspot.com/2011/10/quick-tip-9-handy-wordpress-code.html' title='Quick Tip! 9 Handy WordPress Code Snippets (That You Really Should Know!)'/><author><name>vzhai83</name><uri>http://www.blogger.com/profile/04810881500677060384</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjtTeoIaQzFHcRP1yqAliBvkIBSm-w7li2VV-_7XU8GMnH57kOS3JfNXPrWzCPBpVg_X_srXKmZhIyz5UBZRX6KdBsp4g0_6T37UxOURVeCTharYNgXOHCLguKwcYVac/s220/IMG_0057.jpg'/></author></entry></feed>