【发布时间】:2017-02-08 20:02:36
【问题描述】:
我正在尝试使用 api 从我朋友的 wordpress 中获取 CMS 页面内容。 这很好用,我可以使用 css 自定义内容。
但我知道你不应该在控制器中插入 html,有没有办法为此执行 .tpl 文件,然后调用该文件作为标题和内容 要么 如果您也能以某种方式将此内容提交给管理员,那就更好了,但我认为目前不可能?
但是,其他 cms 页面应该可以正常工作。
我目前在 CmsController.php 里面的函数 initContent:
if($this->cms->meta_title == 'mycmspage')
{
$ch = curl_init();
$timeout = 5;
$url = 'http://friendurl.com/wp-json/wp/v2/pages/xxx';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
$obj = json_decode($data, TRUE);
$this->cms->content = '<h2 class="myheader">'.$obj['title']['rendered'].'</h2><article class="myarticle">'. $obj['content']['rendered'].'</article>';
}
使用 prestashop 1.6.1
【问题讨论】:
标签: json content-management-system prestashop