function bb_pro_display_stories_fb_style() { if (!is_user_logged_in()) return 'You must be logged in to view stories.'; $current_user_id = get_current_user_id(); // Query stories not expired $args = array( 'post_type' => 'bb_story', 'post_status' => 'publish', 'meta_query' => array( array( 'key' => '_bb_story_expiration', 'value' => time(), 'compare' => '>', 'type' => 'NUMERIC', ), ), 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => 20, ); $stories = new WP_Query($args); if (!$stories->have_posts()) return 'No stories available.'; // Get viewed stories from user meta for read/unread ring $viewed_stories = get_user_meta($current_user_id, 'bb_viewed_stories', true); if (!is_array($viewed_stories)) $viewed_stories = []; $html = '
'; $html .= '
'; // 1. Create Story Button $html .= '
'; $html .= '
+
'; $html .= ''; $html .= '
'; // 2. Loop through stories while ($stories->have_posts()) { $stories->the_post(); $story_id = get_the_ID(); $author_id = get_post_field('post_author', $story_id); $author_name = get_the_author_meta('display_name', $author_id); $author_avatar = get_avatar_url($author_id, ['size' => 48]); $story_thumb = get_the_post_thumbnail_url($story_id, 'medium'); $story_title = get_the_title($story_id); if (empty($story_title)) $story_title = $author_name; // Check if viewed $is_viewed = in_array($story_id, $viewed_stories); $ring_class = $is_viewed ? 'viewed' : 'unread'; $html .= '
'; $html .= '
'; $html .= 'Story cover'; $html .= ''.$author_name.' avatar'; $html .= '
'; $html .= ''; $html .= '
'; } $html .= '
'; // close bb-story-bar // 3. Add Right Scroll Arrow Button $html .= ''; $html .= '
'; // close wrapper wp_reset_postdata(); // Modal HTML for full screen story viewer $html .= ''; // Enqueue CSS + JS needed for this style and behavior bb_pro_enqueue_fb_style_assets(); // Prepare stories JSON for JS $story_data = []; foreach ($stories->posts as $post) { $id = $post->ID; $thumb_id = get_post_thumbnail_id($id); $mime = get_post_mime_type($thumb_id); $src = wp_get_attachment_url($thumb_id); $story_data[] = ['id'=>$id, 'src'=>$src, 'mime'=>$mime]; } $story_json = json_encode($story_data, JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP); // JS for scroll button and basic modal functionality $html .= ""; return $html; } add_shortcode('bb_stories', 'bb_pro_display_stories_fb_style'); Members - Abibitumi.com
by