Advertisement
Guest User

Wordpress widget "marquee currency"

a guest
Sep 10th, 2017
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.01 KB | None | 0 0
  1. Скопируйте код, представленный ниже, в файл functions.php,
  2. который вы сможете найти в папке с вашей действующей темой,
  3. либо через редактор админ панели WORDPRESS
  4.  
  5. <?php
  6.  
  7.  
  8. class marqueeCurrency extends WP_Widget {
  9.  
  10.    function __construct() {
  11.      parent::__construct('marqueeСurrency','Курс криптовалют', array('description' => 'Отображает актуальные курсы криптовалют бегущей строкой'));
  12.    }
  13.    
  14.    function widget( $args, $instance ){
  15.      
  16.     $currencies = file_get_contents('https://api.coinmarketcap.com/v1/ticker/?convert=RUB&limit='.$instance['currenciesLimit']);
  17.     $currencies = json_decode($currencies,true);
  18.    
  19.     ?>
  20.      <marquee scrollamount="3" behavior="scroll" loop="infinite" direction="left">
  21.     <?
  22.     foreach ($currencies as $key => $currency) {
  23.     ?>
  24.      <span><strong><? echo $currency['name'].' ('.$currency['symbol'].')'; ?></strong> : <? echo number_format($currency['price_rub'], 2, '.', ' ').' руб.';?> &nbsp;&nbsp;</span>
  25.     <?
  26.     }
  27.     ?>
  28.      </marquee>
  29.     <?
  30.    }
  31.    
  32.    function update( $new_instance, $old_instance ) {
  33.     $instance = $old_instance;
  34.  
  35.     $instance['currenciesLimit'] = strip_tags( $new_instance['currenciesLimit'] );
  36.    
  37.     return $instance;
  38.    }
  39.    
  40.    function form( $instance ) {
  41.     $defaults = array (
  42.      'currenciesLimit' => 10
  43.     );
  44.     $instance = wp_parse_args((array)$instance, $defaults);
  45.     ?>
  46.      <p>
  47.       <label for="<?php echo $this->get_field_id( 'currenciesLimit' ); ?>"> Выводить <input id="<?php echo $this->get_field_id( 'currenciesLimit' ); ?>" name="<?php echo $this->get_field_name( 'currenciesLimit' ); ?>" value="<?php echo $instance['currenciesLimit']; ?>" style="width:50px;" type="number"/> популярных криптовалют</label>
  48.      </p>
  49.     <?
  50.   }
  51.  
  52. }
  53.  
  54. register_widget('marqueeCurrency');
  55.  
  56.  
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement