php - wp 安装文件夹外的 the_permalink() wordpress
问题描述
这是我在 wordpress 安装目录之外加载 wordpress 帖子的代码。我发现我的先例问题和一个旧主题非常有用,该主题将讨论 wp 函数在其他独立 php 页面中的这种用法。
PHP查询
<?php
define('WP_USE_THEMES', FALSE);
require 'portfolio/wp-load.php';
$args = array(
'posts_per_page' => 6,
#'offset' => 0,
#'category' => 'portfolio',
#'category_name' => '',
#'orderby' => 'date',
#'order' => 'DESC',
#'include' => '', 'exclude' => '',
#'meta_key' => '',
#'meta_value' => '',
#'post_type' => 'post', 'post_mime_type' => '',
#'post_parent' => '',
#'author' => '',
#'post_status' => 'publish',
#'suppress_filters' => true
);
$portfolio_items = new WP_Query( $args );
?>
html
<div class="row" id="portfolioPosts">
<?php
if($portfolio_items->have_posts()):
while($portfolio_items->have_posts()):
$portfolio_items->the_post(); ?>
<div class="col-sm-12 col-md-4 col-lg-4" id="portfolio-grid-el">
<a class="portfolio-link" href="<?php the_permalink(); ?>">
<?php
if(has_post_thumbnail()):
the_post_thumbnail('post-thumbnail', ['class' => 'card-img-top post-preview', 'title' => 'Feature image']);
endif;
?>
<h4 class="portfolio-post-title text-uppercase"><?php the_title(); ?></h4>
</a>
</div>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); wp_reset_query(); ?>
</div>
我的问题是关于the_permalink()
功能,如何正确链接它,我已经将 wordpress 配置为使用我的网站索引,该索引是 wp 安装目录之外和网站根目录中的独立页面。现在每次我点击链接时,地址都是http://localhost:8000/mysite/post-name
这样,我将无法显示帖子。我想使用一个解决方案,其中<a href="">
链接相对于 wordpress 安装路径或相对于将接受帖子名称作为参数并加载内容的页面,正如我通过使用带有自定义查询的循环所理解的那样。是否可以?
解决方案
推荐阅读
- python-3.x - 在 django 石墨烯中似乎没有调用 model.UUIDField() 的默认值
- reactjs - 如何在 React Native 中使用带有 RNPickerSelect 的 React Hook Form?
- python - 时间序列平稳技术
- typescript - 如何使用默认值从打字稿文件中导出所有功能?
- reactjs - 创建用户后如何将数据添加到firestore文档
- javascript - Chrome不会循环更改按钮文本
- android - 将数据从回收器视图传递到报价应用程序中的新活动,新活动正在打开但数据未到来
- javascript - 使用 Angular 检查 Firebase 数据库中是否存在数据
- unity3d - Unity 2020.2.0a13 中的精灵问题
- macos - 将 Conduktor 连接到 Kafka Docker 容器