Advertisement
Guest User

sidebar inter posts

a guest
Jun 15th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. /* WIDGET AREAS aka SIDEBARS INBETWEEN POSTS IN LOOP OF INDEX PAGE */
  2.  
  3. add_action( 'after_setup_theme', 'twentyfifteen_child_setup' );
  4.  
  5. function twentyfifteen_child_setup() {
  6. add_action( 'widgets_init', 'twentyfifteen_child_widgets_init' );
  7. add_filter( 'body_class', 'twentyfifteen_child_body_class' );
  8. add_action( 'the_post', 'twentyfifteen_child_inter_posts_sidebars' );
  9. }
  10.  
  11. //register sidebar for inbetween posts
  12.  
  13. function twentyfifteen_child_widgets_init() {
  14.  
  15. register_sidebar( array(
  16. 'name' => __( 'First Inter-Posts Widget Area ', 'twentyfifteen' ),
  17. 'id' => 'inter-posts-1',
  18. 'description' => __( 'Add widgets here to appear between post 1 and 2 in your index page.', 'twentyfifteen' ),
  19. 'before_widget' => '<aside id="%1$s" class="widget inter-post-widget %2$s">',
  20. 'after_widget' => '</aside>',
  21. 'before_title' => '<h2 class="widget-title">',
  22. 'after_title' => '</h2>',
  23. ) );
  24.  
  25. }
  26.  
  27. //body class correction
  28.  
  29. function twentyfifteen_child_body_class( $classes ) {
  30.  
  31. if ( is_active_sidebar( 'inter-posts-1' ) ) {
  32. if( is_home() ) $classes[] = 'widgets-between-posts';
  33. }
  34. return $classes;
  35. }
  36.  
  37. //widget output between posts in index page
  38.  
  39. function twentyfifteen_child_inter_posts_sidebars() {
  40. global $wp_query;
  41. if( is_home() && $wp_query->current_post == 1 ) {
  42. dynamic_sidebar( 'inter-posts-1' );
  43. }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement