how to add new widget to dynamic sidebar
-
After suffering with the sudden blank white page syndrome, I have recently switched from my own cobbled-together theme to creating and using a child of Twenty Twelve. I would like to put 5 random post links (but excluding posts from three categories) on the sidebar.
On my previous theme, I had the postlinks hard-coded in php onto the sidebar. It worked perfectly:
<!-- start random post links --> <h2><?php _e('5 randomly chosen posts:'); ?></h2> <ul> <?php // omit posts from categories 4, 6, 8 $args = array( 'posts_per_page' => 5, 'orderby' => 'rand', 'category__not_in' => array(4, 6, 8) ); $rand_posts = get_posts( $args ); foreach( $rand_posts as $post ) : ?> <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul> <!-- end random post links -->
But with this new child theme, I have a dynamic sidebar so cannot use a text widget and add the coding that way. It appears that the text widget will not permit php coding.
With only enough knowledge about coding to get myself in trouble, I’m guessing that if I put the required code into the child’s functions file. But from there, I’m stymied.
I’ve looked for a random posts plugin but do not see one that will omit categories and/or is compatible with the latest version of WP.
Thank you for any help you can offer.
E Morris, etherwork [dot] net [slash] blog <- please leave unlinked to help prevent malicious bots from visiting
- The topic ‘how to add new widget to dynamic sidebar’ is closed to new replies.