Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ( ! function_exists( 'register_widget_alba_posts' ) ) {
- function register_widget_alba_posts() {
- register_widget( 'alba_posts' );
- }
- }
- add_action( 'widgets_init', 'register_widget_alba_posts' );
- class alba_posts extends WP_Widget {
- /* Constructor
- ------------------------------------ */
- function __construct() {
- parent::__construct(
- // Base ID of the widget
- 'alba_posts',
- // Widget name
- __('alba | قائمة الاقسام'),
- // Widget description
- array( 'description' => __( 'عرض الاقسام' ), )
- );
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
- add_action( 'admin_footer-widgets.php', array( $this, 'print_scripts' ), 9999 );
- }
- /* Widget
- ------------------------------------ */
- public function widget($args, $instance) {
- extract( $args );
- $title = $instance['title'];
- $icname = $instance['icname'];
- $color = $instance['color'];
- $cat_id = $instance['posts_cat_id'];
- $image_uri = $instance['image_uri'];
- $link_type = $instance['link_type'];
- // Get menu
- $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
- $output = $before_widget."\n";
- ob_start();
- ?>
- <?php
- $cat = get_category($cat_id);
- $url = get_category_link($cat_id);
- $name =get_cat_name($cat_id);
- ?>
- <style>
- .cat-<?php echo $this->id;?> .category-title{
- border-bottom-color: <?php echo $color ?>;
- }
- .cat-<?php echo $this->id;?> .category-title:hover,.cat-<?php echo $this->id;?> .boxDiv{
- background-color: <?php echo $color ?>;
- }
- .cat-<?php echo $this->id;?> .category-title .icon,.cat-<?php echo $this->id;?> .category-items li a:hover{
- color:<?php echo $color ?>
- }
- <?php if($image_uri != '' && $icname == ''){ ?>
- .cat-<?php echo $this->id;?> .icon {
- background-image: url(<?php echo $instance['image_uri'] ?>);
- background-position: center center;
- background-repeat: no-repeat;
- width: 50px;
- height: 50px;
- background-size: cover;
- }
- <?php } ?>
- </style>
- <h2 class="category-title">
- <a href="<?php echo esc_url($url); ?>">
- <?php if(alba_option( 'cat-hd-type')=='type-3'){echo '<div class="boxDiv">';}?>
- <span class="icon <?php if($icname != ''){echo 'defulticon ' .$icname; } ?>"></span>
- <?php if(alba_option( 'cat-hd-type')=='type-3'){echo '</div>';}?>
- <span class="title"><?php echo esc_html($title); ?></span>
- </a>
- </h2>
- <ul class="category-items">
- <?php
- if($instance['link_type'] != 'catlink'){
- if($nav_menu){
- wp_nav_menu( array( 'container' => false,'items_wrap' => '%3$s', 'menu' => $nav_menu ) );
- }
- }else{
- wp_list_categories('child_of=' . $cat_id . '&hide_empty=0&title_li=&show_count=0');
- }
- ?>
- </ul>
- <?php
- $output .= ob_get_clean();
- $output .= $after_widget."\n";
- echo $output;
- }
- /* Widget update
- /* ------------------------------------ */
- public function update($new,$old) {
- $instance = $old;
- $instance['title'] = strip_tags($new['title']);
- $instance['icname'] = strip_tags($new['icname']);
- $instance['color'] = strip_tags($new['color']);
- // Posts
- $instance['posts_cat_id'] = strip_tags($new['posts_cat_id']);
- $instance['image_uri'] = strip_tags($new['image_uri']);
- $instance['nav_menu'] = (int) $new['nav_menu'];
- ................................................................
- .......................................
- .................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement