Skip to content

Instantly share code, notes, and snippets.

@JoseMiralles
Created July 11, 2019 13:53
Show Gist options
  • Save JoseMiralles/fe382ef3714cf5550c97cbd1ec4f0cd9 to your computer and use it in GitHub Desktop.
Save JoseMiralles/fe382ef3714cf5550c97cbd1ec4f0cd9 to your computer and use it in GitHub Desktop.
Widget function that loads multiple items dynamically.
public function widget( $args, $instance ) {
//Load all items.
$items = array();
$identifier = 0;
while(isset ($instance["title".$identifier]) ){
array_push($items,
new accordion_item(
$instance["title".$identifier],
$instance['text'.$identifier]
)
);
$identifier++;
}
echo $args['before_widget'];
echo "<div id='accordionWidget'>";
foreach ($items as $item){
?>
<h3><?php echo $item->title; ?></h3>
<div><?php echo $item->text; ?></div>
<?php
}
echo "</div>";
?>
<script>
jQuery(function(){
jQuery("#accordionWidget").accordion();
});
</script>
<?php
echo $args['after_widget'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment