Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // initialise widget
- function sjc_silo_widget_init() {
- if ( function_exists( 'wp_register_sidebar_widget' ) && function_exists( 'wp_register_widget_control' ) ) {
- wp_register_sidebar_widget( 'sjc_silo_latest_widget2', 'Latest Silo Posts', 'sjc_silo_latest_widget' );
- }
- }
- add_action( 'plugins_loaded', 'sjc_silo_widget_init' );
- // create widget
- function sjc_silo_latest_widget( $args ) {
- $sidebar_category = get_the_category();
- // if we have a category and we're on a normal post / page / cpt page call the function
- if ( $sidebar_category[0] && ! is_front_page() && is_single() ) {
- extract( $args );
- sjc_silo_latest_content( $sidebar_category[0], $before_widget, $after_widget );
- }
- }
- // echo the sidebar - called by widget, can also be called directly
- function sjc_silo_latest_content( $this_sidebar_category = null, $before_widget = null, $after_widget = null ) {
- global $post;
- if ( ! empty( $this_sidebar_category ) ) :
- $posts_in_this_category = get_posts( 'category__in=' . $this_sidebar_category->cat_ID . '&exclude=' . $post->ID );
- if ( count( $posts_in_this_category ) > 0 ) { ?>
- <?php echo $before_widget; ?>
- <h2 class="widget-title">Latest from <?php echo $this_sidebar_category->cat_name; ?></h2>
- <ul style="margin-bottom:10px;">
- <?php foreach ( $posts_in_this_category as $sidebar_value ) : ?>
- <li><a href="<?php echo get_permalink( $sidebar_value->ID ); ?>" title="<?php echo $sidebar_value->post_title; ?>"><?php echo $sidebar_value->post_title; ?></a></li>
- <?php endforeach; ?>
- </ul>
- <a href="<?php echo get_category_link($this_sidebar_category->term_id ); ?>">More from <?php echo $this_sidebar_category->cat_name; ?></a>
- <?php echo $after_widget; ?>
- <?php
- }
- endif;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement