官方教程 : https://www.wellcms.cn/read-204.html
官方这次更新的调用数据非常强大,赞一个.
演示图:
域名换成自己的 , ?tag 伪静态把?号删掉, tag-1 获取文章的tag-ID
<?php
$url = 'http://域名/?tag-1.html?ajax=1';
$json = http_get($url); /*得到 json 数据*/
$datalist = xn_json_decode($json); /* json 数据转为数组 */
/*
print_r($datalist);
*/
$_threadlist = $datalist['message']['threadlist']; /* 列表 */
?>
调用结束,输出
<?php if($_threadlist){foreach($_threadlist as $_thread) { ?>
<li class="list-group-item bg-white">
<h4 class="h6 my-0">
<a href="<?php echo $_thread['url'];?>" class="d-block ellipsis" <?php echo (10==$_thread['type']?'rel="nofollow" target="_blank"':''); ?>>
<?php echo $_thread['subject'];?>
</a>
</h4>
</li>
<?php }} ?>
- 燃烧的冰2021-4-292楼这就对了,东西给大家了,就看大家自己怎么变通使用。不管什么方法,目前能解决问题就是好方法。
- mytest2021-4-293楼这种有什么弊端吗,每次都要访问一次 网址. 必定要解析域.
- 燃烧的冰2021-4-294楼
没啥弊端,什么时候达到日IP几十万的时候找我解决。
API开放状态,方便别人采集你的站点。没有太好的解决的办法,就是大站的 API 一样会被采集。等到需要解决的时候,加key解决就行了,不过依然会被破解,只是增加了难度而已。 - mytest2021-4-305楼
已知弊端. 5个TAG标签,全部调取,速度会变慢0.1XX 秒 调取1个TAG标签是 0.0X ,毕竟要循环请求api5次.
<?php
$taglist = xn_json_decode($thread['tag']);
$_taglist = array();
foreach($taglist as $_tagid => $value)
{
$url = 'http://域名/?tag-'.$_tagid.'.html?ajax=1';
$json = http_get($url);
$datalist = xn_json_decode($json);$_threadlist = $datalist['message']['threadlist'];
$_taglist= array_values(array_unique(array_merge($_taglist, $_threadlist),$tid)); //合并数组}
$_threadlist = $_taglist; //老代码没有改,重新赋值下.
?>
<!-- 调出相关文章 --><!-- 循环输出 -->
<?php if($_threadlist){foreach($_threadlist as $i=> $_thread) { if ( $i >9 ){break;} ?>
<?php if($tid != $_thread['tid']){ ?><li class="list-group-item bg-white">
<h4 class="h6 my-0">
<a href="<?php echo $_thread['url'];?>" class="d-block ellipsis" <?php echo (10==$_thread['type']?'rel="nofollow" target="_blank"':''); ?>>
<?php echo $_thread['subject'];?>
</a>
</h4>
</li>
<?php }}} ?>