WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Jun 01 2011

Genesis Grid Loop: How to Set Features to a Specific Category and Non-Features/Grid Posts to a Separate (Another) Category

In order to set your Genesis Grid Loop 'features', which are the number of posts that will show at the top of the page when using the Grid Loop, to one specific category or categories and the non-features or grid posts to another category or set of categories, you will need to adjust your grid_loop_helper function.

Here is a simple way of displaying posts via categories via the Grid loop calling genesis_grid_loop() twice.
[php highlight="15-16, 29-30, 33-39"]function child_grid_loop_helper() {
global $paged;
if ( function_exists( 'genesis_grid_loop' ) ) {
//set featured grid_args
$grid_args_featured = array(
'features' => 1,
'feature_image_size' => 'child_full',
'feature_image_class' => 'aligncenter post-image',
'feature_content_limit' => 100,
'grid_image_size' => 'child_thumb',
'grid_image_class' => 'aligncenter post-image',
'grid_content_limit' => 0,
'more' => '',
'posts_per_page' => 1,
'post_type' => 'books_fbd',
'cat' => '8',
'paged' => $paged
);
//set non-featured grid_args
$grid_args_rest = array(
'features' => 0,
'feature_image_size' => 'child_full',
'feature_image_class' => 'aligncenter post-image',
'feature_content_limit' => 100,
'grid_image_size' => 'child_thumb',
'grid_image_class' => 'aligncenter post-image',
'grid_content_limit' => 0,
'more' => '',
'posts_per_page' => 4,
'post_type' => 'books_fbd',
'cat' => '7',
'paged' => $paged
);

//assuming that features won't go beyond 1 page
if ( ($grid_args_featured['paged'] > 1) || ($grid_args_past['paged'] > 1) )
genesis_grid_loop( $grid_args_rest ); //do not show featured after page 1
else {
genesis_grid_loop( $grid_args_featured );
genesis_grid_loop( $grid_args_rest );
}

} else {
genesis_standard_loop();
}
} [/php]

However, I have posted on the StudioPress forums, which creates another argument for 'features_cat' suggesting some edits for the genesis_grid_loop() function.

Written by Travis Smith · Categorized: Genesis, Genesis Grid Loop, Tutorials

May 31 2011

How to Display Posts from a Specific Category using Genesis Grid Loop

To display posts from a specific category or categories, you need to add a 'cat' argument to the $grid_args array. StudioPress gives a good introductory tutorial, How to Use the Genesis Grid Loop, on how to set this up.

In the StudioPress tutorial, you are given this example for your home.php.
[php highlight="17"]<?php
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'child_grid_loop_helper' );
/** Add support for Genesis Grid Loop **/
function child_grid_loop_helper() {
if ( function_exists( 'genesis_grid_loop' ) ) {
genesis_grid_loop( array(
'features' => 2,
'feature_image_size' => 0,
'feature_image_class' => 'alignleft post-image',
'feature_content_limit' => 0,
'grid_image_size' => 'grid-thumbnail',
'grid_image_class' => 'alignleft post-image',
'grid_content_limit' => 0,
'more' => __( '[Continue reading...]', 'genesis' ),
'posts_per_page' => 6,
'cat' => '6,7' //enter your category IDs here separated by commas in ' '
) );
} else {
genesis_standard_loop();
}
}

/** Remove the post meta function for front page only **/
remove_action( 'genesis_after_post_content', 'genesis_post_meta' );

genesis();[/php]

Written by Travis Smith · Categorized: Genesis, Genesis Grid Loop, Tutorials

May 26 2011

Slight Upgrade/Revision to WP-Cycle to Allow Page IDs

One thing that has bugged me about WP-Cyle is that I had to include hard-coded URLs to linkify the rotating images. This is problem matic when I change my URLs, etc. So I just want to enter page IDs and allow WordPress to properly assign the proper URL. Download the revised/upgraded WP Cycle: [download id="12"].

For those who want to know what I did, here's what I added:

On line 393, the original code contains:
[php]if($value['image_links_to'])
$input[$key]['image_links_to'] = clean_url($value['image_links_to']);[/php]

I changed it to:
[php]if($value['image_links_to']) {
$checkhttp = substr($value['image_links_to'], 0, 4);
if ($checkhttp == 'http')
$input[$key]['image_links_to'] = clean_url($value['image_links_to']);
}[/php]

Then on line 416 in the foreach section, the original code contains:
[php]foreach((array)$wp_cycle_images as $image => $data) {
if($data['image_links_to'])
echo '<a href="'.$data['image_links_to'].'">';

echo '<img src="'.$data['file_url'].'" width="'.$wp_cycle_settings['img_width'].'" height="'.$wp_cycle_settings['img_height'].'" class="'.$data['id'].'" alt="" />';

if($data['image_links_to'])
echo '</a>';

echo $newline;
}
[/php]

I changed it to:
[php highlight="2,3,4,5,6,7,8"]foreach((array)$wp_cycle_images as $image => $data) {
if($data['image_links_to']) {
$checkhttp = substr($data['image_links_to'], 0, 4);
if ($checkhttp != 'http') {
$id = intval($data['image_links_to']);
$data['image_links_to'] = get_permalink( $id );
}
echo '<a href="'.$data['image_links_to'].'">';
}

echo '<img src="'.$data['file_url'].'" width="'.$wp_cycle_settings['img_width'].'" height="'.$wp_cycle_settings['img_height'].'" class="'.$data['id'].'" alt="" />';

if($data['image_links_to'])
echo '</a>';

echo $newline;
}
[/php]

Written by Travis Smith · Categorized: Genesis, Plugins, Tutorials

May 25 2011

Remove or Change Post Info or Post Meta

To remove the post meta, simply use the following code:
[php]// Remove post meta
remove_action('genesis_after_post_content', 'genesis_post_meta');[/php]

To customize the post meta, simply use the following code:
[php]// Customize the post meta function
add_filter('genesis_post_meta', 'post_meta_filter');
function post_meta_filter($post_meta) {
if (!is_page()) {
$post_meta = '<span class="categories">Filed Under: </span> ';
return $post_meta;
}}[/php]

To remove the post info, simply use the following code:
[php]// Remove the post info function
remove_action('genesis_before_post_content', 'genesis_post_info');[/php]

To Customize the post info, go to my post here How to Edit Author, Date, Time, Comments Link, Tags and Categories (Post Information) in Genesis.

Written by Travis Smith · Categorized: Genesis, Tutorials

May 24 2011

Employees Custom Post Type for WordPress with a Genesis Page Template

So for one of my clients, they had a page of employees displayed. However, it was not organized in any manner and the HTML and CSS were a bit messy (and if I can see that, then...). So I created an Employees custom post type and a Genesis page template. You can read through the employees custom post type tutorial or download the necessary files (see instructions below).

Create Employees Custom Post Type

To create the Employees Custom Post Type, add this code to your functions.php:
[php]//employees.png is in the zip file below
function my_init() {
register_post_type('wps_employees', array(
'label' => 'Employees',
'description' => 'employees',
'menu_icon' => CHILD_URL . '/images/employees.png', //for this to work in non-Genesis themes, replace CHILD_URL with your theme constant
'public' => true,'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug' => 'employees'),
'query_var' => true,
'supports' => array('title','editor','excerpt','custom-fields','revisions','thumbnail',),
'labels' => array (
'name' => 'Employees',
'singular_name' => 'Employee',
'menu_name' => 'Employees',
'add_new' => 'Add Employee',
'add_new_item' => 'Add New Employee',
'edit' => 'Edit',
'edit_item' => 'Edit Employee',
'new_item' => 'New Employee',
'view' => 'View Employee',
'view_item' => 'View Employee',
'search_items' => 'Search Employees',
'not_found' => 'No Employees Found',
'not_found_in_trash' => 'No Employees Found in Trash',
'parent' => 'Parent Employee',
),
)
);
}
add_action('init' , 'my_init');[/php]

Create Employees Custom Post Type Genesis Page Template

To create the Genesis Employees Custom Post Type Page Template (not applicable to other Themes), simply open a new file in your favorite text editor and save it as page_employees.php. Then enter this code into it:
[php]<?php
/**
*
* Template Name: Employees
* This file handles employees custom post types within a page.
*
*/

//Add Image to the Custom Loop
add_action('genesis_before_post_content', 'genesis_do_feat_img');
function genesis_do_feat_img() {
$img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option('image_size'), 'attr' => array( 'class' => 'alignright post-image-right' ) ) );
printf( '<a href="%s" title="%s">%s</a>', get_permalink(), the_title_attribute('echo=0'), $img );
}

//Remove Post Information
remove_action('genesis_before_post_content', 'genesis_post_info');
//Remove Tags/Categories and Post Meta
remove_action('genesis_after_post_content', 'genesis_post_meta');

//Create Custom Loop
remove_action('genesis_loop', 'genesis_do_loop');
add_action('genesis_loop', 'custom_do_cat_loop');

function custom_do_cat_loop() {
global $query_args; // any wp_query() args
$args = array( 'post_type' => 'wps_employees' , 'posts_per_page' => 10 , 'orderby' => 'post_title' , 'order' => 'ASC' );
genesis_custom_loop(wp_parse_args($query_args, $args));
}

genesis();

?>[/php]

Employees Custom Post Type Shortcode

For those who prefer a shortcode over a page (or those who do not have the Genesis Framework, other than going to buy Genesis), here is a shortcode for Employees Custom post type (therefore, this shortcode does not need the Genesis framework to work and will work in any theme). This code was first presented by Mark Jaquith and his presentation in Tampa about Custom Post Types.

In your functions.php file, add the following:
[php]function wps_employees_posting() {
global $post;
$xglobals = $GLOBALS;
$args = array( 'post_type' => 'wps_employees' , 'posts_per_page' => 10 , 'orderby' => 'post_title' , 'order' => 'ASC' );
$employeesloop = new WP_Query( $args );
$wps_content_return = '';
while ( $employeesloop->have_posts() ): $employeesloop->the_post() ;
$wps_content_return .= '<div class="entry-content wps_employees">';
$wps_content_return .= get_the_post_thumbnail( $post->ID, 'thumbnail', array('class' => "alignright attachment-$size") );
$wps_content_return .= "<strong>";
$wps_content_return .= get_the_title();
$wps_content_return .= "</strong><br />";
if (!empty( $post->post_excerpt ) )
$wps_content_return .= "<em>".$post->post_excerpt."</em>";
$wps_content_return .= "";
$wps_content_return .= get_the_content();
$wps_content_return .= "</div>";
endwhile;
$GLOBALS = $xglobals;
return $wps_content_return;
}
[/php]

In function my_init() that we previously created, add this line before the close bracket (}):
[php]add_shortcode( 'employees' , 'wps_employees_posting' );[/php]

See also my post "How to Create a WordPress Custom Post Type Template in Genesis," for a blank Custom Post Type Page Template.

CSS

In this example, in displaying the featured image, I use the class post-image-right. Here is the CSS I used with it, so add this to your style.css.
#content .post-image-right {
margin: 0 0 10px 10px;
padding: 4px;
border: 1px solid #DDDDDD;
}

Download Files

For those who prefer to download everything, here's the file: [download id="11"].

You want to place the employees.php file in your theme folder. For Genesis users, place this file in your lib Child Theme folder. If it does not exist (and it probably won't), create it (path: /wp-content/themes/childtheme/lib/), and ignoring the previous code, add only the following code:
[php]require_once(CHILD_DIR.'/lib/employees.php');[/php]

Important: You want to add this code after:
[php]// Start the engine
require_once(TEMPLATEPATH.'/lib/init.php');[/php]

Then place the page_employees.php file in your root child theme folder (so path: /wp-content/themes/childtheme/). And then place the employees.png image in your images folder in your child theme folder (so path: /wp-content/themes/childtheme/images/).

So now you have the employees custom post type ready for use and a page template for your Genesis site! Have I missed anything?

Written by Travis Smith · Categorized: Genesis, Tutorials

  • « Previous Page
  • 1
  • …
  • 3
  • 4
  • 5
  • 6
  • 7
  • …
  • 18
  • Next Page »
  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

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