今天突发奇想,想把WordPress中文社区的视频课程放到WordPress日记网站上显示,从而为本网站进行引流,一开始想着是在WordPress日记网站上开发个页面,手动添加对应的课程链接,突然想能不能直接把WordPress中文社区的课程内容直接读取出来然后显示在WordPress日记上呢?网上搜了一下还真有,现在就分享到这里:
首先需要在被调用的WordPress主题网站的根目录,记着一定是根目录,创建一个php文件,名字你自己定义,比如我写的是mxshow.php,编码格式要是UFT-8无B哦,然后把下面的代码放进去保存:
<?php
define('WP_USE_THEMES', false);
require('./wp-load.php');
?>
//下面就是你要获取的内容,想获取什么就获取什么,比如这里获取文章
<?php
query_posts('showposts=10');
while (have_posts()): the_post();
?>
<li>
<a href="<?php%20the_permalink();%20?>" target="_blank">
<?php the_title();?>
</a>
</li>
<?php endwhile; ?>
然后在你需要显示这些内容的WordPress主题中需要显示的地方使用下面代码就可以了:
<?php
ini_set("user_agent","Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)");
$url="https://被调用网站的域名/mxshow.php";
echo file_get_contents( $url );
?>
然后到你自己的网站上看内容已经显示出来了,你可以根据情况去调整一下样式就行了,不过感觉好像有点慢,哈哈
Related: 2022 farm system rankings, nashville traffic accidents today, wire transfer limits bank of america, are bay leaf trees toxic to dogs, commissary clark county jail, gaston county police department staff, uiuc move in day fall 2020, fitchburg district attorney's office, parkasaurus xbox one, facts about sports in the 1920s, what happened to the olsen twins with bob, duroc pigs for sale near me, ky3 weather girl leaving, average high school kicker distance, toronto property tax customer number,
还没有任何评论,你来说两句吧