Advertisement
Guest User

Untitled

a guest
Apr 26th, 2020
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. <?php
  2. if ( ! function_exists( 'register_widget_alba_posts' ) ) {
  3. function register_widget_alba_posts() {
  4. register_widget( 'alba_posts' );
  5. }
  6. }
  7. add_action( 'widgets_init', 'register_widget_alba_posts' );
  8. class alba_posts extends WP_Widget {
  9. /* Constructor
  10. ------------------------------------ */
  11. function __construct() {
  12. parent::__construct(
  13. // Base ID of the widget
  14. 'alba_posts',
  15. // Widget name
  16. __('alba | قائمة الاقسام'),
  17. // Widget description
  18. array( 'description' => __( 'عرض الاقسام' ), )
  19. );
  20. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
  21. add_action( 'admin_footer-widgets.php', array( $this, 'print_scripts' ), 9999 );
  22. }
  23. /* Widget
  24. ------------------------------------ */
  25. public function widget($args, $instance) {
  26. extract( $args );
  27. $title = $instance['title'];
  28. $icname = $instance['icname'];
  29. $color = $instance['color'];
  30. $cat_id = $instance['posts_cat_id'];
  31. $image_uri = $instance['image_uri'];
  32. $link_type = $instance['link_type'];
  33. // Get menu
  34. $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
  35. $output = $before_widget."\n";
  36. ob_start();
  37. ?>
  38.  
  39. <?php
  40. $cat = get_category($cat_id);
  41. $url = get_category_link($cat_id);
  42. $name =get_cat_name($cat_id);
  43. ?>
  44. <style>
  45. .cat-<?php echo $this->id;?> .category-title{
  46. border-bottom-color: <?php echo $color ?>;
  47. }
  48. .cat-<?php echo $this->id;?> .category-title:hover,.cat-<?php echo $this->id;?> .boxDiv{
  49. background-color: <?php echo $color ?>;
  50. }
  51. .cat-<?php echo $this->id;?> .category-title .icon,.cat-<?php echo $this->id;?> .category-items li a:hover{
  52. color:<?php echo $color ?>
  53. }
  54. <?php if($image_uri != '' && $icname == ''){ ?>
  55. .cat-<?php echo $this->id;?> .icon {
  56. background-image: url(<?php echo $instance['image_uri'] ?>);
  57. background-position: center center;
  58. background-repeat: no-repeat;
  59. width: 50px;
  60. height: 50px;
  61. background-size: cover;
  62. }
  63. <?php } ?>
  64. </style>
  65. <h2 class="category-title">
  66. <a href="<?php echo esc_url($url); ?>">
  67. <?php if(alba_option( 'cat-hd-type')=='type-3'){echo '<div class="boxDiv">';}?>
  68. <span class="icon <?php if($icname != ''){echo 'defulticon ' .$icname; } ?>"></span>
  69. <?php if(alba_option( 'cat-hd-type')=='type-3'){echo '</div>';}?>
  70. <span class="title"><?php echo esc_html($title); ?></span>
  71.  
  72. </a>
  73. </h2>
  74.  
  75. <ul class="category-items">
  76. <?php
  77. if($instance['link_type'] != 'catlink'){
  78. if($nav_menu){
  79. wp_nav_menu( array( 'container' => false,'items_wrap' => '%3$s', 'menu' => $nav_menu ) );
  80. }
  81. }else{
  82. wp_list_categories('child_of=' . $cat_id . '&hide_empty=0&title_li=&show_count=0');
  83. }
  84. ?>
  85. </ul>
  86. <?php
  87. $output .= ob_get_clean();
  88. $output .= $after_widget."\n";
  89. echo $output;
  90. }
  91. /* Widget update
  92. /* ------------------------------------ */
  93. public function update($new,$old) {
  94. $instance = $old;
  95. $instance['title'] = strip_tags($new['title']);
  96. $instance['icname'] = strip_tags($new['icname']);
  97. $instance['color'] = strip_tags($new['color']);
  98. // Posts
  99. $instance['posts_cat_id'] = strip_tags($new['posts_cat_id']);
  100. $instance['image_uri'] = strip_tags($new['image_uri']);
  101. $instance['nav_menu'] = (int) $new['nav_menu'];
  102. ................................................................
  103. .......................................
  104. .................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement