Multiple post-specific sidebars
-
Dear WordPress enthousiasts,
I am trying to design an elegant method to display post-specific contents into the sidebar.
Inspired by this thread, which ask the same question, I adapted the nice general solution of this thread to query custom fields and display them in the left sidebar area.
add_action( '__before_left_sidebar', 'du_rock_box' ); function du_rock_box() { if ( is_singular( 'post') ) { $rock = get_post_meta( get_the_ID(), 'du_rock', true ); if( ! empty( $rock ) ) { echo '<div class="widget_area">'. '<p style="font-size:24px; color:#0000FF;">du Rock</p>' .'</div>'; echo '<div class="widget_area">'. $rock .'</div>'; } } } add_action( '__before_left_sidebar', 'des_carottes_box' ); function des_carottes_box() { if ( is_singular( 'post') ) { $carottes = get_post_meta( get_the_ID(), 'des_carottes', true ); if( ! empty( $carottes ) ) { echo '<div class="widget_area">'. '<p style="font-size:24px; color:#FF3333;">des Carottes</p>' .'</div>'; echo '<div class="widget_area">'. $carottes .'</div>'; } } }
https://www.hostingpics.net/viewer.php?id=824582Capturede769cran20160817a768013850.png”
I like this solution because it allows to keep the content of the text boxes in the relevant post (contrary to multiplying custom widgets with the custom sidebars plugin)
This is only a proof of concept and I need to be able to further customize the boxes. I have several questions :
– How do I get the handles of what I have created ? Ideally, I’d like to have two separate text boxes, one for each custom field, and be able to customize them with a specific border, layout, etc.
For example, I have tried to shift the text down a bit so that it sits below the title of the post, but.left.tc-sidebar { margin-top: 110px; }
does not work. I conclude that left.tc-sidebar is not the correct handle for my object ?
– Is it possible to add a logo at the top of each text box ? Intuitively, I feel that I am missing a step. My basic understanding of php language tells me that I have just printed some string in the widget area of the left sidebar. So I don’t even have two individual “text widgets” to start with.
Would anyone have suggestions to head into this direction, and possibly php code snippets ?
Thanks in advance,
Benjamin
- The topic ‘Multiple post-specific sidebars’ is closed to new replies.