我想将Wordpress(帖子)页面/网站的新闻部分嵌入到没有Wordpress菜单或页脚的html页面中,并使内容看起来好像它是该HTML页面的一部分。这是因为在WordPress中新闻故事的上传对于初学者来说更容易。将Wordpress内容嵌入到html中
1
A
回答
1
推荐的解决方案是使用WordPress来显示您使用其管理界面创建的帖子/内容。您可以从头创建一个主题(或修改现有的主题),以符合您现有的网站设计。但是,如果您使用PHP来生成其他HTML页面,您还可以包含WordPress引导文件(wp-load.php),然后使用WordPress功能get_posts()
来检索帖子列表。例如:
你的PHP文件:
<?php
// ...
// other stuff you do
// ...
require_once('/path/to/your/wordpress/installation/wp-load.php');
$posts = get_posts();
// do whatever you want with the array of found posts
var_dump($posts);
// ...
0
你可以用这种方式使用
<ul>
<?php
global $wpdb;
global $post;
$str = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'";
$result = $wpdb->get_results($str);
foreach($result as $post):
setup_postdata($post);?>
<li><a href="<?php the_permalink()?>"><?php the_title();?></a></li><?php
endforeach;?>
</ul>
或本
<?php
// Include WordPress
global $wpdb;
define('WP_USE_THEMES', false);
require('/server/path/to/your/wordpress/site/htdocs/blog/wp-blog-header.php');
query_posts('posts_per_page=1');
?>
<?php while (have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<p><a href="<?php the_permalink(); ?>" class="red">Read more...</a></p>
<?php endwhile; ?>
的jQuery注入的iframe成HTML,并使用卸下摆臂()删除所有不需要的东西...希望这个工程:) –