文章采集调用(免费开源可商用的PHP万能建站程序-DiYunCMS(帝云CMS))

优采云 发布时间: 2021-12-20 15:03

  文章采集调用(免费开源可商用的PHP万能建站程序-DiYunCMS(帝云CMS))

  免费、开源、可商用的PHP通用建站程序-帝云cms(帝云cms)

  对于个性化的需求,需要在首页或者其他模板页面的指定分类下调用文章,那么我们就可以实现:

  网上很容易找到这个教程,但是有个问题。调用的文章没有按最新排序,或者发布时间越早排在前面,肯定是不合理的。已修复一流的资源网络。这个问题。

  1、首先打开index.php文件,找到如下代码:

  $smarty->assign('new_articles', index_get_new_articles()); // 最新文章

  在此行下方添加以下代码:

  $smarty->assign('class_articles_4', index_get_class_articles(4,6)); // 分类调用文章

  4 是 文章 类别 ID,6 是显示的项目数。

  如果调用的category很多,只需要复制粘贴上一行即可,但是文章category id和调用次数要根据自己的需要修改。

  打开ecshop根目录下的includes/init.php文件,在最下方添加如下代码,并添加到?>。

  2、还在这个文件中吗?> 在这之前添加以下函数:

  /**

* 获得指定栏目最新的文章列表。

*

* @access private

* @return array

*/

function index_get_class_articles($cat_aid, $cat_num)

{

$sql = "SELECT article_id, title,open_type,cat_id,file_url,description FROM " .$GLOBALS['ecs']->table('article'). " WHERE cat_id = ".$cat_aid." and is_open = 1 ORDER BY add_time DESC LIMIT " . $cat_num;

$res = $GLOBALS['db']->getAll($sql);

$arr = array();

foreach ($res AS $idx => $row)

{

$arr[$idx]['id'] = $row['article_id'];

$arr[$idx]['title'] = $row['title'];

$arr[$idx]['file_url'] = $row['file_url'];

$arr[$idx]['description'] = $row['description'];

$arr[$idx]['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ?

sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title'];

$arr[$idx]['cat_name'] = $row['cat_name'];

$arr[$idx]['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']);

$arr[$idx]['url'] = $row['open_type'] != 1 ?

build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']);

$arr[$idx]['cat_url'] = build_uri('article_cat', array('acid' => $row['cat_id']));

}

return $arr;

}

<p>3、在要调用index.dwt模板的地方添加如下代码(注意:调整上面设置中的文章列表,类别ID为4):

0 个评论

要回复文章请先登录注册


官方客服QQ群

微信人工客服

QQ人工客服


线