简单的html dom与wordpress

问题描述 投票:0回答:2

我想使用 html 简单 dom 宽度 WordPress。问题是当我添加时:

require('../wp-blog-header.php');

脚本返回错误:

Fatal error: Call to a member function find() on a non-object in /home/labonnevisite/www/simpledom/simple_html_dom.php on line 1113

当我删除时:

require('../wp-blog-header.php');
我的脚本工作正常

这是我的脚本:

require('../wp-blog-header.php'); require_once 'simple_html_dom.php';

$html->load_file('http://www.urlofwebsite.com'); 
foreach($html->find('a.name') as $e) { $link = $e->href; echo $link . '<br>'; }
wordpress simple-html-dom
2个回答
0
投票

你可以使用

include('../wp-blog-header.php');

或使用内置 Wordpress 功能包含标题:

get_header(); // get_header( $name )

Wordpress 还具有一些内置功能,用于包含常用组件:

get_header()
get_footer()
get_sidebar()
get_template_part()
get_search_form()
comments_template()

法典中的更多信息: http://codex.wordpress.org/Include_Tags


0
投票

这可能有点晚了,但晚点总比不晚好? 为了使用

$html->load_file(...)

您需要首先初始化 html 对象,如下所示:

$html = new simple_html_dom(); $html->load_file(...)

© www.soinside.com 2019 - 2024. All rights reserved.