Wordpress:从其他页面获取指定内容
我只想显示从一个站点到另一个站点的特定内容 例如:Wordpress:从其他页面获取指定内容,wordpress,get,Wordpress,Get,我只想显示从一个站点到另一个站点的特定内容 例如: 我想在另一个@页面中显示一些文本 A页: <h2>This is page A</h2> <div id="showonly">This is the content I want to show in footer for ex.</div> 在footer.php中,我执行了以下操作: $content_leweb = show_post_leweb('kontakt'); echo
我想在另一个
@页面中显示一些文本
A页:
<h2>This is page A</h2>
<div id="showonly">This is the content I want to show in footer for ex.</div>
$content_leweb = show_post_leweb('kontakt');
echo '<div class="special-content">' .$content_leweb . '</div>';
$content_leweb=show_post_leweb('kontakt');
回显“.$content_leweb.”;
工作正常,但我只需要一个特定的div,而不是整个页面,就像我上面提到的。您需要使用
preg\u match
从输出中获取特定内容
所以使用preg_匹配。把启动条件。。。结束div。然后在输出中只获得div内容
有关更多信息,请参阅
首先,通过使用,让你的正则表达式不那么贪婪?操作人员这将确保你不会得到比你认为你会得到的更多。接下来是表达式末尾的/s运算符。我假设您解析的HTML文件有许多新行字符“\n”
$value=preg_match_all('/(.*?)/s',$file_contents,$assessment);
$content_leweb = show_post_leweb('kontakt');
echo '<div class="special-content">' .$content_leweb . '</div>';
$value=preg_match_all('/<div class=\"name\-of\-class\">(.*?)<\/div>/s',$file_contents,$estimates);