Plugin Directory

Changeset 1558498


Ignore:
Timestamp:
12/20/2016 05:35:16 PM (9 years ago)
Author:
Omikant
Message:

add category shortcode attribute

File:
1 edited

Legend:

Unmodified
Added
Removed
  • all-in-one-news-scroll/trunk/allinone-news-scroll.php

    r1396998 r1558498  
    3131    'public'        => true,
    3232    'menu_position' => 5,
    33     'menu_icon'     => 'dashicons-welcome-view-site',
     33    'menu_icon'     => 'dashicons-welcome-view-site',
    3434    'supports'      => array( 'title', 'thumbnail', 'editor' ),
    3535    'has_archive'   => true,
     
    3838}
    3939add_action( 'init', 'wpclcl_news_list' );
     40
     41//hook into the init action and call create_topics_nonhierarchical_taxonomy when it fires
     42
     43add_action( 'init', 'create_news_updates_taxonomy', 0 );
     44
     45function create_news_updates_taxonomy() {
     46
     47// Labels part for the GUI
     48
     49  $labels = array(
     50    'name' => _x( 'Category', 'taxonomy general name' ),
     51    'singular_name' => _x( 'Category', 'taxonomy singular name' ),
     52    'search_items' =>  __( 'Search Category' ),
     53    'popular_items' => __( 'Popular Category' ),
     54    'all_items' => __( 'All Category' ),
     55    'parent_item' => null,
     56    'parent_item_colon' => null,
     57    'edit_item' => __( 'Edit Category' ),
     58    'update_item' => __( 'Update Category' ),
     59    'add_new_item' => __( 'Add New Category' ),
     60    'new_item_name' => __( 'New Category Name' ),
     61    'separate_items_with_commas' => __( 'Separate Category with commas' ),
     62    'add_or_remove_items' => __( 'Add or remove Category' ),
     63    'choose_from_most_used' => __( 'Choose from the most used Category' ),
     64    'menu_name' => __( 'Category' ),
     65  );
     66
     67// Now register the non-hierarchical taxonomy like tag
     68
     69  register_taxonomy('news_category','news_updates',array(
     70    'hierarchical' => true,
     71    'labels' => $labels,
     72    'show_ui' => true,
     73    'show_admin_column' => true,
     74    'update_count_callback' => '_update_post_term_count',
     75    'query_var' => true,
     76    'rewrite' => array( 'slug' => 'categories' ),
     77  ));
     78}
     79
    4080
    4181// create shortcode to list all Testimonials which come in blue
     
    4787        'posts_per_page' => -1,
    4888        'order' => 'ASC',
    49         'orderby' => 'title',
     89        'orderby' => 'rand',
    5090    ) );
    5191    if ( $query->have_posts() ) { ?>
     
    69109    }
    70110}
     111// create shortcode to list all Testimonials which come in blue
     112add_shortcode( 'allinone-news-category', 'wpclcl_news_query_list_category' );
     113function wpclcl_news_query_list_category( $atts ) {
     114    ob_start();
     115   
     116    // define attributes and their defaults
     117    extract( shortcode_atts( array (
     118        'type' => 'news_updates',
     119        'order' => 'date',
     120        'orderby' => 'rand',
     121        'posts' => -1,
     122        'category' => '',
     123    ), $atts ) );
     124   
     125    $query = new WP_Query( array(
     126        'post_type' => 'news_updates',
     127        'posts_per_page' => -1,
     128        'order' => $order,
     129        'orderby' => $orderby,
     130        'news_category' => $category,
     131    ) );
     132    if ( $query->have_posts() ) { ?>
     133        <div class="vticker">
     134            <ul>
     135                <?php while ( $query->have_posts() ) : $query->the_post(); ?>
     136                <li class="item-event"  id="post-<?php the_ID(); ?>">
     137                    <div class="news-event">
     138                        <div class="news_title">
     139                            <h3><?php the_title(); ?></h3>
     140                            <p><?php the_content(); ?></p>
     141                        </div>
     142                    </div>
     143                </li>
     144                <?php endwhile;
     145                wp_reset_postdata(); ?>
     146            </ul>
     147        </div>
     148    <?php $myvariable_news1 = ob_get_clean();
     149    return $myvariable_news1;
     150    }
     151}
    71152
    72153
Note: See TracChangeset for help on using the changeset viewer.