-
-
Save anonymous/e97812f6d5c12d16039d to your computer and use it in GitHub Desktop.
Latest News Widget Setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RewriteEngine On | |
RewriteBase / | |
RewriteRule ^index\.php$ - [L] | |
# uploaded files | |
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L] | |
# add a trailing slash to /wp-admin | |
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] | |
RewriteCond %{REQUEST_FILENAME} -f [OR] | |
RewriteCond %{REQUEST_FILENAME} -d | |
RewriteRule ^ - [L] | |
RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L] | |
RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L] | |
RewriteRule . index.php [L] | |
redirect 301 /admin /wp-admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Latest News | |
Plugin URI: # | |
Description: Adds the Latest News and Widget to display the number of Latest News items | |
Author: # | |
Version: 1.1 | |
Author URI: # | |
*/ | |
class LatestNews extends WP_Widget | |
{ | |
// Constructor // | |
function LatestNews() | |
{ | |
// Widget Settings | |
$widget_ops = array( | |
'classname' => 'latest-news', | |
'description' => 'Displays the number of Latest News items from the Latest News Custom Post' | |
); | |
// Create the widget | |
$this->WP_Widget( 'LatestNews', 'Latest News', $widget_ops ); | |
} | |
function widget( $args, $instance ) | |
{ | |
// outputs the content of the widget | |
global $wpdb; | |
extract( $args ); | |
$title = apply_filters( 'widget_title', empty( $instance[ 'title' ] ) ? __( '' ) : $instance[ 'title' ], $instance, $this->id_base ); | |
$include_date = $instance[ 'includedate' ] ? '1' : '0'; | |
$news_item_title = $instance[ 'newsitemtitle' ] ? '1' : '0'; | |
if ( !$number = absint( $instance[ 'number' ] ) ) { | |
$number = 3; | |
} | |
echo $before_widget; | |
if ( $title ) : ?> | |
<h3 class="latest-news-heading"><?php echo $title; ?></h3> | |
<?php endif; ?> | |
<?php | |
$args = array( | |
'post_type' => 'latest-news', | |
'post_status' => 'publish', | |
'paged' => $paged, | |
'posts_per_page' => $number, | |
'order' => 'DESC', | |
'orderby' => 'date' | |
); | |
$loops = new WP_Query( $args ); | |
if ( $loops->have_posts() ) : ?> | |
<ul id="latest-news"> | |
<?php while ( $loops->have_posts() ) : | |
$loops->the_post(); | |
$news_content = get_the_content(); | |
$news_content = strip_tags( $news_content ); | |
$news_content = ShortenText( $news_content, 80, '…' ); | |
?> | |
<li class="lastest-news-item"> | |
<?php if( $news_item_title ) : ?> | |
<h3 class="latest-news-title"><?php the_title() ?></h3> | |
<?php endif; ?> | |
<?php if ( $include_date ) : ?> | |
<p class="latest-news-date"><span><?php the_time( 'j M Y' ) ?></span></p> | |
<?php endif; ?> | |
<div class="latest-news-content"> | |
<p><?php echo $news_content; ?></p> | |
<p class="read-more"><a href="<?php echo get_permalink(); ?>"title="<?php echo htmlentities( get_the_title() ); ?>">Read more</a></p> | |
</div> | |
</li> | |
<?php endwhile; ?> | |
</ul> | |
<?php if( function_exists( 'wp_paginate' ) ) { | |
wp_paginate(); | |
} ?> | |
<?php endif; ?> | |
<?php | |
wp_reset_postdata(); | |
echo $after_widget; | |
} | |
function update( $new_instance, $old_instance ) | |
{ | |
$instance = $old_instance; | |
$instance[ 'title' ] = strip_tags( $new_instance[ 'title' ] ); | |
$instance[ 'number' ] = absint( $new_instance[ 'number' ] ); | |
$instance[ 'includedate' ] = !empty ( $new_instance[ 'includedate' ] ) ? 1 : 0; | |
$instance[ 'newsitemtitle' ] = !empty ( $new_instance[ 'newsitemtitle' ] ) ? 1 : 0; | |
return $instance; | |
} | |
function form( $instance ) | |
{ | |
$defaults = array( | |
'title' => '', | |
'number' => 3, | |
'includedate' => true, | |
'newsitemtitle' => true | |
); | |
$instance = wp_parse_args( ( array ) $instance, $defaults ); | |
$title = isset( $instance[ 'title' ] ) ? esc_attr( $instance[ 'title' ] ) : ''; | |
$number = isset( $instance[ 'number' ] ) ? absint( $instance[ 'number' ] ) : 3; | |
$include_date = isset( $instance[ 'includedate' ] ) ? ( bool ) $instance[ 'includedate' ] : true; | |
$news_item_title = isset( $instance[ 'newsitemtitle' ] ) ? ( bool ) $instance[ 'newsitemtitle' ] : true; | |
?> | |
<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></p> | |
<p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of news items to show:' ); ?></label> | |
<input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p> | |
<p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id( 'newstitle' ); ?>" name="<?php echo $this->get_field_name( 'newsitemtitle' ); ?>"<?php checked( $news_item_title ); ?> /> | |
<label for="<?php echo $this->get_field_id( 'newsitemtitle' ); ?>"><?php _e( 'Show News Item Title' ); ?></label></p> | |
<p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id( 'includedate' ); ?>" name="<?php echo $this->get_field_name( 'includedate' ); ?>"<?php checked( $include_date ); ?> /> | |
<label for="<?php echo $this->get_field_id( 'includedate' ); ?>"><?php _e( 'Show Date' ); ?></label></p> | |
<?php | |
} | |
} | |
function create_latest_news() | |
{ | |
$labels = array( | |
'name' => _x( 'Latest News', 'post type general name' ), | |
'singular_name' => _x( 'News List', 'post type singular name' ), | |
'add_new' => _x( 'Add New', 'News' ), | |
'add_new_item' => __( 'Add New News' ), | |
'edit_item' => __( 'Edit News' ), | |
'new_item' => __( 'New News' ), | |
'view_item' => __( 'View News' ), | |
'search_items' => __( 'Search News' ), | |
'not_found' => __( 'Nothing found' ), | |
'not_found_in_trash' => __( 'Nothing found in Trash' ) | |
); | |
$args = array( | |
'labels' => $labels, | |
'public' => true, | |
'has_archive' => 'true', // Activate the archive | |
'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes' ), | |
'taxonomies' => array( 'category' ) // this is IMPORTANT | |
); | |
register_post_type( 'latest-news', $args ); | |
} | |
// End class soup_widget | |
add_action( 'init', 'create_latest_news' ); | |
add_action( 'widgets_init', create_function( '', 'return register_widget( "LatestNews" );' ) ); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php get_header(); ?> | |
<div id="sub-page" class="news main-sub-page"> | |
<?php if( have_posts() ) : while( have_posts() ) : ?> | |
<?php the_post(); ?> | |
<h1 class="page-title"><?php the_title(); ?></h1> | |
<?php endwhile; endif; ?> | |
<?php dynamic_sidebar( 'first-widget-area' ); ?> | |
</div> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment