php历史上的今天效果

Posted 代码当酒喝

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php历史上的今天效果相关的知识,希望对你有一定的参考价值。

效果图

在这里插入图片描述

         申明一个请求类,并指定请求的过期时间
        //$client = new Client(['timeout' => 5,'verify' => false]);
        获取当前月份
        //$month = date('m', time());
        获取当然日期
        //$day = date('d', time());
        //
        日期
        //$url = "http://baike.baidu.com/cms/home/eventsOnHistory/{$month}.json";
        //
         发起请求
        //$response = $client->get($url);
        //
        //$body = (string)$response->getBody();
        //
        //$todays = json_decode($body, true)[$month][$month .$day];
        //
        //$todays = array_reverse($todays);
        //这里需要预加载
        $todays = [];
        $articles = Article::with('articleExt,user,user.profile')->order('create_time','desc')->paginate(config('my.pagesize'));

        return view('index/index',compact('articles','todays'));
{extend name="common/layout/base" /}

{block name="style"}
<link href="/static/lib/swiper/swiper-bundle.min.css" rel="stylesheet"/>
{/block}

{block name="cnt"}
<div class="min-vh-100 d-flex flex-column">
    <div class="flex-grow-1">
        {include file="index@common/layout/header" /}
        <div class="container">

            {include file="index@common/msg" /}
            <div class="card  my-3 border-0 shadow-sm rounded-0">
                <div class="card-header bg-white">
                        <i class="iconfont iconrili"></i>历史上的今天-{:date('n月j日',time())}
                </div>
                <div class="card-body">
                    <div class="swiper-container  swiper-container-initialized swiper-container-horizontal swiper-container-pointer-events">
                        <div class="swiper-wrapper">
                            {foreach $todays as $today }
                            <div class="swiper-slide">

                                <div class="text-center">
                                    <div>
                                        <span class="badge rounded-pill bg-secondary mb-2">{$today.year}</span>
                                    </div>
                                    <h5 class="card-title">
                                        {$today.title| raw}
                                    </h5>
                                    <h6 class="card-subtitle mb-2 text-muted">{$today.desc| raw}</h6>
                                    <div class="mb-3">

                                        {if ( $today.type == 'birth')}
                                        <span class="badge rounded-pill bg-success">出生</span>
                                        {elseif ( $today.type == 'event') /}
                                        <span class="badge rounded-pill bg-warning">事件</span>
                                        {elseif ( $today.type == 'death') /}
                                        <span class="badge rounded-pill bg-danger">离世</span>
                                        {/if}


                                        {if !empty($today.festival) }
                                        <span class="badge rounded-pill bg-info">{$today.festival}</span>
                                        {/if}
                                    </div>

                                    <div class="mb-5">
                                        <a class="btn btn-outline-secondary btn-sm" target="_blank" href="{$today.link}" role="button">
                                            <i class="iconfont iconchakan">详情</i>
                                        </a>
                                    </div>

                                </div>

                            </div>
                            {/foreach}
                        </div>
                        <!-- Add Pagination -->
                        <div class="swiper-pagination swiper-pagination-bullets swiper-pagination-bullets-dynamic"></div>

                    </div>
                </div>
            </div>



            {foreach $articles as $article }

            <div class="card  my-3  shadow-sm border-0 bg-white">
                <div class="card-body">
                    <div class="mb-2 pt-3">
                        {$article.type|raw}
                        <a href="/article/{$article->id}"
                           target="_blank"
                           class="card-title text-decoration-none link-secondary">
                            {$article.title}
                        </a>
                    </div>
                    <div class="mb-2">
                        <a class="text-decoration-none link-secondary"
                           href="#">
                            <img class="rounded-circle wh-3rem"
                                 src="{$article->user->profile->avatar}">
                            {$article->user->profile->nickname}
                        </a>
                    </div>
                    <div class="text-muted mb-2">
                        <i class="iconfont iconzan me-1"></i>999
                        <i class="iconfont iconshoucang me-1"></i>100
                    </div>
                    <div class="card-subtitle text-muted">{$article.create_time}</div>
                </div>
            </div>

            {/foreach}
            {$articles|raw}



        </div>

    </div>
    <div class="py-2 text-center text-muted">
        黔ICP备2020009706号-1
    </div>
</div>
{/block}

{block name="js"}
<script src="/static/lib/swiper/swiper-bundle.min.js"></script>
<script>

    var swiper = new Swiper('.swiper-container', {
        pagination: {
            el: '.swiper-pagination',
            dynamicBullets: true,
        },
    });

</script>
{/block}

以上是关于php历史上的今天效果的主要内容,如果未能解决你的问题,请参考以下文章

历史上的今天:PHP公开发布;iPhone 4 问世;万维网之父诞生

历史上的今天11 月 22 日:PHP 创始人诞生;2020 年图灵奖得主出生;IE 2.0 发布

超级有用的9个PHP代码片段

历史上的今天:数据库之父逝世;苹果公司购买 CUPS 代码;IBM 芯片联盟

微信公众号开发---历史上的今天小实例

Java爬虫实践之获取历史上的今天