Untitled

mail@pastecode.io avatar
unknown
php
3 years ago
2.5 kB
2
Indexable
Never
<?php
// Creating the widget
class cw_widget extends WP_Widget
{
    function __construct()
    {
        parent::__construct(
        // Base ID of your widget
            'cw_widget',
        // Widget name will appear in UI
            __('Oferta - lista', 'cw_widget_domain'),
        // Widget description
            array(
            'description' => __('Oferta z kategoriami zabiegów',
                                     'cw_widget_domain')
        ));
    }
    // Creating widget front-end
    // This is where the action happens
	
    public function widget($args, $instance)
    {
        $title = apply_filters('widget_title', $instance['title']);
        // before and after widget arguments are defined by themes
        echo $args['before_widget'];
		echo '<div class="widget-oferta">';
        if (!empty($title))
            echo $args['before_title'] . $title . $args['after_title'];
		$categories =  get_categories();
echo '<ul>';
foreach  ($categories as $category) {
  echo '<a href="' . get_category_link( $category->term_id ) . '"><li>' .  $category->name . '</li></a>';
}
echo '<a href="/kosmetyka-upiekszajaca/"><li>Kosmetyka upiekszająca</li></a>';	
echo '<a href="/pielegnacja-dloni-i-stop/"><li>Pielęgnacja dłoni i stóp</li></a>';	
echo '</ul>';
echo '</div>';
        // This is where you run the code and display the output
        echo '</div>';
		echo '</div>';
    }
    // Widget Backend
    public function form($instance)
    {
        if (isset($instance['title'])) {
            $title = $instance['title'];
        } else {
            $title = __('New title', 'cw_widget_domain');
        }
      // Widget admin form
?>
<label for="<?php
        echo $this->get_field_id('title');
?>"><?php
        _e('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 esc_attr($title);
?>" />
<?php
    }
    // Updating widget replacing old instances with new
    public function update($new_instance, $old_instance)
{
        $instance          = array();
        $instance['title'] = (!empty($new_instance['title'])) 
                              ? strip_tags($new_instance['title']) : '';
        return $instance;
    }
} // Class cw_widget ends here
// Register and load the widget
function cw_load_widget()
{
     register_widget('cw_widget');
}
add_action('widgets_init', 'cw_load_widget');