Community Forums › Forums › Archived Forums › Design Tips and Tricks › After Content Widget not Displayed
- This topic has 4 replies, 2 voices, and was last updated 6 years, 9 months ago by sunnypapabear.
-
AuthorPosts
-
July 27, 2017 at 6:53 pm #209651sunnypapabearMember
If someone could tell me whats wrong with the below code, I would really appreciate it.
I added the below to my Prose Theme Function.php file. The idea was to add two Widgets after the content on the Front Page (Page 1522) and then add a single Widget to a Page entitled "askpeter" (Page 1584). The two Widgets on the Front Page work fine, but the Single Widget does not show up on http://petercruikshank.com/dev/askpeter/
// Register page widget areas
genesis_register_sidebar( array(
'id' => 'page-widget-left',
'name' => __( 'Page Widget Left', 'nabm' ),
'description' => __( 'This is the left widget area for a specific page.', 'nabm' ),
) );
genesis_register_sidebar( array(
'id' => 'page-widget-right',
'name' => __( 'Page Widget Right', 'nabm' ),
'description' => __( 'This is the right widget area for a specific page.', 'nabm' ),
) );
genesis_register_sidebar( array(
'id' => 'page-widget-single',
'name' => __( 'Page Widget Single', 'nabm' ),
'description' => __( 'This a widget area for a specific page.', 'nabm' ),
) );// Add the page widget in the content
add_action( 'genesis_after_post_content', 'nabm_add_page_content' );
function nabm_add_page_content() {
if ( is_page('1522') ) {echo '<div class="page-widget-container"><div class="wrap">';
genesis_widget_area ('page-widget-left', array(
'before' => '<div class="page-widget one-half first">',
'after' => '</div>',
) );genesis_widget_area ('page-widget-right', array(
'before' => '<div class="page-widget one-half">',
'after' => '</div>',
) );echo '</div></div>';
}
}{
if ( is_page('1584') ) {echo '<div class="page-widget-container"><div class="wrap">';
genesis_widget_area ('page-widget-single', array(
'before' => '<div class="page-widget">',
'after' => '</div>',
) );echo '</div></div>';
}
http://petercruikshank.com/dev
}July 28, 2017 at 3:57 am #209658Victor FontModeratorYou are closing the function before the second if statement can execute. You have too many brackets. Here is the corrected code:
// Add the page widget in the content add_action( 'genesis_after_post_content', 'nabm_add_page_content' ); function nabm_add_page_content() { if ( is_page('1522') ) { echo '<div class="page-widget-container"><div class="wrap">'; genesis_widget_area ('page-widget-left', array( 'before' => '<div class="page-widget one-half first">', 'after' => '</div>', ) ); genesis_widget_area ('page-widget-right', array( 'before' => '<div class="page-widget one-half">', 'after' => '</div>', ) ); echo '</div></div>'; } if ( is_page('1584') ) { echo '<div class="page-widget-container"><div class="wrap">'; genesis_widget_area ('page-widget-single', array( 'before' => '<div class="page-widget">', 'after' => '</div>', ) ); echo '</div></div>'; } }
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?July 28, 2017 at 9:57 am #209675sunnypapabearMemberThanks that resolved the issue. Appreciate the correction. You by chance don't have a solution for retaining HTML formatting when you use Excerpt in the Genesis Featured Page (Advanced)?
July 28, 2017 at 1:59 pm #209685Victor FontModeratorYes, if you Google this you'll find hundreds of articles about retaining the formatting. Brad Dalton as a good article on this as well.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?July 29, 2017 at 2:04 pm #209719sunnypapabearMemberI discovered the below solution that allows HTML in the Excerpt, when using Genesis Featured Page Advanced. The only issue is, while it does allow HTML, the spacing is greatly exaggerated - including the space at the top of the text excerpt. If you look at http://PeterCruikshank.com/dev and then at the bottom right widget (Ask Peter: Author Q & A) you will see the issue I'm talking about. Looks nothing like the Page itself (click on Read More...) Any suggestions on how I can correct the line spacing issue and I think I would have a winner here.
function custom_wp_trim_excerpt($text) {
$raw_excerpt = $text;
if ( '' == $text ) {
$text = get_the_content('');
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$excerpt_length = apply_filters('excerpt_length', 80);
$excerpt_more = apply_filters( 'excerpt_more', ' ' . '[…]' );
$words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
if ( count($words) > $excerpt_length ) {
array_pop($words);
$text = implode(' ', $words);
$text = $text . $excerpt_more;
$text = force_balance_tags( $text );
} else {
$text = implode(' ', $words);
}
}
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'custom_wp_trim_excerpt'); -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.