Pārlūkot izejas kodu

碎语心情或说说页面实现

wqg 3 nedēļas atpakaļ
vecāks
revīzija
8e2af9908b

+ 89 - 0
usr/plugins/CateFilter/Plugin.php

@@ -0,0 +1,89 @@
+<?php
+/**
+ * 首页过滤指定分类
+ * 
+ * @package CateFilter
+ * @author Rakiy
+ * @version 1.2.5
+ * @link 
+ */
+class CateFilter_Plugin implements Typecho_Plugin_Interface
+{
+    /**
+     * 激活插件方法,如果激活失败,直接抛出异常
+     * 
+     * @access public
+     * @return void
+     * @throws Typecho_Plugin_Exception
+     */
+    public static function activate()
+    {
+        Typecho_Plugin::factory('Widget_Archive')->indexHandle = array(__CLASS__, 'filter'); 
+        return _t('插件已激活,现在可以对插件进行设置!');
+    }
+    /**
+     * 禁用插件方法,如果禁用失败,直接抛出异常
+     * 
+     * @static
+     * @access public
+     * @return void
+     * @throws Typecho_Plugin_Exception
+     */
+    public static function deactivate(){}
+    /**
+     * 获取插件配置面板
+     * 
+     * @access public
+     * @param Typecho_Widget_Helper_Form $form 配置面板
+     * @return void
+     */
+    public static function config(Typecho_Widget_Helper_Form $form){
+        
+    Typecho_Widget::widget('Widget_Metas_Category_List')->to($categories);
+    while($categories->next()){$cate[$categories->mid]=$categories->name;}//获取分类列表
+    
+    $CateId = new Typecho_Widget_Helper_Form_Element_Checkbox('CateId', 
+    $cate,[], _t('勾选首页不想显示的分类'), NULL);
+    $form->addInput($CateId->multiMode());
+ 
+    }
+    /**
+     * 个人用户的配置面板
+     * 
+     * @access public
+     * @param Typecho_Widget_Helper_Form $form
+     * @return void
+     */
+    public static function personalConfig(Typecho_Widget_Helper_Form $form){}
+    
+    /**
+     * 插件实现方法
+     * 
+     * @access public
+     * @return void
+     */
+ 
+    /**
+     * 插件实现方法
+     * 
+     * @access public
+     * @return void
+     */
+    public static function filter($obj, $select){
+        
+        $request = Typecho_Request::getInstance();
+        $pathInfo = $request->getPathInfo();
+        //throw new Exception($pathInfo);
+        if('/feed' == strtolower($pathInfo) || '/feed/' == strtolower($pathInfo)){
+           return $select; 
+        } 
+        $CateIds = Typecho_Widget::widget('Widget_Options')->plugin('CateFilter')->CateId;
+        if(empty($CateIds)) return $select;       //数组为空,则直接返回
+        $select = $select->join('table.relationships','table.relationships.cid = table.contents.cid','right')->join('table.metas','table.relationships.mid = table.metas.mid','right')->where('table.metas.type=?','category');
+        foreach ($CateIds as $k => $v) {
+            $select = $select->where('table.relationships.mid != '.intval($v))->group('cid');//确保每个值都是数字;排除重复文章
+        } 
+        return $select;
+    }   
+ 
+}

+ 48 - 0
usr/themes/default/page-mood.php

@@ -0,0 +1,48 @@
+<?php 
+/**
+ * 碎语心情
+ * @author WQG www.wqg.life
+ * @package custom
+ */
+
+if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
+<?php $this->need('header.php'); ?>
+
+
+<?php $this->widget('Widget_Archive@myCustomCategory', 'type=category', 'mid=7')->to($categoryPosts); ?>
+<div class="col-mb-12 col-8" id="main" role="main">
+    <?php if ($categoryPosts->have()): ?>
+        <?php while ($categoryPosts->next()): ?>
+            <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
+                <h2 class="post-title" itemprop="name headline"><a itemprop="url"
+                                                                   href="<?php $categoryPosts->permalink() ?>"><?php $categoryPosts->title() ?></a>
+                </h2>
+                <div class="post-content" itemprop="articleBody">
+                    <?php $categoryPosts->content('- 阅读剩余部分 -'); ?>
+                </div>
+                <ul class="post-meta">
+                    <li itemprop="author" itemscope itemtype="http://schema.org/Person"><?php _e('BY: '); ?><a
+                            itemprop="name" href="<?php $categoryPosts->author->permalink(); ?>"
+                            rel="author"><?php $categoryPosts->author(); ?></a></li>
+                    <li><?php _e('时间: '); ?>
+                        <time datetime="<?php $categoryPosts->date('c'); ?>"
+                              itemprop="datePublished"><?php $categoryPosts->date(); ?></time>
+                    </li>
+                    <li itemprop="interactionCount"><a
+                            href="<?php $categoryPosts->permalink() ?>#comments"><?php $categoryPosts->commentsNum('评论', '1 条评论', '%d 条评论'); ?></a>
+                    </li>
+                </ul>
+            </article>
+        <?php endwhile; ?>
+    <?php else: ?>
+        <article class="post">
+            <h2 class="post-title"><?php _e('没有找到内容'); ?></h2>
+        </article>
+    <?php endif; ?>
+
+    <?php $categoryPosts->pageNav('&laquo; 前一页', '后一页 &raquo;'); ?>
+</div><!-- end #main -->
+
+
+<?php $this->need('sidebar.php'); ?>
+<?php $this->need('footer.php'); ?>

+ 3 - 0
var/Widget/Contents/Post/Recent.php

@@ -29,10 +29,13 @@ class Recent extends Contents
         $this->parameter->setDefault(['pageSize' => $this->options->postsListSize]);
 
         $this->db->fetchAll($this->select()
+            ->join('table.relationships', 'table.contents.cid = table.relationships.cid')
+            ->where('table.relationships.mid != ?', 7)
             ->where('table.contents.status = ?', 'publish')
             ->where('table.contents.created < ?', $this->options->time)
             ->where('table.contents.type = ?', 'post')
             ->order('table.contents.created', Db::SORT_DESC)
+            ->group('cid')
             ->limit($this->parameter->pageSize), [$this, 'push']);
     }
 }