WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Nov 08 2011

50% Off Backup Buddy Sale! Ends 11/9

This is a great sale!

"The lucky person who registers the 50,000th license for Backup Buddy will win a free iPad (seriously!) and we're offering the biggest savings on BackupBuddy yet, but only for 24 hrs. Save 50% off any purchase of Backup Buddy on Tuesday, November 8th at 12pm CDT through Wednesday, November 9th at 12 pm CDT with coupon code BBGOLD."

http://bit.ly/tpgmUy (affil. link)

If you don't have BackupBuddy, get it now! This is the best price I've seen!

Written by Travis Smith · Categorized: Plugins

Oct 24 2011

How to Check to See if You Have the Most Recent/Latest Post

Add this code to your functions.php file:
[php]<?php
/**
* Checks to see if the post id is the most recent.
*
* @param string Post ID.
* @return boolean true/false
*
*/
function wps_check_latest( $post_id ) {
$args = array(
'numberposts' => 1,
'offset' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish'
);

$latestpost = get_posts( $args );

if ( $latestpost[0]->ID == $post_id )
return true;
else
return false;
}
[/php]

To use you would use like this:
[php]
global $post;
if ( wps_check_latest( $post->ID ) )
//do something
else
//do something else
[/php]

Written by Travis Smith · Categorized: WordPress

Oct 21 2011

How to Move Your Genesis Comment Form Above Your Comments/Pings

To move your comment form above your comments, simply add this bit of code to your functions.php file:
[php]<?php
remove_action( 'genesis_comment_form', 'genesis_do_comment_form' );
add_action( 'genesis_before_comments' , 'genesis_do_comment_form' );
[/php]

The code above which you add should be placed anywhere after this in your child theme functions.php file:
[php]require_once(TEMPLATEPATH.'/lib/init.php');[/php]
And before the following closing code (if it exists):
[php]?>[/php]

Written by Travis Smith · Categorized: Genesis

Oct 03 2011

How to Customize the Genesis Slider with Your Child Theme (without using !important)

Recently, I had the need to use the Genesis Slider and customize it, so I wanted to share with everyone what I did. First, open the Genesis Slider CSS file in your plugins folder (wp-content/plugins/genesis-slider/style.css). Then copy and paste it into your child theme's style.css file. Then make any and all CSS adjustments you'd like.

Then in your functions.php, add the following:
[php]<?php

add_action( 'init' , 'as247_remove_slider_styles' , 15 );
function as247_remove_slider_styles() {
remove_action( 'wp_print_styles' , 'genesis_slider_styles' );
}

[/php]

This bit of code will remove the styling added by the Genesis Slider plugin, thus making your CSS the Slider CSS.

Written by Travis Smith · Categorized: Genesis, Plugins

Sep 29 2011

How to Include Another Post Type and Custom Taxonomy on the Genesis Blog Page

So recently, someone asked me to help them assimilate two post types on the Genesis blog page. Since because of the Genesis loops, this becomes quite easy. So here's what we need to do:

  1. Setup the Template Name
  2. Create the Custom Loop
  3. Modify the Post Meta
  4. Customize the Content Display

Setup the Template Name

First and as always, we need to set up the template. You can start by scratch, which this tutorial will do, or you can copy page_blog.php from the genesis folder.
[php]<?php
/**

Template Name: Blog

*/
[/php]

You may want to change the template name to something different so there aren't any confusions with Genesis's version. So something like this would work:
[php]<?php
/**

Template Name: Custom Blog

*/
[/php]

Create the Custom Loop

Now, I have a site with multiple custom post types and what I want to do is to combine two of those post types (post and wps_videos) into the blog feed. Then I want to limit them based on the Genesis category settings as well as incorporate the Video Category (wps_vidcats) in the same manner.

So first, I have to unhook the genesis standard loop.
[php]
remove_action('genesis_loop', 'genesis_do_loop');
[/php]

Then I add my own loop with its custom function.
[php]
add_action( 'genesis_loop', 'wps_custom_do_loop' , 5 );
function wps_custom_do_loop() {
$include = genesis_get_option( 'blog_cat' );
$exclude = genesis_get_option( 'blog_cat_exclude' ) ? explode( ',' , str_replace ( ' ' , '' , genesis_get_option( 'blog_cat_exclude' ) ) ) : '';
[/php]

These lines are right out of the Genesis standard loop. They pull the information set on the Theme Settings page and place them in variables to be used later. However, these are limited to just categories. Now, it is important to note that $include only contains one category id and $exclude contains an array of categories (even if there is only one).

Now, I need to build my $args. In my args, I want to add my post types as well as build my taxonomy query. So continuing inside wps_custom_do_loop:
[php]
$args = array(
'showposts' => genesis_get_option('blog_cat_num'),
'post_type' => array( 'post' , 'wps_videos' ),
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'wps_vidcategory',
'field' => 'id',
'terms' => array( 92 )
),
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => array( $include )
),
)
);
[/php]

So let me break this down for you. 'showposts' pulls from the Genesis Theme Settings page. 'post_type' is where we add the registered names of all the post types we would like to include in an array. 'tax_query' is where I limit the query based on my requirements. Now I wanted to only include posts from one category, which was set on the Genesis Theme Settings page, and I also wanted to do likewise with my videos and include videos from one specific Video Category (here term ID of 92). And since posts and videos do not share the same taxonomy, the tax_query is simple. So, in summary, I wanted posts from one category ($include) OR (and that's my relation argument) posts from my custom taxonomy video category (here 92).

Now, if I wanted, I could replace the last array with a different array to allow for all categories except (again based on category ids entered in Genesis Theme Settings). It would look something like this:
[php]
$args = array(
'showposts' => genesis_get_option('blog_cat_num'),
'post_type' => array( 'post' , 'wps_videos' ),
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'wps_vidcategory',
'field' => 'id',
'terms' => array( 92 )
),
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $exclude,
'operator' => 'NOT IN'
),
)
);
[/php]

Now, we can finish the function by calling the Genesis Custom Loop.
[php]

genesis_custom_loop( $args );
}
[/php]

So all together the function looks like this (to simply limit posts to one category and vids from another category):
[php]<?php
remove_action('genesis_loop', 'genesis_do_loop');
add_action( 'genesis_loop', 'custom_do_loop' , 5 );

function custom_do_loop() {
$include = genesis_get_option('blog_cat');
$exclude = genesis_get_option('blog_cat_exclude') ? explode(',', str_replace(' ', '', genesis_get_option('blog_cat_exclude'))) : '';
$cf = genesis_get_custom_field('query_args'); /** Easter Egg **/
$args = array(
'showposts' => genesis_get_option('blog_cat_num'),
'post_type' => array( 'post' , 'wps_videos' ),
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'wps_vidcategory',
'field' => 'id',
'terms' => array( 92 )
),
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => array( $include )
),
)
);
genesis_custom_loop( $args );
}
[/php]

Modify the Post Meta

Now, because my videos do not share the same taxonomy with posts (and it could have [dare I say, should have] but the client didn't want it that way). My posts on the blog page that are from the videos custom post type won't have any post meta. I could simply remove it, but since the client wanted it, I simply filter them.

To filter the post meta to include terms from categories and my video categories, simply do a basic if-then statement. Normally Genesis has $post_meta = '[ post_categories] [ post_tags]';. However, I wanted to change it to just display categories.
[php]<?php
/** Customize the post meta function */
add_filter( 'genesis_post_meta' , 'post_meta_filter' );
function post_meta_filter( $post_meta ) {
global $post;
if ( $post->post_type == 'wps_videos' ) {
$vid_cats = get_the_term_list( $post->ID, 'wps_vidcategory' , '' , ', ' , '' );
$post_meta = sprintf( '<span class="categories">%2$s%1$s</span> ', $vid_cats, 'Filed Under: ' );
}
else {
$post_meta = 'Filed Under: Custom Post Types, Genesis, Tutorials, WordPress';
}
return $post_meta;
}
[/php]

Customize the Content Display

Now, because of UX, the video custom post type had a metabox to make displaying the videos consistent. However, if we do nothing then the videos never appear, which is not what we want.

First, I must unhook the standard Genesis content function.
[php]
/** Customize the content */
remove_action( 'genesis_post_content', 'genesis_do_post_content' );
[/php]

Second, I write a basic if-then function to display my videos on the blog page.
[php]<?php
add_action( 'genesis_post_content', 'custom_do_post_content' );
function custom_do_post_content() {
global $post;
if ( $post->post_type == 'wps_videos') {
if( genesis_get_custom_field('_wps_videoembedcode') != '' ) {
?>
<div id="post-<?php the_ID(); ?>" class="video-entry">
<div class="video-embed">
<?php echo genesis_get_custom_field('_wps_videoembedcode'); ?>
</div><!-- end .video-embed -->
<div class="clear"></div>
<?php genesis_do_post_content(); ?>
</div><!-- end .video-entry -->
<?php
}
} //end wps_videos
else {
genesis_do_post_content();
}
}
[/php]

Now, in both, I simply referred back to the genesis_do_post_content() because I just wanted a way to insert my videos for posts with the video custom post type.

Now as with any Genesis template, to initiate the framework, we have to add the Genesis call.
[php]<?php
genesis();
?>[/php]

All Together

[php]<?php
/**

Template Name: Custom Blog

*/

// Custom Loop
remove_action('genesis_loop', 'genesis_do_loop');
add_action( 'genesis_loop', 'custom_do_loop' , 5 );
function custom_do_loop() {
$include = genesis_get_option('blog_cat');
$exclude = genesis_get_option('blog_cat_exclude') ? explode(',', str_replace(' ', '', genesis_get_option('blog_cat_exclude'))) : '';
$cf = genesis_get_custom_field('query_args'); /** Easter Egg **/
$args = array(
'showposts' => genesis_get_option('blog_cat_num'),
'post_type' => array( 'post' , 'wps_videos' ),
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'wps_vidcategory',
'field' => 'id',
'terms' => array( 92 )
),
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => array( $include )
),
)
);
genesis_custom_loop( $args );
}

// Customize the post meta function
add_filter( 'genesis_post_meta' , 'post_meta_filter' );
function post_meta_filter( $post_meta ) {
global $post;
if ( $post->post_type == 'wps_videos' ) {
$vid_cats = get_the_term_list( $post->ID, 'wps_vidcategory' , '' , ', ' , '' );
$post_meta = sprintf( '<span class="categories">%2$s%1$s</span> ', $vid_cats, 'Filed Under: ' );
}
else {
$post_meta = 'Filed Under: Custom Post Types, Genesis, Tutorials, WordPress';
}
return $post_meta;
}

// Customize the content
remove_action( 'genesis_post_content', 'genesis_do_post_content' );
add_action( 'genesis_post_content', 'custom_do_post_content' );
function custom_do_post_content() {
global $post;
if ( $post->post_type == 'wps_videos') {
if( genesis_get_custom_field('_wps_videoembedcode') != '' ) {
?>
<div id="post-<?php the_ID(); ?>" class="video-entry">
<div class="video-embed">
<?php echo genesis_get_custom_field('_wps_videoembedcode'); ?>
</div><!-- end .video-embed -->
<div class="clear"></div>
<?php genesis_do_post_content(); ?>
</div><!-- end .video-entry -->
<?php
}
} //end wps_videos
else {
genesis_do_post_content();
}
}

genesis();
?>
[/php]

Written by Travis Smith · Categorized: Custom Post Types, Genesis, Tutorials, WordPress

  • « Previous Page
  • 1
  • …
  • 32
  • 33
  • 34
  • 35
  • 36
  • …
  • 61
  • Next Page »
  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in