从WordPress网站提取内容以在HTML网站上显示 [英] Pull content from WordPress site to display on HTML site

查看:149
本文介绍了从WordPress网站提取内容以在HTML网站上显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WordPress网站,上面有博客,但我还有一个HTML/Dreamweaver网站.

I have a WordPress website with blogs on it, but I also have a HTML/Dreamweaver site.

我想让WordPress博客在更新WordPress网站时自动显示在我的index.html页面上.

I'd like to have the WordPress blogs automatically display on my index.html page when I update the WordPress website.

推荐答案

如果两个站点都托管在同一服务器上,则完全有可能.首先,您必须制作一个PHP文件,例如latest-post.php.并在下面添加代码

If both sites hosted on same server, it is simply possible. First you have to make a PHP file for example latest-post.php. and add the code below

<?php
define('WP_USE_THEMES', false);
require($_SERVER['DOCUMENT_ROOT'] . "/wp-load.php");
?>
<?php 
//The Loop - latest 5 posts from blogs category
$query1 = new WP_Query('showposts=5&cat=blogs&offset=0'); 
if ($query1->have_posts()) : 
while ($query1->have_posts()) : $query1->the_post(); 
?>
<div class="whatever you want to style">
<h2><!--The Title-->
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark">
<?php the_title(); ?>
</a>
</h2>
<!--thumbnail-->
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('Thumbnail'); ?>
</a>
<!--Excerpt-->
<p> <?php the_excerpt(); ?> </p>
</div>
<?php 
//loop ends
endwhile; endif; wp_reset_postdata(); 
?>  

将此文件放置在索引文件所在的非wordpress网站上,并在需要的位置包含上述lastest.php.

Place this file on your non wordpress site where your index file is and include the above latest.php where you want.

<?php include_once("latest-post.php"); ?>

如果您使用的是HTML文件,则PHP不会停止运行.您可以将索引文件.html重命名为.php或添加

If you are using HTML file, The PHP will not exicute. You can either rename index file .html to .php or add

AddType application/x-httpd-php .html

您的.htaccess文件.看一眼 从HTML运行PHP

to your .htaccess. Take a look at Run PHP from HTML

将数字"showposts = 5"更改为所需的帖子数,并将"cat = blogs"更改为"cat =您的类别名称"

Change the number "showposts=5" to how many posts you want, and change "cat=blogs" to "cat=your category name"

这篇关于从WordPress网站提取内容以在HTML网站上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆