Typecho通过后台多cid获取文章信息的字段写法教程

如下代码:

<?php $this->widget('Widget_Archive@indexxiu', 'pageSize=1&type=post', 'cid=1')->to($ji); ?>
标题:<?php $ji->title(); ?>
链接:<?php $ji->permalink(); ?>
描述:<?php $ji->description(); ?>
...

通过后台指定的话,则为

<?php $this->widget('Widget_Archive@indexxiu', 'pageSize=1&type=post', 'cid='.$this->options->imghdp.'')->to($ji); ?>

如果是多个的话

代码如下,其中166,163,160就是对应的三个文章的cid

<?php 
$lunbo="166,163,160";
$hang = explode(",", $lunbo);
$n=count($hang);
$html="";
for($i=0;$i<$n;$i++){
$this->widget('Widget_Archive@lunbo'.$i, 'pageSize=1&type=post', 'cid='.$hang[$i])->to($ji);
if($ji->fields->thumb){$img=$ji->fields->thumb;}
if($i==0){$no=" sx_no";}else{$no="";}
$html=$html.'<div class="sx_vt'.$no.'" name="'.$i.'" title="'.$ji->title.'" intro="'.$ji->description.'" hsrc="'.$ji->permalink.'"><img src="./images/load.jpg" bsrc="'.$img.'" alt="'.$ji->title.'"></div>';
}
echo $html;
?>

如果ID是后台functions设置的话,比如字段为:

$this->options->imghdp

那么完整的代码为

<?php 
$lunbo = $this->options->imghdp;
$hang = explode(",", $lunbo);
$n=count($hang);
$html="";
for($i=0;$i<$n;$i++){
$this->widget('Widget_Archive@lunbo'.$i, 'pageSize=1&type=post', 'cid='.$hang[$i])->to($ji);
if($ji->fields->thumb){$img=$ji->fields->thumb;}
if($i==0){$no=" sx_no";}else{$no="";}
$html=$html.'<div class="sx_vt'.$no.'" name="'.$i.'" title="'.$ji->title.'" intro="'.$ji->description.'" hsrc="'.$ji->permalink.'"><img src="./images/load.jpg" bsrc="'.$img.'" alt="'.$ji->title.'"></div>';
}
echo $html;
?>
文章由官网发布,如若转载,请注明出处:https://www.veimoz.com/30
2 条评论
4.6k

发表评论

已有 2 条评论

  1. 火喵酱     Win 10 /    Chrome
    2022-07-19 18:37

    问题貌似在$this->widget('Widget_Archive@lunbo'.$i, 'pageSize=1&type=post', 'cid='.$hang[$i])->to($ji);这句话上不对劲qaq

  2. 火喵酱     Win 10 /    Chrome
    2022-07-19 18:33

    后台报错403怎么回事啊,页面显示正常

!