Community Forums › Forums › Archived Forums › Design Tips and Tricks › Backcountry: Make Widget Category Titles on Front Page "Clickable" to Category
Tagged: backcountry, widget titles
- This topic has 12 replies, 2 voices, and was last updated 10 years, 10 months ago by rfmeier.
-
AuthorPosts
-
June 5, 2013 at 5:23 pm #44243kaboodleMember
Everything the latest version including Genesis 2.0 (which works like a champ BTW! Nice work guys!).
http://www.thehealthycookingblog.com
Here's what I'm trying to do: Home Top Left, Right, Bottom Widget Titles example: Arthritis -- I would like the title to be clickable to the selected category.
Any thoughts?
Thanks
http://www.thehealthycookingblog.comJune 5, 2013 at 7:12 pm #44252rfmeierMemberHello,
I am guessing some custom code will have to hook the widget titles and create a link. What widget are you using?
June 5, 2013 at 7:45 pm #44257kaboodleMemberjust the Genesis Featured Posts, nice and simple. If it were a plugin I'd edit it right in there, but I'm not exactly sure where to go in the framework to fool around, and not sure that I really want to wade into those waters with out at least a point in the right direction if you know what I mean!
June 5, 2013 at 8:12 pm #44258rfmeierMemberI threw this snippet together. It hooks the WordPress 'widget_title' filter.
Note, this will create a category link on all pages using this widget for all pages. If you just want it on the home page you can check the page.
I hope this helps.
June 5, 2013 at 8:24 pm #44259kaboodleMemberyou rock! so I want to throw this into Genesis Hooks right, with 'widget title' and then create a .php file using your snippet and load it up into the theme folder, is that correct?
June 6, 2013 at 7:19 am #44290rfmeierMemberAll you have to do is paste that code into your theme's function.php file.
Let me know if you run into any issues.
June 6, 2013 at 7:37 am #44295kaboodleMemberjust did it, got this Warning: Missing argument 2 for custom_widget_title() in /home/goodcook/public_html/wp-content/themes/backcountry/functions.php on line 72
June 6, 2013 at 7:40 am #44296rfmeierMemberHello,
Arg. I updated the code above. It will now account for variables not being passed. Sorry about that.
June 6, 2013 at 7:42 am #44297kaboodleMemberthis is the whole shadoobie. Line 72 according to PSDPad would be
function custom_widget_title( $title, $instance, $id_base ){
<?php
/** Start the engine */
require_once( get_template_directory() . '/lib/init.php' );/** Create additional color style options */
add_theme_support( 'genesis-style-selector', array( 'backcountry-blue' => 'Blue', 'backcountry-green' => 'Green', 'backcountry-red' => 'Red' ) );/** Child theme (do not remove) */
define( 'CHILD_THEME_NAME', 'Backcountry Child Theme' );
define( 'CHILD_THEME_URL', 'http://www.studiopress.com/themes/backcountry' );$content_width = apply_filters( 'content_width', 470, 400, 910 );
/** Add new image sizes */
add_image_size( 'home-bottom', 170, 90, TRUE );
add_image_size( 'home-middle', 265, 150, TRUE );
add_image_size( 'home-mini', 50, 50, TRUE );/** Add support for custom background */
add_custom_background();/** Add support for custom header */
add_theme_support( 'genesis-custom-header', array( 'width' => 960, 'height' => 120 ) );/** Reposition the primary navigation */
remove_action( 'genesis_after_header', 'genesis_do_nav' );
add_action( 'genesis_before_header', 'genesis_do_nav' );/** Add description to secondary navigation */
add_filter( 'walker_nav_menu_start_el', 'add_description', 10, 4 );
function add_description( $item_output, $item, $depth, $args ) {$args = (array) $args;
if ( $args['theme_location'] != 'primary' ) {
return preg_replace( '/(<a.*?>[^<]*?)</', '$1' . "<span class=\"menu-description\">{$item->post_content}</span><", $item_output );
}
else {
return $item_output;
}}
/** Add home top section to homepage */
add_action( 'genesis_before_content_sidebar_wrap', 'backcountry_home_top' );
function backcountry_home_top() {if ( is_front_page() && is_active_sidebar( 'home-top' ) ) {
echo '<div id="home-top">';
dynamic_sidebar( 'home-top' );
echo '</div><!-- end #home-top -->';
}}
add_filter( 'widget_title', 'custom_widget_title', 10, 3 );
/**
* Callback for WordPress 'widget_title' filter.
*
* Create a link for the title of the Genesis Featured Widget if a category is
* specified.
*
* @package WordPress
* @category Widget
* @author Ryan Meier http://www.rfmeier.net
*
* @param string $title The widget title
* @param object $instance The instance of the current widget
* @param string $id_base the base id
* @return string $title The widget title
*/
function custom_widget_title( $title, $instance, $id_base ){
// if not the featured image post, return title
if( 'featured-post' != $id_base )
return $title;
// if the instance does not specify a category, return title
if( empty( $instance['posts_cat'] ) )
return $title;
// get the category link from the id
$category_link = get_category_link( $instance['posts_cat'] );
// get the category name from the id
$category_name = get_the_category_by_ID( $instance['posts_cat'] );
// build the category link
$title_link = sprintf( '<a href="%s" title="%s">%s</a>',
esc_url( $category_link ),
esc_attr( $category_name ),
esc_html( $title ) );
// return the category link title
return $title_link;
}/** Customize the post info function */
add_filter( 'genesis_post_info', 'backcountry_post_info_filter' );
function backcountry_post_info_filter( $post_info ) {return '[post_date] by [post_author_posts_link] · [post_comments] [post_edit]';
}
/** Customize the post meta function */
add_filter( 'genesis_post_meta', 'backcountry_post_meta_filter' );
function backcountry_post_meta_filter( $post_meta ) {return '[post_categories before="Filed Under: "] · [post_tags before="Tagged: "]';
}
/** Add after post ad section */
add_action( 'genesis_after_post_content', 'backcountry_after_post_ad', 9 );
function backcountry_after_post_ad() {if ( is_single() && is_active_sidebar( 'after-post-ad' ) ) {
echo '<div class="after-post-ad">';
dynamic_sidebar( 'after-post-ad' );
echo '</div><!-- end .after-post-ad -->';
}}
/** Add support for 3-column footer widgets */
add_theme_support( 'genesis-footer-widgets', 4 );/** Register widget areas */
genesis_register_sidebar( array(
'id' => 'home-top',
'name' => __( 'Home Top', 'backcountry' ),
'description' => __( 'This is the home top section.', 'backcountry' ),
) );
genesis_register_sidebar( array(
'id' => 'home-left',
'name' => __( 'Home Left', 'backcountry' ),
'description' => __( 'This is the home left section.', 'backcountry' ),
) );
genesis_register_sidebar( array(
'id' => 'home-right',
'name' => __( 'Home Right', 'backcountry' ),
'description' => __( 'This is the home right section.', 'backcountry' ),
) );
genesis_register_sidebar( array(
'id' => 'home-bottom',
'name' => __( 'Home Bottom', 'backcountry' ),
'description' => __( 'This is the home bottom section.', 'backcountry' ),
) );
genesis_register_sidebar( array(
'id' => 'after-post-ad',
'name' => __( 'After Post Ad', 'magazine' ),
'description' => __( 'This is the after post ad section.', 'backcountry' ),
) );/* CSS Document */June 6, 2013 at 7:44 am #44299kaboodleMemberlike a charm man, can I send you some loot when she pays me for your help?
June 6, 2013 at 7:46 am #44300rfmeierMemberI am glad I could help. Sorry about the error before, I assumed all the variables would be passed. I am completely open to donations if you feel up to it.
You can reach me at [email protected]
June 6, 2013 at 8:01 am #44305kaboodleMemberAs soon as she pays up, and she's good about it, I'll get you some loot (just got clobbered yesterday on Child Support -- they cleaned me out!). In the meantime, how can I give you some love with some social signals, etc.
Chris -- email me your paypal address please
June 6, 2013 at 8:11 am #44309rfmeierMemberThis reply has been marked as private. -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.