Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter widget rendering based on $posts and/or $query #80

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion js/zoninator.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ var zoninator = {};
// Add Post to List
var $post = $(returnData.content);
$post.hide()
.appendTo(zoninator.$zonePostsList)
//.appendTo(zoninator.$zonePostsList)
.prependTo(zoninator.$zonePostsList)
.fadeIn()
;

Expand Down
38 changes: 26 additions & 12 deletions widget.zone-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,27 @@ function widget( $args, $instance ) {
return;

$posts = z_get_posts_in_zone( $zone_id );
if ( empty( $posts ) )
if ( empty( $posts ) ) {
return;
}

$query = z_get_zone_query( $zone_id );
?>
<?php echo wp_kses_post( $args['before_widget'] ); ?>

<?php echo wp_kses_post( $args['before_title'] ) . esc_html( $zone->name ) . wp_kses_post( $args['after_title'] ); ?>

<?php if ( ! empty( $zone->description ) && $show_description ) : ?>
<p class="description"><?php echo esc_html( $zone->description ); ?></p>
<?php endif; ?>

<ul>
<?php foreach ( $posts as $post ) : ?>
<li>
<a href="<?php echo esc_url( get_permalink( $post->ID ) ); ?>">
<?php echo esc_html( get_the_title( $post->ID ) ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif;

$html = apply_filters( 'widget_zone_posts_override_html', false, $posts, $query );
if ( false !== $html ) {
echo $html;
} else {
$this->widget_posts( $posts );
}
?>
<?php echo wp_kses_post( $args['after_widget'] ); ?>
<?php
$cache[ $args['widget_id'] ] = ob_get_flush();
Expand All @@ -81,6 +80,21 @@ function widget( $args, $instance ) {
wp_cache_set( 'widget-zone-posts', $cache, 'widget' );
}

// filterable function to render posts in a zone post widget
function widget_posts( $posts ) {
?>
<ul>
<?php foreach ( $posts as $post ) : ?>
<li>
<a href="<?php echo esc_url( get_permalink( $post->ID ) ); ?>">
<?php echo esc_html( get_the_title( $post->ID ) ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php
}

function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$new_instance = wp_parse_args( (array) $new_instance, array( 'zone_id' => 0, 'show_description' => 0 ) );
Expand Down