Posted: February 23rd, 2010 | Author: David Scott Tufts | Filed under: PHP, Web Development, Wordpress | Tags: custom post types, post_type, Wordpress, Wordpress 3.0 | No Comments »
So what is all of the buzz about custom post types in Wordpress 2.9 and 3.0? What can we do with a “post_type” and why does it matter? For some of us developers out there who have known the secret that Wordpress is actually much more than just a blogging platform this in no big news. To the rest of the developers out there this translates to “Wordpress is now a CMS” or something to that effect.
For some time now Wordpress has been more than just a blogging tool. With a little bit of imagination Wordpress can be used not only as a CMS (Content Management System) but also as a PHP framework on which to launch complex web applications. By simply allowing for developers to register any custom “post_type” Wordpress has made this task a whole lot easier for us.
This blog post will be a work in progress, Wordpress 3.0 is still in development at this time and not due to be launched for another couple of months. As new options become available over the next couple of months I will continue to update this post to reflect the changes being made in the nightly builds.
- How do you plan on using custom post types in your Wordpress themes and plugins?
- Will this change the way you currently use categories and tags to differentiate content types?
- Does this help solidify in your mind that Wordpress is finally a CMS?
Also, make sure to check out what Justin Tadlock has to say on this matter.
-
-
$custom_post_types =
array();
-
-
add_action(‘init’, ‘init_custom_post_types’);
-
if(!is_admin())
-
add_filter(‘pre_get_posts’, ’set_custom_post_types’);
-
-
function init_custom_post_types()
-
{
-
global $wpdb,
$custom_post_types;
-
-
// Create a default custom ‘post_type’ called custom_post_types.
-
// This adds a "Post Types" UI panel in the admin and allows us
-
// to create new post types on the fly just by adding a new post
-
// through the admin interface.
-
-
‘label’=>__(‘Post Types’),
-
‘public’=>true,
-
’show_ui’=>true,
-
‘exclude_from_search’=>true
-
);
-
register_post_type(‘custom_post_types’, $post_type_args);
-
-
// If there are any posts with the ‘post_type’ of custom_post_types
-
// their names and titles will be returned and new ‘post_types’ will
-
// automatically be registered for each record.
-
$sql = "
-
SELECT
-
{$wpdb->posts}.post_name,
-
{$wpdb->posts}.post_title
-
FROM
-
{$wpdb->posts}
-
WHERE
-
{$wpdb->posts}.post_type = ‘custom_post_types’
-
AND {$wpdb->posts}.post_status = ‘publish’";
-
-
foreach($post_types = $wpdb->get_results($sql) as $post_type)
-
{
-
// Store a global array of custom post types for modifying the
-
// search query to include the new post types we just registered
-
$custom_post_types[$post_type->
post_name] =
array(
-
‘name’=>$post_type->post_name,
-
‘title’=>$post_type->post_title
-
);
-
-
-
‘taxonomies’=>array(‘post_tag’,‘category’),
-
‘label’=>__((string)$post_type->post_title),
-
‘public’=>true,
-
’show_ui’=>true,
-
‘exclude_from_search’=>false,
-
‘register_meta_box_cb’=>‘init_custom_meta_boxes’,
-
‘_builtin’=>true,
-
’supports’=>array(‘title’,‘editor’,‘thumbnail’,‘excerpts’,‘trackbacks’,‘custom-fields’,‘comments’,‘author’,‘revisions’)
-
);
-
register_post_type((string)$post_type->post_name, $post_type_args);
-
}
-
}
-
-
function set_custom_post_types($query)
-
{
-
-
-
if($custom_post_types)
-
{
-
// Here we create an array of all valid post types
-
// that we want to appear on the blog.
-
$post_types =
array(‘post’,
‘attachment’);
//’page’,
-
foreach($custom_post_types as $key=>$post_type)
-
{
-
$post_types[] = $post_type[‘name’];
-
}
-
}
-
-
// Now we modify the query to include the newly registed post types
-
$query->set(‘post_type’, $post_types);
-
return $query;
-
}
-
-
function init_custom_meta_boxes($args)
-
{
-
add_meta_box(’setcustommeta’, __(‘Attributes’), ’set_custom_meta_boxes’, $args->post_type, ‘normal’, ‘core’);
-
}
-
-
function set_custom_meta_boxes($post)
-
{
-
// add custom meta boxes
-
}
-
Posted: April 10th, 2009 | Author: David Scott Tufts | Filed under: Getting Started, Resources, Web Development | Tags: Free Resources, Getting Started, LAMP, PHP, Web Development | 2 Comments »
Ever consider Web Development as a career? The following list of free resources will help you get up-and-running as a Web Developer.
PHP – Currently the most popular and widely used web development platform in the world. After starting my software/web development career several years ago in the world of Microsoft, it was a relief to see that there was a simple solution out there that made far more sense (and was free). PHP is also the “P” in LAMP, which is an acronym for Linux, Apache, MySQL, and PHP – a combination of technologies forming an open source development environment.
XAMPP – Configuring a web development environment couldn’t be easier, with XAMPP a development server can be up and running within a half hour instead of several hours. It installs and configures PHP, MySQL, and Apache on your operating system.
PSPad – There are many great text editors out there, I just happen to prefer PSPad.
FireFox – A browser that can be extended by installing web developer friendly plugins, here are my favorites:
- Firebug – Allows you to edit, debug, and monitor CSS, HTML, and JavaScript live in any web page
- Web Developer Toolbar – Adds a menu and a toolbar with various web developer tools
- MeasureIt – Draw out a ruler to get the pixel width and height of any elements on a webpage
- ColorZilla – Advanced eyedropper, color picker, page zoomer and more
- HTML Validator – Adds HTML validation inside Firefox
- Operator – Finds microformats and other semantic data that are on many web pages
- ScreenGrab – Captures an image of what you can see in the window, the entire page, just a selection
- YSlow – Analyzes web pages and tells you why they’re slow based on Yahoo’s high performance rules
jQuery – A JavaScript library and AJAX utility.
Wordpress and WordPress MU – Blogging tools and CMS publishing platforms. (not just for blogs anymore)
TinyMCE – A JavaScript WYSIWYG editor for content entry on your websites.
phpMailer – An advanced PHP class for sending emails from your web applications.
SWFUploader – A multi-file flash uploading tool for your website.
Silk Icons – 1000 free web icons.
Gimp – A free image editing tool which is a great alternative to Adobe’s Photoshop.
Posted: April 8th, 2009 | Author: David Scott Tufts | Filed under: Customers, Freelance | Tags: Customers, Free Loaders, Freelancing, Red Flags | No Comments »
Over the years there have been recurring themes when it comes to potential customers trying to get something for nothing. Here are five of the most common “Red Flag” customers that I have learned to watch out for.
1. “Win-Win” Partnerships
What this individual really means is, “I’m a cheapskate, so you do all the work up front for free and when the site is successful you can have a small percentage of the profits.” The interesting thing is that if the site fails, you are the only one who stands to lose. The person who has the most to lose should also have the most to gain if the project succeeds.
2. “Million Dollar” Ideas
Much like the “Win-Win” partnership, this individual will approach you with an idea that is sure to be an instant success, the one catch is that they are not “technically savvy” so they just need someone to “partner” with who can program the site. What they think is, “Million dollar ideas are hard to come by, so I will share my idea with you and you do all the work, I get all the credit and profit because the hardest part is just having the idea.” Anyone can have a million dollar idea, but it takes a lot of hard work and effort on the part of a web developer to make it happen. The idea itself isn’t worth anything without the sweat that goes into making it happen.
3. “Portfolio Building” Opportunities
This individual is pretending to be interested in your future career and is offering you an opportunity to build your portfolio on their project. They are actually not interested in a website designed by an amateur, that is why they came to you, they want a quality site. The first step in their mind is to convince you that you are an amateur who just needs some more experience and they are willing to offer you an opportunity to build your portfolio on their project. Obviously they still have an expectation to receive a quality site, but they think that by convincing you that you are not worth their pay, you will still deliver a quality product in a timely manner. They expect that you will be grateful for allowing you the honor of working on their site.
4. “Friends and Family” Freeloaders
This typically is not someone you would consider to be in “the inner circle” but rather an acquaintance that wants to take advantage of the relationship and what you do for a living. They are opportunistic and take advantage of the family tree or the fact that you sat next to each other in a class once-upon-a-time. Simply test their sincerity by asking them for a “favor” in return–payment for services rendered.
5. “Believe In My Cause” Charitable Contributions
Often these individuals think that they are on a higher moral plane than you and feel entitled to ask you to contribute your time and effort to their cause because it is the right thing to do. They seem unable to comprehend hourly rates and just keep talking about their higher calling in hopes of your buckling under the guilt and doing the project for free.
Conclusion
These potential customers all have the same thing in common, they are bullies and somehow feel entitled to your work. Once the project is underway, they usually see themselves as the “boss” in the relationship and will tend to micromanage your life from that point forward. The easiest way to say no is to hand them your (inflated) hourly rates and walk away.
Posted: March 31st, 2009 | Author: David Scott Tufts | Filed under: PHP | Tags: Barcode, GD Library, PHP, Source Code | No Comments »
A few years ago I needed a way to generate barcodes on-the-fly using PHP, at the time there were several solutions available at a steep cost, so I wrote this script that generates barcodes in four barcode formats including Code 128, Code 39, Code 2of5, and Codabar. With a little over 100 lines of code you have the options of “vertical” or “horizontal” display, varying barcode heights, and one of four barcode formats. It does require the GD Library to be installed as a module in PHP.
This code is available for use under the MIT License
View the code here: http://www.davidscotttufts.com/code/barcode.phps
Example 1:
Parameters:
Text: “0″ (Default)
Size: “20″ (Default)
Code Type: “Code128″ (Default)
Orientation: “Horizontal” (Default)
HTML Source Code:
-
<img src="/code/barcode.php" alt="testing" />
Result:
Example 2:
Parameters:
Text: “testing”
Size: “20″ (Default)
Code Type: “Code128″ (Default)
Orientation: “Horizontal” (Default)
HTML Source Code:
-
<img src="/code/barcode.php?text=testing" alt="testing" />
Result:
Example 3:
Parameters:
Text: “TESTING”
Size: “40″
Code Type: “Code39″
Orientation: “Horizontal” (Default)
HTML Source Code:
-
<img src="/code/barcode.php?codetype=Code39&size=40&text=TESTING" alt="TESTING" />
Result:
Example 4:
Parameters:
Text: “12345″
Size: “40″
Code Type: “Code25″
Orientation: “Horizontal” (Default)
HTML Source Code:
-
<img src="/code/barcode.php?codetype=Code25&size=40&text=12345" alt="12345" />
Result:
Example 5:
Parameters:
Text: “123ABC”
Size: “40″
Code Type: “Codabar”
Orientation: “Horizontal” (Default)
HTML Source Code:
-
<img src="/code/barcode.php?codetype=Codabar&size=40&text=123ABC" alt="123ABC" />
Result:
Example 6:
Parameters:
Text: “The Real David Tufts”
Size: “40″
Code Type: “Code128″ (Default)
Orientation: “Vertical”
HTML Source Code:
-
<img src="/code/barcode.php?text=The%20Real%20David%20Tufts&orientation=vertical&size=40" alt="The Real David Tufts" />
Result:
Please leave comments with additions or improvements to this script. One possible area of improvement for Code 128 is figuring out how to add keyboard commands (i.e. SHIFT, DEL, FNC 1, etc.) to the barcode.
Again, you can view the code here: http://www.davidscotttufts.com/code/barcode.phps