首页 > 解决方案 > 子目录中的 WP:如何在根目录中的非 wp 上显示项目

问题描述

Wordpress 安装在子目录 «/blog» 中,可以在那里访问。我试图找出如何将最后一个博客项目作为主要文章放在非 wp 根目录 «index.php» 中。

我只能在子目录中找到关于 WP 的信息,如果它在根目录中则执行操作,但这不是我想要的。博客必须保留在子目录中,因为站点的其余部分是非 WP。我知道这是可能的;几年前我读过它,但我再也找不到那个来源了。

标签: phpwordpress

解决方案


在根索引中添加: require('blog/wp-blog-header.php');

然后你想在哪里发布你的帖子:

<article>
<?php
    $posts = get_posts('numberposts=1&order=ASC&orderby=post_title');

    foreach ($posts as $post) : setup_postdata( $post ); ?>
    <?php the_date(); echo "<br />"; ?>
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <? 
    php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>    
    <?php the_excerpt(); ?> 

    <?php endforeach;?>

</article>

就是这样... 来源:https ://codex.wordpress.org/Integrating_WordPress_with_Your_Website


推荐阅读