WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

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

May 18 2011

How to Remove or Move the Genesis Footer below the #wrap

It is easy to remove.move the footer, simply add this to your functions.php.

To remove the footer, use:
[php]remove_action( 'genesis_footer', 'genesis_do_footer' );[/php]

To move the footer below the body #wrap, use:
[php]remove_action( 'genesis_footer', 'genesis_do_footer' );
add_action( 'wp_footer', 'genesis_do_footer' );[/php]

Written by Travis Smith · Categorized: Genesis, Tutorials

May 16 2011

A Genesis iFrame Page Template

***UPDATED: 5/16***
Recently, I needed an iFrame page template so that I could create pages that appear on multiple external websites, especially Facebook pages. So in order to do this, I had to remove the header, navigation, footer, breadcrumbs, and post title. For styling, I added an iframe custom body class. Here is a Sample iFrame Page.

So here is the code from the page:
[php]
<?php
/*
*Template Name: iframe
*/

remove_action('genesis_header', 'genesis_header_markup_open', 5);
remove_action('genesis_header', 'genesis_do_header');
remove_action('genesis_after_header', 'genesis_do_nav');
remove_action('genesis_after_header', 'genesis_do_subnav');
remove_action('genesis_footer', 'genesis_do_footer');
remove_action('genesis_before_footer', 'metric_include_footer_widgets');
remove_action('wp_head', 'genesis_header_scripts');
remove_action('genesis_before_loop', 'genesis_do_breadcrumbs');
remove_action('genesis_post_title', 'genesis_do_post_title');
add_filter('body_class','my_body_classes');
function my_body_classes($classes) {
$classes[] = "iframe";
return $classes;
}

genesis();
?>
[/php]

For example, it can be styled by adding something like the following:
[html]body.iframe {
background: none repeat scroll 0 0 #FFFFFF;
}[/html]

You could also remove the sidebar or you could just force the layout to be full-width:
[php]add_filter('genesis_pre_get_option_site_layout', 'wps_iframe_layout');
function wps_iframe_layout($opt) {
$opt = 'full-width-content';
return $opt;
} [/php]

The possibilities of this are endless! I would love to know what you do with this!

Written by Travis Smith · Categorized: Genesis, Tutorials

  • « Previous Page
  • 1
  • …
  • 40
  • 41
  • 42
  • 43
  • 44
  • …
  • 60
  • Next Page »

Need Help?

Please let us know how we can help you!

Get Help

Recommendations

Genesis WordPress Framework
Sucuri Security
Gravity Forms
GetSoliloquy
Get Envira
Scribe SEO
BackupBuddy
WordPress Video User Manuals

Recent Posts

  • Solving WordPress 5XX Server Errors on SiteGround
  • Hiding an User in the WordPress Admin
  • Custom Rewrite Rules for Custom Post Types and Taxonomies
  • WordPress JavaScript Manager Native Functions
  • Causes of WordPress Site Performance Slowdown

About Travis

As a WordPress enthusiast, developer, and speaker, Travis writes about what he learns in WordPress trying to help other WordPress travelers, beginners and enthusiasts with tutorials, explanations, & demonstrations.

  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

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