Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Anoop Ranawat

    (@anoopranawat)

    Hello,

    Sorry for late reply

    Plz deactivate the SP news plugin

    and just paste this code in to your Function.php file

    // Function for News section starts 
    
    function cadila_setup_post_types() {
    
    	$news_labels =  apply_filters( 'cadila_news_labels', array(
    		'name'                => 'News',
    		'singular_name'       => 'News',
    		'add_new'             => __('Add New', 'cadila_news'),
    		'add_new_item'        => __('Add New News', 'cadila_news'),
    		'edit_item'           => __('Edit News', 'cadila_news'),
    		'new_item'            => __('New News', 'cadila_news'),
    		'all_items'           => __('All News', 'cadila_news'),
    		'view_item'           => __('View News', 'cadila_news'),
    		'search_items'        => __('Search News', 'cadila_news'),
    		'not_found'           => __('No News found', 'cadila_news'),
    		'not_found_in_trash'  => __('No News found in Trash', 'cadila_news'),
    		'parent_item_colon'   => '',
    		'menu_name'           => __('News', 'cadila_news'),
    		'exclude_from_search' => true
    	) );
    
    	$news_args = array(
    		'labels' 			=> $news_labels,
    		'public' 			=> true,
    		'publicly_queryable'=> true,
    		'show_ui' 			=> true,
    		'show_in_menu' 		=> true,
    		'query_var' 		=> true,
    		'capability_type' 	=> 'post',
    		'has_archive' 		=> true,
    		'hierarchical' 		=> false,
    		'supports' => array('title','editor','thumbnail','excerpt'),
    		'taxonomies' => array('category', 'post_tag')
    	);
    	register_post_type( 'cadila_news', apply_filters( 'cadila_setup_post_types_args', $news_args ) );
    
    }
    
    add_action('init', 'cadila_setup_post_types');
    /*
     * Add [cadila_news limit="-1"] shortcode
     *
     */
    function cadila_news_shortcode( $atts, $content = null ) {
    
    	extract(shortcode_atts(array(
    		"limit" => ''
    	), $atts));
    
    	// Define limit
    	if( $limit ) {
    		$posts_per_page = $limit;
    	} else {
    		$posts_per_page = '-1';
    	}
    
    	ob_start();
    
    	// Create the Query
    	$post_type 		= 'cadila_news';
    	$orderby 		= 'post_date';
    	$order 			= 'DESC';
    
    	$query = new WP_Query( array (
    								'post_type'      => $post_type,
    								'posts_per_page' => $posts_per_page,
    								'orderby'        => $orderby,
    								'order'          => $order,
    								'no_found_rows'  => 1
    								)
    						);
    
    	//Get post type count
    	$post_count = $query->post_count;
    	$i = 1;
    
    	// Displays Custom post info
    	if( $post_count > 0) :
    
    		// Loop
    		while ($query->have_posts()) : $query->the_post();
    		?>
    		<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>									
    
    					<?php if( is_single() ): ?>
    						<h5 class="entry-title post-title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h5>
    					<?php else: ?>
    						<h5 class="entry-title post-title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h5>
    					<?php endif; ?>
    					<div class="entry-meta post-info">
                <span class="date published time" title="<?php the_time('c') ?>"><?php the_time('F j, Y') ?></span>
              </div> <!-- .entry-meata .post-info -->
    					<?php if( has_post_thumbnail() ) : ?>
    							<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    								<?php the_post_thumbnail(); ?>
    							</a>
    						<?php endif; ?>
    					<div class="post-entry">
    						<?php echo get_excerpt(300); ?>
    					</div>		
    
    				</div>
    				<?php
    		endwhile;
    
    	endif;
    
    	// Reset query to prevent conflicts
    	wp_reset_query();
    
    	?>
    
    	<?php
    
    	return ob_get_clean();
    
    }
    
    add_shortcode("cadila_news", "cadila_news_shortcode");
    
    /* home page latestnews
     * Add [cadila_news_home limit="-1"] shortcode
     *
     */
    function cadila_news_home_shortcode( $atts, $content = null ) {
    
    	extract(shortcode_atts(array(
    		"limit" => ''
    	), $atts));
    
    	// Define limit
    	if( $limit ) {
    		$posts_per_page = $limit;
    	} else {
    		$posts_per_page = '-1';
    	}
    
    	ob_start();
    
    	// Create the Query
    	$post_type 		= 'cadila_news';
    	$orderby 		= 'post_date';
    	$order 			= 'DESC';
    
    	$query = new WP_Query( array (
    								'post_type'      => $post_type,
    								'posts_per_page' => $posts_per_page,
    								'orderby'        => $orderby,
    								'order'          => $order,
    								'showposts'	     => 1,
    								'no_found_rows'  => 1
    								)
    						);
    
    	//Get post type count
    	$post_count = $query->post_count;
    	$i = 1;
    
    	// Displays Custom post info
    	if( $post_count > 0) :
    
    		// Loop
    		while ($query->have_posts()) : $query->the_post();
    		?>
    		<div class="homepagenews" >									
    
    					<div class="post-entry">
    						<?php echo get_excerpt(80); ?>
    					</div>		
    
    				</div>
    				<?php
    		endwhile;
    
    	endif;
    
    	// Reset query to prevent conflicts
    	wp_reset_query();
    
    	?>
    
    	<?php
    
    	return ob_get_clean();
    
    }
    
    add_shortcode("cadila_news_home", "cadila_news_home_shortcode");
    
    //News sidebar
    class Cadila_News_Widget extends WP_Widget {
    
        function Cadila_News_Widget() {
    
            $widget_ops = array('classname' => 'Cadila_News_Widget', 'description' => __('Displayed Letest News Items from the News  in a sidebar', 'cadila_news') );
            $control_ops = array( 'width' => 350, 'height' => 450, 'id_base' => 'cadila_news_widget' );
            $this->WP_Widget( 'cadila_news_widget', __('Letest News Widget', 'cadila_news'), $widget_ops, $control_ops );
        }
    
        function form($instance) {
            $instance = wp_parse_args((array) $instance, array( 'title' => '' ));
            $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
            $num_items = isset($instance['num_items']) ? absint($instance['num_items']) : 5;
        ?>
          <p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
          <p><label for="<?php echo $this->get_field_id('num_items'); ?>">Number of Items: <input class="widefat" id="<?php echo $this->get_field_id('num_items'); ?>" name="<?php echo $this->get_field_name('num_items'); ?>" type="text" value="<?php echo attribute_escape($num_items); ?>" /></label></p>
        <?php
        }
    
        function update($new_instance, $old_instance) {
            $instance = $old_instance;
            $instance['title'] = $new_instance['title'];
            $instance['num_items'] = $new_instance['num_items'];
            return $instance;
        }
        function widget($news_args, $instance) {
            extract($news_args, EXTR_SKIP);
    
            $current_post_name = get_query_var('name');
    
            $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
            $num_items = empty($instance['num_items']) ? '5' : apply_filters('widget_title', $instance['num_items']);
    
            $postcount = 0;
    
            echo $before_widget;
    
    ?>
    			<div class="widget-title">
                <h3 ><?php echo $title ?></h3>
    			</div>
                <!--visual-columns-->
                <div class="recent-news-items">
                    <ul>
                <?php // setup the query
                $news_args = array( 'suppress_filters' => true,
                               'posts_per_page' => $num_items,
                               'post_type' => 'cadila_news',
                               'order' => 'DESC'
                             );
    
                $cust_loop = new WP_Query($news_args);
                if ($cust_loop->have_posts()) : while ($cust_loop->have_posts()) : $cust_loop->the_post(); $postcount++;
                        ?>
                        <li>
    					<?php echo get_excerpt(130); ?>	
    
                        </li>
                <?php endwhile;
                endif;
                 wp_reset_query(); ?>
    
                    </ul>
                </div>
    <?php
            echo $after_widget;
        }
    }
    
    /* Register the widget */
    function cadila_news_widget_load_widgets() {
        register_widget( 'Cadila_News_Widget' );
    }
    
    /* Load the widget */
    add_action( 'widgets_init', 'cadila_news_widget_load_widgets' );
    
    ?>
    Plugin Author Anoop Ranawat

    (@anoopranawat)

    Plz use this shortcode

    [cadila_news_home limit="-1"]

    As i am using this code in my project so i am using “cadila” prifix.

    Please use this code as it is..You will gat a news tab in admin left side
    and put short code into NEWS Page.

    SP-News plugin does not use shortcode…this plugin just fatch all the POST_TYPE news from database when you add a news link in the address bar

    Thread Starter dixit

    (@riddhi123)

    Thx for nice reply. i put this code.got Fatal error: Call to undefined function get_excerpt()

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘All news’ is closed to new replies.