{php}

// 获取所有分类

$allCategories = $zbp->GetCategoryList();


{/php}

{foreach $allCategories as $cate}

  <!-- 获取分类下的文章 -->

        {php}

        $articles = $zbp->GetPostList('*', array(array('=', 'log_CateID', $cate->ID)), array('log_PostTime' => 'DESC'), 5, null);

        {/php}

{/foreach}


//输出图片

{foreach $article.AllImages as $k=>$v}

<img class="article-image" src="{$v}" alt="">

{break}

{/foreach}


{* 提取文章中的视频 *}

                                {php}

                                function extractVideos($content) {

                                    $videos = array();

                                    

                                    // 匹配iframe视频(如YouTube、优酷等)

                                    preg_match_all('/<iframe[^>]*src=["\']([^"\']*)["\'][^>]*>/i', $content, $iframe_matches);

                                    foreach($iframe_matches[1] as $url) {

                                        $videos[] = $url;

                                    }

                                    

                                    // 匹配video标签

                                    preg_match_all('/<video[^>]*src=["\']([^"\']*)["\'][^>]*>/i', $content, $video_matches);

                                    foreach($video_matches[1] as $url) {

                                        $videos[] = $url;

                                    }

                                    

                                    // 匹配source标签(在video标签内部)

                                    preg_match_all('/<source[^>]*src=["\']([^"\']*)["\'][^>]*>/i', $content, $source_matches);

                                    foreach($source_matches[1] as $url) {

                                        $videos[] = $url;

                                    }

                                    

                                    return $videos;

                                }


                                $article_videos = extractVideos($article->Content);

                                {/php}


                                {* 显示提取的视频 *}

                                {if count($article_videos) > 0}

                                <div class="article-videos">

                                    <h3>文章中的视频:</h3>

                                    {foreach $article_videos as $video_url}

                                    <div class="video-item">

                                        {if (strpos($video_url, 'youtube') !== false || strpos($video_url, 'youtu.be') !== false)}

                                            <iframe width="560" height="315" src="{$video_url}" frameborder="0" allowfullscreen></iframe>

                                        {elseif strpos($video_url, 'vimeo') !== false}

                                            <iframe src="{$video_url}" width="640" height="360" frameborder="0" allowfullscreen></iframe>

                                        {else}

                                            <video width="560" height="315" controls>

                                                <source src="{$video_url}" type="video/mp4">

                                                您的浏览器不支持视频标签。

                                            </video>

                                        {/if}

                                    </div>

                                    {/foreach}

                                </div>

                                {/if}