Community Forums › Forums › Archived Forums › General Discussion › Help creating custom Widget
Tagged: display posts shortcode, widget
- This topic has 4 replies, 4 voices, and was last updated 9 years, 2 months ago by Tom.
-
AuthorPosts
-
December 24, 2014 at 6:16 am #135243andrewjzhaoMember
Hello,
I have 12 categories:
January
February
March
April
May
June
July
August
September
October
November
DecemberI would like a widget at the top of my page that displays featured posts from the current month. How can that be possible?
http://themepartyideasforadults.comDecember 24, 2014 at 9:16 am #135259DTHkellyMemberYou need a conditional. It could be based on page name.
http://www.carriedils.com/add-widget-area-below-nav/
Also, select your genesis hook:
http://genesistutorials.com/visual-hook-guide/
https://wordpress.org/plugins/genesis-visual-hook-guide/December 24, 2014 at 5:07 pm #135282Ren VenturaMemberYes, you'll need to know what pages and where at on those pages you want to display the featured posts (probably something like genesis_before_content) but the output will need to be generated using a custom query and loop.
Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren
December 31, 2014 at 1:17 pm #135760TomParticipant@andrewjzhao: Here is a method to do this without writing a custom loop. The shortcode may be used in a widget or template file.
http://keypresswp.com/display-posts-common-multiple-categories/
Choose your next site design from over 350 Genesis themes.
[ Follow me: Twitter ] [ Follow Themes: Twitter ] [ My Favourite Webhost ]January 1, 2015 at 10:17 am #135493TomParticipant@andrewjzhao: Assuming you want a widget at the top of your home page you can use the existing (and currently empty) Home - Top widget area. This solution that does not require writing a custom loop but does require the addition of some code snippets to your functions.php and style.css files.
1. You've already categorized the posts by month; add a category of "Featured" to the posts you want to display in the widget.
2. Install the plugin Display Posts Shortcode by Bill Erickson. From the WordPress Codex: To add shortcode support to sidebar widgets, you can install a plugin, or use the below code (in functions.php):
add_filter( 'widget_text', 'shortcode_unautop' ); add_filter( 'widget_text', 'do_shortcode' );
While you're in functions.php, also add this slightly modified code from Bill Erickson to wrap the post title in h2 tags:
/** * Add classes to Display Posts Shortcode plugin * @author Bill Erickson * @link http://wordpress.org/extend/plugins/display-posts-shortcode/ */ function be_display_posts_classes( $output, $atts, $image, $title, $date, $excerpt, $inner_wrapper ) { $classes = 'listing-item'; // Counter global $dps_counter; $classes .= ' dps-list-item-' . $dps_counter; $dps_counter++; // Current Page global $dps_current_page; if( $dps_current_page == get_permalink() ) $classes .= ' current'; // Now let's rebuild the output. $output = '<' . $inner_wrapper . ' class="' . $classes . '">' . $image . '<h2 class="entry-title">' . $title . '</h2>' . $date . $excerpt . '</' . $inner_wrapper . '>'; // Finally we'll return the modified output return $output; } add_filter( 'display_posts_shortcode_output', 'be_display_posts_classes', 10, 7 );
3. Now you can use a shortcode like this to display your posts. The only maintenance is to update the shortcode when you need to select for a different month. There are several customizations available via shortcode and others via code snippets.
[display-posts taxonomy="category" tax_term="featured" taxonomy_2="category" tax_2_term="december" include_excerpt="true" image_size="entry-image" posts_per_page="3"]
4. Add some minor CSS to the child theme stylesheet:
.display-posts-listing img { margin: 24px 0px; } .excerpt-dash { display: none; } .excerpt, .more-link{ margin: 0 0 24px; }
The end result looks like this:
Choose your next site design from over 350 Genesis themes.
[ Follow me: Twitter ] [ Follow Themes: Twitter ] [ My Favourite Webhost ] -
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.