PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/fruitful/inc/widgets.php

https://gitlab.com/sihabudinahmad/asppi
PHP | 133 lines | 90 code | 17 blank | 26 comment | 10 complexity | cb58f35169e4c2fa905b49f1a06cd64f MD5 | raw file
  1. <?php
  2. /**
  3. * Makes a custom Widget for displaying Aside, Link, Status, and Quote Posts available
  4. *
  5. * @package WordPress
  6. * @subpackage Fruitful
  7. * @since Fruitful
  8. */
  9. class Fruitful_Widget_News_Archive extends WP_Widget {
  10. /**
  11. * Constructor
  12. *
  13. * @return void
  14. **/
  15. public function __construct() {
  16. $theme_name = wp_get_theme();
  17. $widget_name = $theme_name.' '.__( 'News Archive', 'fruitful' );
  18. parent::__construct( 'widget_news_archive', $widget_name, array(
  19. 'classname' => 'widget_news_archive',
  20. 'description' => __( 'Use this widget to list your Link posts.', 'fruitful' ),
  21. ) );
  22. }
  23. /**
  24. * Outputs the HTML for this widget.
  25. *
  26. * @param array An array of standard parameters for widgets in this theme
  27. * @param array An array of settings for this widget instance
  28. * @return void Echoes it's output
  29. **/
  30. public function widget( $args, $instance ) {
  31. $id_item = 0;
  32. if (!isset( $args['widget_id'] ) )
  33. $args['widget_id'] = null;
  34. if (isset( $cache[$args['widget_id']] ) ) {
  35. echo $cache[$args['widget_id']];
  36. return;
  37. }
  38. $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'News-Archive', 'fruitful' ) : $instance['title'], $instance, $this->id_base);
  39. $number = empty( $instance['number'] ) ? 10 : absint( $instance['number'] );
  40. $custom_content = empty ($instance['textarea_newsarchiv']) ? null : stripslashes($instance['textarea_newsarchiv']);
  41. $r = new WP_Query(
  42. apply_filters( 'widget_posts_args',
  43. array( 'posts_per_page' => -1,
  44. 'no_found_rows' => true,
  45. 'post_status' => 'publish',
  46. 'ignore_sticky_posts' => true
  47. )
  48. )
  49. );
  50. if ($r->have_posts()) :
  51. ?>
  52. <?php echo $args['before_widget']; ?>
  53. <?php if ( $title ) echo $args['before_title'] . $title . $args['after_title']; ?>
  54. <div class="news_archive_wrapper">
  55. <?php if ( $custom_content != '') { ?>
  56. <div class="news_archive_message"><p><?php echo $custom_content; ?></p></div>
  57. <?php } ?>
  58. <ul class="news_archiv_list">
  59. <?php while ($r->have_posts()) : $r->the_post(); ?>
  60. <li id="arch_item_<?php echo $id_item; ?>" class="news_archiv_item">
  61. <a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php echo esc_attr( get_the_date( 'd.m.Y' ) ); ?></br><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a>
  62. </li>
  63. <?php endwhile; ?>
  64. </ul>
  65. </div>
  66. <?php echo $args['after_widget']; ?>
  67. <?php
  68. wp_enqueue_script('wdgt_news_arch', get_template_directory_uri() . '/inc/js/jxBox/jquery.bxSlider.js', array( 'jquery' ), '20120206', false );
  69. wp_enqueue_style( 'wdgt_news_style', get_template_directory_uri() . '/inc/js/jxBox/bx.css');
  70. ?>
  71. <script type="text/javascript">
  72. jQuery(document).ready(function($) {
  73. $('#<?php echo $args['widget_id']; ?> .news_archiv_list').bxSlider({
  74. mode: 'vertical',
  75. displaySlideQty: <?php echo $instance['number']; ?>,
  76. moveSlideQty: 1,
  77. hideControlOnEnd: true,
  78. adaptiveHeightSpeed:true
  79. });
  80. });
  81. </script>
  82. <?php
  83. wp_reset_postdata();
  84. endif;
  85. }
  86. /**
  87. * Deals with the settings when they are saved by the admin. Here is
  88. * where any validation should be dealt with.
  89. **/
  90. function update( $new_instance, $old_instance ) {
  91. $instance = $old_instance;
  92. $instance['title'] = strip_tags( $new_instance['title'] );
  93. $instance['number'] = (int) $new_instance['number'];
  94. $instance['textarea_newsarchiv'] = stripslashes($new_instance['textarea_newsarchiv']);
  95. $alloptions = wp_cache_get( 'alloptions', 'options' );
  96. if ( isset( $alloptions['widget_news_archive'] ) )
  97. delete_option( 'widget_news_archive' );
  98. return $instance;
  99. }
  100. /**
  101. * Displays the form for this widget on the Widgets page of the WP Admin area.
  102. **/
  103. function form( $instance ) {
  104. $title = isset( $instance['title']) ? esc_attr( $instance['title'] ) : '';
  105. $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 10;
  106. $textarea_newsarchive = isset( $instance['textarea_newsarchiv'] ) ? stripslashes( $instance['textarea_newsarchiv'] ) : '';
  107. ?>
  108. <p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:', 'fruitful' ); ?></label>
  109. <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /></p>
  110. <p><label for="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>"><?php _e( 'Number of posts to show:', 'fruitful' ); ?></label>
  111. <input id="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'number' ) ); ?>" type="text" value="<?php echo esc_attr( $number ); ?>" size="3" /></p>
  112. <p><label for="<?php echo esc_attr( $this->get_field_id( 'textarea_newsarchiv' ) ); ?>"><?php _e( 'Text Message:', 'fruitful' ); ?></label>
  113. <textarea id="<?php echo esc_attr( $this->get_field_id( 'textarea_newsarchiv' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'textarea_newsarchiv' ) ); ?>" class="widefat" cols="16" rows="5"><?php echo stripslashes( $textarea_newsarchive ); ?></textarea></p>
  114. <?php
  115. }
  116. }