NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

widget.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. class P2P_Widget extends scbWidget {
  3. protected $defaults = array(
  4. 'ctype' => false,
  5. 'listing' => 'connected',
  6. 'title' => ''
  7. );
  8. static function init( $class = '', $file = false, $base = 'p2p' ) {
  9. if ( empty( $class ) )
  10. $class = __CLASS__;
  11. parent::init( $class, $file, $base );
  12. }
  13. function __construct() {
  14. parent::__construct( 'p2p', __( 'Posts 2 Posts', P2P_TEXTDOMAIN ), array(
  15. 'description' => __( 'A list of posts connected to the current post', P2P_TEXTDOMAIN )
  16. ) );
  17. }
  18. function form( $instance ) {
  19. if ( empty( $instance ) )
  20. $instance = $this->defaults;
  21. $ctypes = array();
  22. foreach ( P2P_Connection_Type_Factory::get_all_instances() as $p2p_type => $ctype ) {
  23. $ctypes[ $p2p_type ] = $ctype->get_desc();
  24. }
  25. echo html( 'p', $this->input( array(
  26. 'type' => 'text',
  27. 'name' => 'title',
  28. 'desc' => __( 'Title:', P2P_TEXTDOMAIN )
  29. ), $instance ) );
  30. echo html( 'p', $this->input( array(
  31. 'type' => 'select',
  32. 'name' => 'ctype',
  33. 'values' => $ctypes,
  34. 'desc' => __( 'Connection type:', P2P_TEXTDOMAIN ),
  35. 'extra' => "style='width: 100%'"
  36. ), $instance ) );
  37. echo html( 'p',
  38. __( 'Connection listing:', P2P_TEXTDOMAIN ),
  39. '<br>',
  40. $this->input( array(
  41. 'type' => 'radio',
  42. 'name' => 'listing',
  43. 'values' => array(
  44. 'connected' => __( 'connected', P2P_TEXTDOMAIN ),
  45. 'related' => __( 'related', P2P_TEXTDOMAIN )
  46. ),
  47. ), $instance )
  48. );
  49. }
  50. function widget( $args, $instance ) {
  51. $instance = array_merge( $this->defaults, $instance );
  52. $output = P2P_List_Renderer::query_and_render( array(
  53. 'ctype' => $instance['ctype'],
  54. 'method' => ( 'related' == $instance['listing'] ? 'get_related' : 'get_connected' ),
  55. 'item' => get_queried_object(),
  56. 'mode' => 'ul',
  57. 'context' => 'widget'
  58. ) );
  59. if ( !$output )
  60. return;
  61. $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
  62. echo $args['before_widget'];
  63. if ( ! empty( $title ) )
  64. echo $args['before_title'] . $title . $args['after_title'];
  65. echo $output;
  66. echo $args['after_widget'];
  67. }
  68. }