typecho调用指定文章
admin
撰写于 2021年 03月 08 日

typecho调用指定文章

在functions.php中加入如下代码

 class Widget_Post_fanjubiao extends Widget_Abstract_Contents
{
public function __construct($request, $response, $params = NULL)
{
    parent::__construct($request, $response, $params);
    $this->parameter->setDefault(array('pageSize' => $this->options->commentsListSize, 'parentId' => 0, 'ignoreAuthor' => false));
}
public function execute()
{
    $select  = $this->select()->from('table.contents')
->where("table.contents.password IS NULL OR table.contents.password = ''")
->where('table.contents.type = ?', 'post')
->limit($this->parameter->pageSize)
->order('table.contents.modified', Typecho_Db::SORT_DESC);

 if ($this->parameter->fanjubiao) {
 $fanju=explode(",",$this->parameter->fanjubiao);
 $select->where('table.contents.cid in ?', $fanju);
 }
  $this->db->fetchAll($select, array($this, 'push'));
}
  }

然后在前台调用热门文章时就可以这样写了

 <?php 
 $week1="728,1197";//指定文章id集合多个文章中间用英文逗号隔开
 $this->widget('Widget_Post_fanjubiao@fanjubiao', 'fanjubiao='.$week1)->to($fanju); ?>
 <?php while($fanju->next()): ?>
 文章链接:<?php $fanju->permalink() ?>
 文章标题:<?php $fanju->title(); ?>
 <!--等等-->
  <?php endwhile; ?>

这种写法非常原生,使用方法也同typecho调用某分类下的文章语法一致

typecho调用指定文章

typecho调用指定文章

在functions.php中加入如下代码

 class Widget_Post_fanjubiao extends Widget_Abstract_Contents
{
public function __construct($request, $response, $params = NULL)
{
    parent::__construct($request, $response, $params);
    $this->parameter->setDefault(array('pageSize' => $this->options->commentsListSize, 'parentId' => 0, 'ignoreAuthor' => false));
}
public function execute()
{
    $select  = $this->select()->from('table.contents')
->where("table.contents.password IS NULL OR table.contents.password = ''")
->where('table.contents.type = ?', 'post')
->limit($this->parameter->pageSize)
->order('table.contents.modified', Typecho_Db::SORT_DESC);

 if ($this->parameter->fanjubiao) {
 $fanju=explode(",",$this->parameter->fanjubiao);
 $select->where('table.contents.cid in ?', $fanju);
 }
  $this->db->fetchAll($select, array($this, 'push'));
}
  }

然后在前台调用热门文章时就可以这样写了

 <?php 
 $week1="728,1197";//指定文章id集合多个文章中间用英文逗号隔开
 $this->widget('Widget_Post_fanjubiao@fanjubiao', 'fanjubiao='.$week1)->to($fanju); ?>
 <?php while($fanju->next()): ?>
 文章链接:<?php $fanju->permalink() ?>
 文章标题:<?php $fanju->title(); ?>
 <!--等等-->
  <?php endwhile; ?>

这种写法非常原生,使用方法也同typecho调用某分类下的文章语法一致

那年今日
03月
08日
赞 (0)

猜您想看

评论区(暂无评论)

这里空空如也,快来评论吧~

我要评论