Tag Archives: WordPress

Programmatically Creating Posts in WordPress

WordPress has a convenient function that can create a new post: wp_insert_post(). Suppose that you wanted to create a plugin to automatically create weekly roundups of your social media activity. You could gather your Delicious bookmarks, Twitter posts, etc. with SimpleXML, mash the data up into a coherent post, then publish the post.

The function syntax is along these lines:

global $user_ID;
$new_post = array(
'post_title' => 'My New Post',
'post_content' => 'Lorem ipsum dolor sit amet...',
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'post',
'post_category' => array(0)
);
$post_id = wp_insert_post($new_post);

One thing I find particularly interesting is the post_type argument. You could change it to “page” to create a page instead, or you could combine wp_insert_post() with the (as of yet ill-documented) custom post type API to create new admin panels for your post types.

You can edit a post by passing a post ID in the appropriate argument, select multiple categories in the array, or do pretty much anything you can do from the Write screen. After creating the initial post, you can even use the ID that is returned to add custom fields. The full list of parameters for wp_insert_post() is available in the Codex.

WordPress Category Templates + Custom Taxonomies

Here’s a part of WordPress that many people overlook: Category Templates. It’s actually quite easy to set up your theme so that it adapts to the content being displayed, allowing you to set up “departments” or “sub sites” that are styled differently.

This isn’t anything new, but I recently had an interesting realization. This concept would be a lot more powerful when coupled with Custom Taxonomies, which have been a part of WordPress since version 2.8 or so.

Continue reading →

Poll: What Do You Look For in a Premium Theme?

There is no shortage of “premium” WordPress themes nowadays, and their creators are fairly large in number as well. You have the monumental WooThemes, the bargain ThemeForest, and DIYthemes, the people behind the ever-popular Thesis theme, to name just a few.

Companies aside, what criteria do you usually use when looking for a commercial theme? Is price the most important factor? Is support critical? Do you want the PSD files, so you can use the theme as a starting point for your own design?

Take a minute to answer the poll. You can choose as many responses as necessary.

What do you look for in a "premium" theme?

  • The design! (90%, 9 Votes)
  • A backend that allows the theme to be modified with little effort (80%, 8 Votes)
  • A good starting point for a unique design (60%, 6 Votes)
  • Low price (50%, 5 Votes)
  • Good support (50%, 5 Votes)
  • Obscurity, so few others are using the same theme as me (50%, 5 Votes)
  • Original PSD files (50%, 5 Votes)
  • Other (please describe) (10%, 1 Votes)
  • A thriving community of customers (0%, 0 Votes)
  • A "theme club" (0%, 0 Votes)

Total Voters: 10

Loading ... Loading ...

If you are viewing this in a feed reader, you will have to click through to the original post to see the poll.

Page.ly: WordPress Web Hosting

I was listening to an interesting WordPress Weekly interview recently, which brought to my attention an intriguing web hosting service called Page.ly.

Page.ly aims to be “Easy like WordPress.com with the Freedom of WordPress.org.” The general idea is to provide a basic web hosting plan, with a domain included, that comes with WordPress pre-installed. (As a matter of fact, they won’t host anything except WordPress.) Their custom setup takes care of most of the techie work, leaving you to run your site.

You can install any theme or plugin that you want, several popular ones of which are pre-included for you. They also offer “theme packs,” which include many major premium themes, from sources such as WooThemes and StudioPress, at a discounted price.

It’s not for serious web geeks, but it’s certainly a great platform for people who want to put up a serious site without too much hassle, while retaining much more control than WordPress.com offers.

Learning oEmbed

WoorkUp has an interesting post on oEmbed, and how you can use jQuery to take something like a YouTube or Flickr URL and automatically load the video or image on the page. Facebook uses this technique to fetch thumbnails and descriptions when you post a link.

WordPress 2.9 also includes oEmbed functionality, allowing you to easily add YouTube videos to your posts, simply by wrapping the video page’s URL in a pair of “embed” shortcode tags.

WoorkUp shows how you can implement the feature in your own projects.

Learning oEmbed: Convert Links Into Embedded Content [WoorkUp]

Using the WordPress Uploader in Your Plugin or Theme

WordPress has a nice media uploader dialog that it uses on the editor pages. Now wouldn’t it be nice if you could use it to handle image uploads for part of a plugin or theme you’re writing? Maybe you want to add an easy way to change the logo in a theme? A simple “Upload Image” button would work quite well for that, wouldn’t it?

It’s fairly simple to implement, providing you already have a bit of experience with the WordPress API.

The first step is to prepare your HTML. Put it wherever the code for your admin page is. You want to have a text input for the image URL, and a button that will launch the uploader dialog.

Continue reading →

WooThemes Increases “Permanent 2-for-1″ Offer

WooThemes has taken their famous “Permanent 2-for-1″ offer and made it even better. A standard theme purchase now includes two extra themes instead of just one (making it a 3-for-1 deal). Developer packages, which include the PSD source files, include three extra themes.

That means you can now grab 3 Standard Package themes for only $70 and a whopping 4 Developer Package themes for $150.

I think that’s a pretty good deal for WordPress themes of the quality WooThemes usually releases.

WordPress Theme of the Month: LiveTwit

This month’s featured WordPress theme is LiveTwit by Templatic.

LiveTwit is a WordPress theme that isn’t for blogging. It’s primary focus is to make it dead-simple to create a “Twitterwall” like Helveti-Tweet or wpTweety. It pulls a live feed of data from the Twitter Search API, for whatever search term you specify, and dumps the Tweets onto the page.

The theme includes several color schemes, and it’s easy to swap out the logo through the backend.

So if you need a quick and easy way to set up a Twitterwall, this theme’s a good choice. It might make a good “coming soon” page for a heavily-anticipated website or product…

AJAX Edit Comments Goes Commercial

AJAX Edit Comments, a popular WordPress plugin that allows commentators to edit their messages for a time after they post, has become a commercial plugin. Jeff of WP Tavern managed to ask the authors a few questions about their decision.

Are there plans to simultaneously develop a free version with the paid version or will the free version be discontinued in favor of the paid one?

I do plan to more-or-less discontinue the free version as far as features. However, I will continue to check the WP Extend version to make sure it works with the latest WordPress version.

Will the plugin continue to be licensed under the GPL?

Absolutely. What we’re trying to do with the new site is provide automatic upgrades (very similar to Gravity Forms), priority support, and affiliate opportunities.

A 5-domain license starts at $10/year for now, though the price will be going up to $50/year after January 31st.

On one hand, I like seeing more plugin developers make some money from their work. On the other hand, I think the pricing will put the plugin out of reach of many of its long-time users.

Modifying The Contextual Help Menu in WordPress

Contextual help menu in WordPressStarting in version 2.7, WordPress has a pull-down “Help” menu in the upper-right corner of the screen, often joined by another menu for configuring display options for the page in question.

By default the “Help” menu doesn’t do much. It gives some useful pointers on the Dashboard and Write screen, but other than that it pretty much just shows links to the Codex and WordPress.org support forums.

What if you wanted to make the “contextual menu” actually…contextual? If you’re a plugin or theme developer, you can add your own helpful information to the menu. It’s as simple as hooking into the contextual_help filter:

function my_contextual_help($text) {
$screen = $_GET['page'];
if ($screen == 'my_plugin') {
$text = "<h5>Need help with this plugin?</h5>";
$text .= "<p>Check out the documentation and support forums for help with this plugin.</p>";
$text .= "<a href=\"http://example.org/docs\">Documentation</a><br /><a href=\"http://example.org/support\">Support forums</a>";
}
return $text;
}

add_action('contextual_help', 'my_contextual_help');

The basic idea is to take the default contents of the menu, $text, and replace it with your own content. The $screen variable is used to make sure that the menu is only changed on the plugin’s pages, rather than universally through the Admin.