php - 子目录中的 WP:如何在根目录中的非 wp 上显示项目
问题描述
Wordpress 安装在子目录 «/blog» 中,可以在那里访问。我试图找出如何将最后一个博客项目作为主要文章放在非 wp 根目录 «index.php» 中。
我只能在子目录中找到关于 WP 的信息,如果它在根目录中则执行操作,但这不是我想要的。博客必须保留在子目录中,因为站点的其余部分是非 WP。我知道这是可能的;几年前我读过它,但我再也找不到那个来源了。
解决方案
在根索引中添加: 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
推荐阅读
- javascript - 单击任何其他父菜单的子菜单或同一子菜单时如何关闭多个子菜单
- c++ - 在 gdb 和 gdbserver 中调试时有什么方法可以制作钩子吗?
- python - 如何从列表中一次显示一个元素而不在 Python 中重复相同的元素
- ios - 集合视图单元格未正确显示
- html - 如何使用 htaccess 从 url 中删除 .html 用于 tomcat 服务器
- reactjs - 如何从单独的组件调用组件中的函数?
- swift - Swift/Firestore/Cloud Functions - 向随机用户发送消息
- java - 要打印的字符串包含 3 个字母后跟 7 个数字
- xml - 使用 Camel 将 java.util.Date 存储为标头中的 java.util.Date
- c++ - C++:使用更大的比较器实现意外的性能提升