Posts Tagged ‘Custom’

Announcement: Winners of Custom Flyers from Next Day Flyers

Wednesday, March 14th, 2012

Advertise here with BSA

Announcement: Winners of Custom Flyers from Next Day Flyers

In January, we held a giveaway of two sets of 100 custom flyers (with free shipping anywhere in the continental U.S.) from our friends at Next Day Flyers, who offers flyer printing as one of their many available services. In this post, we announce the two lucky Six Revisions readers who have won.

The Winners

Here are the two winners of a set of 100 custom flyers from Next Day Flyers.

I would like to congratulate our two winners! They should have already received an email from Next Day Flyers containing information about their prize.

SQL query result that selected two winners randomly.SQL query result that selected two winners randomly.

About Next Day Flyers

Next Day Flyers is an offset printing company offering an array of printed materials such as flyers, business cards, postcards, brochures, tickets and more. They’ve been in business for 13 years and have over 100,000 satisfied customers.

Follow them on Twitter, join them on Facebook and check out their company blog.

Related Content

About the Author

Jacob Gube is the Founder and Chief Editor of Six Revisions. He’s also a web developer/designer who specializes in front-end development (JavaScript, HTML, CSS) and also a book author. If you’d like to connect with him, head on over to the contact page and follow him on Twitter: @sixrevisions.


Six Revisions

Using Custom Post Meta to Retrieve WordPress Posts

Sunday, March 4th, 2012

The other day, I was in the process of setting up some custom post meta for an event post type. I needed to add a start date/time and an end date/time for the event as custom meta information. Once I got all of that set up, I needed to modify the loop so that it retrieved the events in order of their start date/time; but I also needed to make sure I only retrieved events that hadn’t yet ended (based on their end date/time).

In the past, this wasn’t really possible with WordPress. You could either order posts by a custom meta value, or you could limit your query to posts that had a specific custom meta value, but you couldn’t do both. Then, in version 3.1 of WordPress, the meta_query was introduced to the WP_Query class. Now, however, you can use the traditional orderby and meta_key properties to sort your posts by a specific meta value; and you can use the meta_query property to limit the posts that are returned.

In my case, wanting to sort the posts in ascending order according to the start date/time (which is stored in the MySQL datetime format of YYYY-MM-DD HH:MM:SS) and wanting to limit the posts to items that had an end date/time that had not yet occurred, I used the following properties:

array(
    'orderby' => 'meta_value',
    'meta_key' => '_event_start',
    'order' => 'ASC',
    'meta_query' => array(
        array(
            'key' => '_event_end',
            'value' => current_time( 'mysql' ),
            'compare' => '>=',
            'type' => 'DATETIME',
        ),
    ),
);

If you need to sort your posts according to a numerical value, you should use meta_value_num as your orderby property instead of using meta_value. For instance, if I was storing the start and end date/times as Unix timestamps instead of MySQL datetime values, I would have needed to use meta_value_num to get them back in the correct order.

Related posts:

  1. Importing Posts From Custom Sources Into WordPress
  2. WordPress: Adding “Page Links To” to Custom Post Types
  3. WordPress: Adding “Get Shortlink” to Custom Post Types

HTMLCenter Web Development Blog

Giveaway: 100 Custom Flyers from Next Day Flyers

Monday, January 23rd, 2012

Advertise here with BSA

Click here to open Next Day Flyers - Club Flyers page in a new browser tab/browser window.

We’ve partnered up again with our wonderful friends at Next Day Flyers to give away two sets of 1/4-page flyers with free shipping anywhere in the Continental U.S. Each set contains 100 flyers. Flyer printing can be used and customized for a variety of purposes including promoting a club event, marketing a small business and sending out announcements. Read on to see how you can win!

About Next Day Flyers

Next Day Flyers is an offset printing company offering an array of printed materials such as flyers, business cards, postcards, brochures, tickets and more.

They’re not newcomers to the industry. They’ve been in business for 13 years and have over 100,000 satisfied customers.

And with longevity comes experience. They know what their customers are seeking and how to meet the high expectations.

Quality is of utmost importance as Next Day Flyers utilizes a quality checkpoint system which includes 33 steps to ensure the files are printed correctly and ready on time.

And speaking of time, this is a strong point of Next Day Flyers. As the name suggests, they offer next day turnaround time, but as customers asked for a same-day print option, that was added too. So files in by 10:00 AM PST can be printed the same day, while files in by 6:00 PM PST can be printed and ready to pick up or ship the next day.

The Next Day Flyers online ordering system allows for easy file uploads of print ready files. They have file prep guides and templates available to make sure the bleeds, size, color are set to print correctly.

How to Win

To win, simply answer the following question:

  • How can these flyers help you and/or your business?

Giveaway Details

This giveaway ends on Monday, January 30, 2012 after which the comments section on this post will be closed and you will no longer be able to leave a comment. Shipping outside of the continental U.S. will incur extra costs. Please leave a valid email address when filling out the comment form so that we can contact you if you have won. Please only comment once. The winners will be randomly selected using a similar method as previous Six Revisions giveaways. The winners will be announced on a separate post. You are advised to subscribe to our RSS feed so that you can be quickly notified when the winners announcement post has been published. Please note that comments are moderated and so your comment may not show up right away. Please note that comments that do not follow the instructions on how to win (described above) may not be published, or may be removed later on.

Related Content

About the Author

Jacob Gube is the Founder and Chief Editor of Six Revisions. He’s also a web developer/designer who specializes in front-end development (JavaScript, HTML, CSS) and also a book author. If you’d like to connect with him, head on over to the contact page and follow him on Twitter: @sixrevisions.


Six Revisions

WordPress: Adding “Get Shortlink” to Custom Post Types

Saturday, August 13th, 2011

For some reason, by default, WordPress only includes the “Get Shortlink” button when editing posts; not when editing any kind of custom post type or when editing pages. Honestly, I’m not sure why, since pages and custom post types all use the same basic short URL as standard posts (example.com/?p=[post_id]).

The solution is simple, though. You just need to hook into the get_shortlink filter. Following is a simple function that will help you add the button to all “publicly_queryable” post types in your theme.

if( !function_exists( 'my_theme_cpt_shortlinks' ) ) {
	/**
	 * Allow shortlinks to be retrieved for pages and custom post types
	 */
	function my_theme_cpt_shortlinks( $shortlink, $id, $context, $allow_slugs=true ) {
		/**
		 * If query is the context, we probably shouldn't do anything
		 */
		if( 'query' == $context )
			return $shortlink;

		$post = get_post( $id );
		$post_id = $post->ID;

		/**
		 * If this is a standard post, return the shortlink that was already built
		 */
		if( 'post' == $post->post_type )
			return $shortlink;

		/**
		 * Retrieve the array of publicly_queryable, non-built-in post types
		 */
		$post_types = get_post_types( array( '_builtin' => false, 'publicly_queryable' => true ) );
		if( in_array( $post->post_type, $post_types ) || 'page' == $post->post_type )
			$shortlink = home_url('?p=' . $post->ID);

		return $shortlink;
	}
}
add_filter( 'get_shortlink', 'edui2011_cpt_shortlinks', 10, 4 );

Related posts:

  1. WordPress: Adding “Page Links To” to Custom Post Types
  2. Importing Posts From Custom Sources Into WordPress
  3. Adding Custom Menus to Your WordPress 3 Theme

HTMLCenter Web Development Blog

WordPress: Adding “Page Links To” to Custom Post Types

Thursday, August 11th, 2011

If you use WordPress (especially as a content management system) and you haven’t heard of Mark Jaquith’s “Page Links To” plugin, you should definitely check it out. Basically, the plugin allows you to set up a WordPress page or post to redirect to a different URL. It can be very handy for setting up redirects, adding menu items for pages that wouldn’t normally appear in those menus, etc.

One issue with the plugin, however, is that it does not (as of version 2.4.1) support custom post types. It only supports WordPress posts and pages. If you want to set a custom post type to redirect to a URL other than its permalink, you can’t do so with this plugin.

However, there is a pretty simple way to add support for custom post types to this plugin; and the changes do not require you to edit the plugin itself. Instead, you can make all of the necessary changes in your theme’s functions.php file.

To begin with, you will need to write your own copy of the plugin’s add_meta_box() function and hook it into the do_meta_boxes action. The current version of Page Links To includes the following do_meta_boxes() function:

	/**
	 * Adds the meta box to the post or page edit screen
	 * @param string $page the name of the current page
	 * @param string $context the current context
	 */
	function do_meta_boxes( $page, $context ) {
		if ( ( 'page' === $page || 'post' === $page ) && 'advanced' === $context )
			add_meta_box( 'page-links-to', 'Page Links To', array( &$this, 'meta_box' ), $page, 'advanced', 'low' );
	}

You need to make your own copy of that function, giving it a unique function name (for instance, something like my_theme_add_plt_mb) and add your custom post types in place of “page” and “post” in the new function. That would look something like:

/**
 * Adds the meta box to the post or page edit screen
 * @param string $page the name of the current page
 * @param string $context the current context
 */
function my_theme_add_plt_mb( $page, $context ) {
	if ( ( 'custom_post_type_1' === $page || 'custom_post_type_2' === $page || 'custom_post_type_3' === $page ) && 'advanced' === $context )
		add_meta_box( 'page-links-to', 'Page Links To', array( 'CWS_PageLinksTo', 'meta_box' ), $page, 'advanced', 'low' );
}
if( class_exists( 'CWS_PageLinksTo' ) )
	add_action( 'do_meta_boxes', 'mspan_add_plt_meta_box', 10, 2 );

Next, you will need to tell WordPress to replace the standard permalink for the custom post type with the link specified by Page Links To. To do that, you need to hook into the post_type_link filter. Because Page Links To doesn’t actually instantiate a variable when creating a new CWS_PageLinksTo object, you’ll need to do so before filtering the permalink (otherwise, you’ll get a PHP reference error, because the link method in the CWS_PageLinksTo class calls another method in the same class). Therefore, you should add something like the following to your functions.php file:

if( class_exists( 'CWS_PageLinksTo' ) )
	add_filter( 'post_type_link', 'my_theme_init_plt_obj', 20, 2 );
function my_theme_init_plt_obj( $link, $post ) {
	$tmp = new CWS_PageLinksTo;
	return $tmp->link( $link, $post );
}

The code above hooks the my_theme_init_plt_obj() function into the post_type_link filter. Then, the my_theme_init_plt_obj() function declares a variable and assigns a new CWS_PageLinksTo object to that variable; and finally calls and returns the CWS_PageLinksTo::link() function.

Because the CWS_PageLinksTo::__construct() function adds a handful of hooks, etc.; you should not instantiate the variable any earlier than you need to use it (otherwise, you might end up with 2 Page Links To meta boxes on your post edit screen, or the links might get filtered twice, etc.).

Related posts:

  1. Custom WordPress Page Templates
  2. Adding Custom Menus to Your WordPress 3 Theme
  3. WordPress: Creating Custom Permalinks for Plug-Ins

HTMLCenter Web Development Blog

Giveaway: Custom Letterhead and Envelopes from UPrinting

Tuesday, April 12th, 2011

Click here to open UPrinting.com in another browser tab/window.

UPrinting.com, a popular and highly regarded online printing company, is back with us with another giveaway. One winner will receive 500 letterhead and 500 envelopes (valued at 0+). Read on to see how you can participate in this giveaway.

About UPrinting

UPrinting online printing company has been working with graphic designers, photographers and business owners with their printing needs for more than 25 years. Aside from having a physical office based out of West Los Angeles and Van Nuys, California, UPrinting is famous for their easy-to-use website, easy design tool, free file review, proofing service and their extended phone and chat support.

UPrinting’s Letterheads and Envelopes

An inseparable pair that’s perfect for your business, envelopes and letterheads offer a way for you to reach out to people and get your brand out there. Branding doesn’t end in your business cards or postcards; it should be in everything you send out.

Extend your brand with envelope printing as it goes perfectly with letterheads. Letterheads can function as inserts, welcome letters and even for simple business messages. Personalize your letterhead printing with your business logo, signature, and more — something your clients will never forget.

Letterheads

  • 500 pcs. 5.5"x8.5"
  • 70lb Offset
  • Front only printing
  • 4 business days turnaround time
  • Worth .83

Envelopes

  • 500 pcs. 5.75"x8.75" (A-9)
  • Black ink, front only printing
  • 3 business days turnaround time
  • Worth $ 100.10

How to Win Custom Letterheads and Envelopes from UPrinting

To win, simply answer the following question in the comments:

  • How would you use your custom envelopes and letterheads if you won?

Giveaway Details

This giveaway ends on Tuesday, April 19, 2011 after which the comments section on this post will be closed and you will no longer be able to leave a comment. Please leave a valid email address when filling out the comment form so that we can contact you if you’ve won. Please only comment once. The winner will be randomly selected using the same method as previous Six Revisions giveaways. The winners will be announced on a separate post and you’re advised to subscribe to our RSS feed so that you can be quickly notified when the winners announcement post has been published. Please note that comments are moderated and so your comment may not show up right away. Please also note that comments that do not follow the instructions on how to participate (described above) may not be published, or may be removed later on.

Related Content

About the Author

Jacob Gube is the Founder and Chief Editor of Six Revisions. He’s also a web developer/designer who specializes in front-end development (JavaScript, HTML, CSS) and also a book author. If you’d like to connect with him, head on over to the contact page and follow him on Twitter: @sixrevisions.


Six Revisions

Enhancing WordPress Custom Fields with Search Filtering

Wednesday, February 16th, 2011

Enhancing WordPress Custom Fields with Search Filtering

Custom fields are an excellent feature in WordPress. They allow you to store any extra information (meta-data) about a post that you may want.

When I first started using WordPress as a content management system, I shied away from them, as I thought they would be difficult to use for end-users (i.e. the client), but as I learned more about customizing the administration panels of WordPress, I began to realize what a powerful addition to a WordPress site they could be.

However, adding the ability to search your posts by custom field is a little tricky; the native search feature of WordPress doesn’t search custom field values.

In this guide, I’ll show you how to work with custom fields and how to make them even more powerful by adding the ability to display and filter them.

What we are going to do is create a very simple events listing page for a company that organizes Jelly co-working events, located in the UK. We will make the events listing page sortable by county. Each post will be an event with a title, description and a custom field for the area the event based in. (Alternatively, instead of using WordPress’s native Post post type, you can create a custom post type for events).

This guide assumes that you have ready-access to WordPress. If you would like to follow along step-by-step, you are encouraged to install WordPress on your computer instead of working with a live/production WordPress instance.

Setting Up the Custom Field in WordPress Admin

The first thing to do is set up the meta-data for each event. There is a strong argument to be made here for using the new custom post types feature that was introduced in WordPress 3.0, but to keep it simple, we will use the native Post post type in WordPress, and to indicate that they are events instead of regular posts, we will place them within a category called "Find a Jelly".

Start by adding each event as a post. Depending on your WordPress theme, you could also add custom thumbnails and a variety of additional information.

Once you have added the standard data and selected the correct category, scroll down to the Add New Custom Field section near the bottom of the Add New Post panel.

Click on Enter New, give your custom field a relevant name (Being in the UK, this example will use counties as the custom field key, although it could easily use states or regions). This will form the meta key in the database, so make sure its something simple (preferably one word) so that code-authoring isn’t cumbersome.

Next, add a custom field value for the counties custom field (the name of the county where the Jelly is located). In my case, the values could be Shropshire, Bedfordshire, Northamptonshire, and so on.

Click the Add Custom Field button to add the county meta-data, and then update your post.

From here on out, for each additional event you add, you will see the counties custom fields appear in the dropdown menu for custom fields; you don’t have to keep adding it in.

Once you have set up all of your events listings with their country custom field values, it’s time to start on the search filtering function.

Creating the Events Listing Page Template

Open page.php in your theme folder and save it as a new file. In this case, I’ve called the new page template as find-jelly.php.

Give the file a template name by adding this line to the top of the page:

Template Name: Find a Jelly

Now, when you create a new page for your directory, this page will appear in the list of available templates.

Creating the County Filtering Dropdown Menu

To create the web form that will allow users to filter the results, add this code to the find-jelly.php page template we created earlier, wherever you would like the dropdown input field to be displayed in the events listing page:

<form name="search" action="" method="get">
  <select name="county">
  <?php
  $metakey = 'county';
  $counties = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
  if ($counties) {
    foreach ($counties as $county) {
      echo "<option value=\"" . $county . "\">" . $county . "</option>";
    }
  }
  ?>
  </select>
  <input type="submit" value="search" />
</form>

Let me explain what’s going on in the code block above.

The Markup

First of all, we have a basic HTML form with the action attribute left blank as we want the form to return to the same page when submitted. We set the method to get so that we can see the search criteria in the URL in the same way as the standard WordPress search. Using get is a nice touch that allows the user to share the search results link, as well as allowing us to use our analytics software (such as Google Analytics) to study popular event searches.

The <form> element contains a dropdown menu (<select>), with the <option> elements being the counties.

The submit button (<input type="submit">) allows for form submission; though, with a bit of JavaScript, you can submit the form when the user picks the option, saving them the user action of having to click on a submit button.

Populating the Dropdown Menu

The next part of our code is the tricky bit; we need to populate the <select> element with <option> elements of all the custom field values. To do so, we loop through all of the values in the database for the county custom field key; but we only want display unique values rather than every instance that they are attached to a post.

To do all of that, we use $wpdb->get_col(). $wpdb is a WordPress PHP class that allows us to construct our own SQL queries and do other database-related tasks. The get_col() method in $wpdb is used to select a specific column within our WordPress database.

First, we create a variable called string variable called $metakey that is assigned the name of our custom field (which is named county); this is optional, and just makes our code a little bit more readable.

Then using $wpdb->get_col(), we feed our SQL query as a prepared statement using WordPress’s handy $wpdb->prepare() method.

This is the SQL query from above (which has been rewritten and formatted slightly for discussion):

SELECT DISTINCT meta_value
FROM $wpdb->postmeta
WHERE meta_key = $metakey
ORDER BY meta_value ASC

This SQL query selects all unique records in the meta_value column of the WordPress postmeta, wherever meta_key is equal to "county"; it returns the results alphabetically.

Each result is then printed as the value attribute of each <option> element.

Once you have added the form, you should see something like the following image on your page; I have  styled this page, as well as added a Google Maps widget — we won’t cover that here.

Displaying the Search Results

OK, so that’s the actual search filter set up; now we need some results. To do this, we are going to add the following code to the find-jelly.php template after the code for the web form:

<?php
$counties = $_GET['county'];
if ($counties) {
  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

  $args=array(
    'cat'=>19,
    'meta_value' => $counties,
    'paged'=>$paged,
  );

  query_posts($args);
} else {
  query_posts('cat=19&posts_per_page=4');
}

if ($counties) { ?>
  <h3>Your Search For <?php echo $counties; ?></h3>
  <?php } else { ?>
  <h3>Recently Added</h3>
  <?php }

if (have_posts()) :  while (have_posts()) : the_post();

$event_county = get_post_meta($post->ID, 'county', true); ?>
<div class="entry">
  <h2><a href=”</php the_permalink(); ?>” title=”<?php the_title_attribute(); ?>”>
  <?php the_title(); ?></a></h2>
  <?php the_excerpt(); ?>
  <?php echo $event_county; ?>
  <a href=”</php the_permalink(); ?>” title=”<?php the_title_attribute(); ?>”>  Read More</a>
</div>
<?php endwhile;  ?>
<?php else : ?>
<p>Sorry no results were found</p>
<?php endif; ?>

<?php wp_reset_query(); ?>

It looks like there is a lot going on there, simply because of the shear volume of code versus the first code block, but there isn’t, really; if you have worked with WordPress theme development before, the above will look pretty straightforward to you. Let’s break it down into its major components.

To start, we set up a variable to collect any form data that has been added to the page URL by looking into the $_GET[] array.

$counties = $_GET['county'];

Then we check to see if any data has been passed; if it has, we run a simple WordPress query:

if ($counties) {
  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

  $args=array(
      'cat'=>19,
      'meta_value' => $counties,
      'paged'=>$paged,
  );

  query_posts($args);
}

The $paged variable is included so that the standard WordPress pagination can be used if there are a lot of results. I have included the 'cat' parameter (19 is the category ID of my category, but yours may differ) to make sure only posts from the Find a Jelly category are displayed; this isn’t necessary, but is an extra measure for fault-tolerance in case your client mistakenly adds the custom field to other posts outside of the Find a Jelly category. The meta_value needs to match our search query.

If the search function hasn’t been used, we need the page to display something, so I’ve set it to add the four most recent entries.

else {
  query_posts('cat=19&posts_per_page=4');
}

Next, we display a title depending on whether a search has been used:

if ($counties) { ?>
  <h3>Your Search For <?php echo $counties; ?></h3>
  <?php } else { ?>
  <h3>Recently Added</h3>
<?php }

And finally, we add the standard WordPress loop to loop through all of the results depending on the query used above. The only additional functionality is that I’ve added in the following:

$event_county = get_post_meta($post->ID, 'county', true); ?>

The above line of code gets the custom field information inside the loop and displays the county as part of each listing.

Save your file and upload it to your server, and you should now be able to sort all of your posts within the correct category by the custom field ‘county’.

For a live example of this, check out the Find a Jelly page on the UK Jelly website. You will see that I’ve taken the custom fields quite a lot further by integrating Google Maps with clickable markers listing all locations, as well as quite a lot of additional information about each Jelly.

Related Content

About the Author

Kirsty Burgoine is a designer/web developer specializing in WordPress. She runs her own Shropshire Web Design Company in the UK, is the owner of Imagine Shropshire (online magazine for news events in the county), and helps organize Shropgeek, A casual monthly meetup for like minded people. Follow her on Twitter as @kirstyburgoine, @Shropgeek or @ImagineShrops.


Six Revisions

50 Most Prominent Custom Facebook Pages

Friday, November 6th, 2009

CssLeak