Пример #1
0
 public function actionIndex()
 {
     $type = intval($this->get("type", 1));
     $type = in_array($type, [1, 2, 3]) ? $type : 1;
     $p = intval($this->get("p", 1));
     if (!$p) {
         $p = 1;
     }
     $data = [];
     $pagesize = 10;
     $offset = ($p - 1) * $pagesize;
     $query = Posts::find()->where(['status' => 1]);
     switch ($type) {
         case 2:
             $query->orderBy(['view_count' => SORT_DESC]);
             break;
         case 3:
             $query->andWhere(['original' => 1]);
             $query->orderBy(['id' => SORT_DESC]);
             break;
         default:
             $query->orderBy(['id' => SORT_DESC]);
             break;
     }
     $total_count = $query->count();
     $posts_info = $query->offset($offset)->limit($pagesize)->all();
     if ($posts_info) {
         $idx = 1;
         $author = Yii::$app->params['author'];
         foreach ($posts_info as $_post) {
             $tmp_content = UtilHelper::blog_summary($_post['content'], 105);
             $tags = explode(",", $_post['tags']);
             $data[] = ['idx' => $idx, 'id' => $_post['id'], 'title' => DataHelper::encode($_post['title']), 'content' => nl2br($tmp_content), 'original' => $_post['original'], 'view_count' => $_post['view_count'], 'author' => $author, 'tags' => $tags, 'date' => date("Y.m.d", strtotime($_post['updated_time'])), 'view_url' => UrlService::buildUrl("/default/info", ["id" => $_post['id']])];
         }
     }
     $page_info = DataHelper::ipagination(["total_count" => $total_count, "page_size" => $pagesize, "page" => $p, "display" => 5]);
     $tags = CacheHelperService::getFrontCache("tag");
     return $this->render("index", ["data" => $data, "page_info" => $page_info, "type" => $type, "hot_kws" => array_slice($tags, 0, 5)]);
 }
Пример #2
0
<?php

use common\service\CacheHelperService;
use common\service\GlobalUrlService;
use blog\components\UrlService;
$wx_urls = ["my" => GlobalUrlService::buildStaticUrl("/images/weixin/my.jpg"), "imguowei" => GlobalUrlService::buildStaticUrl("/images/weixin/imguowei_888.jpg"), "starzone" => GlobalUrlService::buildStaticUrl("/images/weixin/mystarzone.jpg")];
$tags = CacheHelperService::getFrontCache("tag");
?>
<aside class="col-md-4 sidebar">
    <div class="widget hide">
        <h4 class="title">搜索</h4>
        <div class="content search">
            <div class="input-group">
                <input type="text" class="form-control" id="kw"/>
                <span class="input-group-btn">
                    <button class="btn btn-default do-search" type="button" style="padding: 6px 12px;">搜索</button>
                </span>
            </div>
        </div>
    </div>
    <div class="widget hidden content_index_wrap">
        <h4 class="title">目录</h4>
        <div class="content">

        </div>
    </div>
    <div class="widget">
        <h4 class="title">智能推荐</h4>
        <div class="content recommend_posts">
                <?php 
foreach ($recommend_blogs as $_recommend_blog_info) {
Пример #3
0
<?php

use common\service\CacheHelperService;
use common\service\GlobalUrlService;
$data = CacheHelperService::getFrontCache();
$tags = $data['tag'];
$post_hot = array_slice($data['post_hot'], 0, 5);
$post_latest = array_slice($data['post_latest'], 0, 5);
?>
<footer class="main-footer">
    <div class="container">
        <div class="row">
            <div class="col-sm-4">
                <div class="widget">
                    <h4 class="title">热门文章</h4>
                    <div class="content recent-post hots-post">
                        <?php 
if ($post_hot) {
    ?>
                            <?php 
    foreach ($post_hot as $_post_info) {
        ?>
                                <div class="recent-single-post">
                                    <a href="<?php 
        echo $_post_info['detail_url'];
        ?>
" class="post-title">
                                        <?php 
        echo $_post_info['title'];
        ?>
                                    </a>