WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Mar 21 2011

How to Edit Author, Date, Time, Comments Link, Tags and Categories (Post Information) in Genesis

To Edit Author and Date Post Information, simply add the following to your functions.php file. This code uses Genesis specific shortcodes.

[php]// Modify Post Info
add_filter('genesis_post_info', 'my_post_info_filter');
function my_post_info_filter($post_info) {
if (!is_page()) {
$post_info = '[ post_date] by [ post_author_posts_link] at [ post_time] [ post_comments] [ post_edit]'; //remove spaces after initial [
//$post_info = 'Custom text'; //edit this to whatever you'd like.
}
return $post_info;
}[/php]

Available shortcodes are (without the space in front):

  • [ post_date]: Date of publication; e.g., [ post_date format="F j, Y" label="Dated: "] = Dated: March 21, 2011
  • [ post_time]: Time of publication; e.g., [ post_time format="g:i a"] = 1:29 am
  • [ post_author]: Displays author's name; e.g., [ post_author before="<em>" after="</em>"] = <em>Travis Smith</em>
  • [ post_author_link]: Produces the link to Author URL; e.g., [ post_author_link before="" after=""] = Travis Smith
  • [ post_author_posts_link]: Produces the link to Author's Archive; e.g., [ post_author_link before="" after=""] = Travis Smith
  • [ post_comments]: Produces the Comment Link; e.g., [ post_comments zero="No Comments" one="1 Comment" more="% Comments"] =
    • No Comments
    • 1 Comment
    • # Comments
  • [ post_tags]: Displays the tag link list; e.g., [ post_tags sep=", " before="Tags: "] =
  • [ post_categories]: Displays the category link list; e.g., [ post_categories sep=", " before="Posted Under: "] = Posted Under: Genesis, Tutorials
  • [ post_edit]: Displays the Edit link for logged in users; e.g., [ post_edit before="(" after=")"] =

For more shortcodes, see StudioPress's Shortcodes.

Written by Travis Smith · Categorized: Genesis, Tutorials

Mar 20 2011

How to Add More Icons to the Genesis Social Profiles Widget

Nathan Rice wrote a simple but excellent plugin called the Social Profiles Widget. I love the simplicity and only wanted to add one feature, the ability to quickly add my own icons by dumping a folder with the other social profiles folders. So this required changing the code. Because I have not received permission from Nathan Rice to update and contribute to his plugin, I'll share it here. Download: [download id="4"]

[php]<?php
/*
Plugin Name: Social Profiles Widget
Plugin URI: http://www.studiopress.com/plugins/social-profiles-widget
Description: This plugin/widget allows you to insert social profile icons into your sidebar via a widget.
Version: 1.1.1
Author: Nathan Rice
Author URI: http://www.nathanrice.net/

This plugin is released under the GPLv2 license. The images packaged with this plugin are the property of
their respective owners, and do not, necessarily, inherit the GPLv2 license.
*/
/*
Slightly modified by Travis Smith, https://wpsmith.net, to allow for additional icon folders to be uploaded. Simply upload custom folder to the images folder. Be sure to name your icons [SOCIAL]_32x32.* and [SOCIAL]_48x48.* [SOCIAL]=Delicious, Digg, Facebook, Feed, Flickr, Linkedin, Myspace, Stumbleupon, Twitter (e.g., Twitter_32x32.png)
*/
/**
* Register the Widget
*/
add_action('widgets_init', 'social_profiles_widget_register');
function social_profiles_widget_register() {
register_widget('Social_Profiles_Widget');
}

/**
* The Widget Class
*/
if ( !class_exists('Social_Profiles_Widget') ) {
class Social_Profiles_Widget extends WP_Widget {

function Social_Profiles_Widget() {
$widget_ops = array( 'classname' => 'social-profiles', 'description' => __('Displays Social Profile links as icons', 'spw') );
$this->WP_Widget( 'socialprofiles', __('Social Profiles', 'spw'), $widget_ops );
}

var $plugin_imgs_url;

function spw_fields_array( $instance = array() ) {

$this->plugins_imgs_url = plugin_dir_url(__FILE__) . 'images/';

return array(
'feedburner' => array(
'title' => __('RSS/Feedburner URL', 'spw'),
'img' => sprintf( '%s/Feed_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), esc_attr( $instance['size'] ) ),
'img_widget' => sprintf( '%s/Feed_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), '48x48' ),
'img_title' => __('RSS', 'spw')
),
'twitter' => array(
'title' => __('Twitter URL', 'spw'),
'img' => sprintf( '%s/Twitter_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), esc_attr( $instance['size'] ) ),
'img_widget' => sprintf( '%s/Twitter_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), '48x48' ),
'img_title' => __('Twitter', 'spw')
),
'facebook' => array(
'title' => __('Facebook URL', 'spw'),
'img' => sprintf( '%s/Facebook_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), esc_attr( $instance['size'] ) ),
'img_widget' => sprintf( '%s/Facebook_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), '48x48' ),
'img_title' => __('Facebook', 'spw')
),
'linkedin' => array(
'title' => __('Linkedin URL', 'spw'),
'img' => sprintf( '%s/Linkedin_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), esc_attr( $instance['size'] ) ),
'img_widget' => sprintf( '%s/Linkedin_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), '48x48' ),
'img_title' => __('Linkedin', 'spw')
),
'youtube' => array(
'title' => __('YouTube URL', 'spw'),
'img' => sprintf( '%s/Youtube_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), esc_attr( $instance['size'] ) ),
'img_widget' => sprintf( '%s/Youtube_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), '48x48' ),
'img_title' => __('Youtube', 'spw')
),
'flickr' => array(
'title' => __('Flickr URL', 'spw'),
'img' => sprintf( '%s/Flickr_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), esc_attr( $instance['size'] ) ),
'img_widget' => sprintf( '%s/Flickr_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), '48x48' ),
'img_title' => __('Flickr', 'spw')
),
'delicious' => array(
'title' => __('Delicious URL', 'spw'),
'img' => sprintf( '%s/Delicious_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), esc_attr( $instance['size'] ) ),
'img_widget' => sprintf( '%s/Delicious_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), '48x48' ),
'img_title' => __('Delicious', 'spw')
),
'stumbleupon' => array(
'title' => __('StumbleUpon URL', 'spw'),
'img' => sprintf( '%s/Stumbleupon_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), esc_attr( $instance['size'] ) ),
'img_widget' => sprintf( '%s/Stumbleupon_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), '48x48' ),
'img_title' => __('StumbleUpon', 'spw')
),
'digg' => array(
'title' => __('Digg URL', 'spw'),
'img' => sprintf( '%s/Digg_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), esc_attr( $instance['size'] ) ),
'img_widget' => sprintf( '%s/Digg_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), '48x48' ),
'img_title' => __('Digg', 'spw')
),
'myspace' => array(
'title' => __('MySpace URL', 'spw'),
'img' => sprintf( '%s/Myspace_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), esc_attr( $instance['size'] ) ),
'img_widget' => sprintf( '%s/Myspace_%s.png', $this->plugins_imgs_url . esc_attr( $instance['icon_set'] ), '48x48' ),
'img_title' => __('MySpace', 'spw')
),
);
}

function widget($args, $instance) {

extract($args);

$instance = wp_parse_args($instance, array(
'title' => '',
'icon_set' => 'default',
'size' => '48x48'
) );

echo $before_widget;

if ( !empty( $instance['title'] ) )
echo $before_title . $instance['title'] . $after_title;

foreach ( $this->spw_fields_array( $instance ) as $key => $data ) {
if ( !empty ( $instance[$key] ) ) {
printf( '<a href="%s"><img src="%s" alt="%s" /></a>', esc_url( $instance[$key] ), esc_url( $data['img'] ), esc_attr( $data['img_title'] ) );
}
}

echo $after_widget;

}

function update($new_instance, $old_instance) {
return $new_instance;
}

function dir_list($d){
foreach(array_diff(scandir($d),array('.','..')) as $f) {
if(is_dir($d.'/'.$f)) {
$l[]=$f;
}
}
return $l;
}

function form($instance) {
$dir = WP_PLUGIN_DIR.'/social-profiles-widget/images';
$imagefolders = $this->dir_list($dir);
$instance = wp_parse_args($instance, array(
'title' => '',
'icon_set' => 'default',
'size' => '48x48'
) );
?>

<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'spw'); ?>:</label><br />
<input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" style="width:95%;" />
</p>

<p>
<label for="<?php echo $this->get_field_id('icon_set'); ?>"><?php _e('Icon Set', 'spw'); ?>:</label>
<select id="<?php echo $this->get_field_id('icon_set'); ?>" name="<?php echo $this->get_field_name('icon_set'); ?>">
<?php
foreach ($imagefolders as $key => $folder) :
?>
<option style="padding-right:10px;" value="<?php echo $folder; ?>" <?php selected($folder, $instance['icon_set']); ?>><?php _e($folder, 'spw'); ?></option>
<?php endforeach; ?>
</select>
</p>

<p>
<label for="<?php echo $this->get_field_id('size'); ?>"><?php _e('Icon Size', 'spw'); ?>:</label>
<select id="<?php echo $this->get_field_id('size'); ?>" name="<?php echo $this->get_field_name('size'); ?>">
<option style="padding-right:10px;" value="32x32" <?php selected('32x32', $instance['size']); ?>><?php _e('Small', 'spw'); ?> (32px)</option>
<option style="padding-right:10px;" value="48x48" <?php selected('48x48', $instance['size']); ?>><?php _e('Large', 'spw'); ?> (48px)</option>
</select>
</p>

<p><?php _e('Enter the URL(s) for your various social profiles below. If you leave a profile URL field blank, it will not be used.', 'spw'); ?></p>

<?php

foreach ( $this->spw_fields_array( $instance ) as $key => $data ) {
echo '<p>';
printf( '<img style="float: left; margin-right: 3px;" src="%s" title="%s" />', $data['img_widget'], $data['img_title'] );
printf( '<label for="%s"> %s:</label>', esc_attr( $this->get_field_id($key) ), esc_attr( $data['title'] ) );
printf( '<input id="%s" name="%s" value="%s" style="%s" />', esc_attr( $this->get_field_id($key) ), esc_attr( $this->get_field_name($key) ), esc_url( $instance[$key] ), 'width:65%;' );
echo '</p>' . "n";
}

}
}}[/php]

Written by Travis Smith · Categorized: Genesis, Plugins

Mar 19 2011

How to Programatically Set the Default Page Layout

Like I mentioned on a previous post, do you worry that in their snooping they will change the default page layout to something other than the default on archive pages (ex: category).

[php]// Register default site layout option
genesis_set_default_layout( 'full-width-content' );[/php]

Written by Travis Smith · Categorized: Genesis, Tutorials

Mar 18 2011

How to Make the Top Section (above Sidebar/Content) Widgetized in the Genesis Framework

To make the area before the loop (or rather, the area before the sidebar/content area after the header) widgetized, add the following to your functions.php file:

[php]
genesis_register_sidebar( array(
'id' => 'genesis_before_content_sidebar_widget',
'name' => __( 'Before Content', 'genesis' ),
'description' => __( 'This is the main section after the header before the content/sidebar.', 'focus' ),
) );

add_action( 'genesis_before_content_sidebar_wrap', 'genesis_before_content_sidebar_widget_box' );
function genesis_before_content_sidebar_widget_box() {
if ( is_single() || is_home() || is_category || is_archive || is_page || is_front_page ) {
?>
<?php if ( is_active_sidebar( 'genesis_before_content_sidebar_widget' ) ) : ?>
<div class="before-content">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('genesis_before_content_sidebar_widget') ) : ?>
<div class="widget">
<h3><?php _e( 'Top Widget Area', 'focus' ); ?></h3>
<p><?php _e("This is an example of a widget area that you can place text to describe a product or service. You can also use other WordPress widgets such as recent posts, recent comments, a tag cloud or more.", 'genesis'); ?></p>
</div><!-- end .widget -->
<?php endif; ?>
</div>
<?php endif; ?>
<?php
} }
[/php]

Written by Travis Smith · Categorized: Genesis, Tutorials

Mar 17 2011

How to Force a Specific Layout to Prevent User Error

Ever worry that your client will change or break your custom pages you built for them (e.g., homepage, 404 page, etc.)? Or, do you worry that in their snooping they will change the default page layout to something other than the default on archive pages (ex: category). The example below is to set the category and archive pages to Sidebar-Content-Sidebar and home page to Sidebar-Content.

[php]
// Force layout on category
add_filter('genesis_pre_get_option_site_layout', 'be_category_layout');
function be_category_layout($opt) {
if ( is_category() || is_archive() )
$opt = 'sidebar-content-sidebar';
return $opt;
}
// Force layout on home
add_filter('genesis_pre_get_option_site_layout', 'be_home_layout');
function be_home_layout($opt) {
if ( is_home() ) //May also be is_front_page()
$opt = 'sidebar-content';
return $opt;
}
[/php]

The available layout options are

  • Content/Sidebar = ‘content-sidebar’
  • Sidebar/Content = ‘sidebar-content’
  • Content/Sidebar/Sidebar = ‘content-sidebar-sidebar’
  • Sidebar/Sidebar/Content = ‘sidebar-sidebar-content’
  • Sidebar/Content/Sidebar = ‘sidebar-content-sidebar’
  • Full Width Content = ‘full-width-content’

Written by Travis Smith · Categorized: Genesis, Tutorials

  • « Previous Page
  • 1
  • …
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • Next Page »
  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

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