【问题标题】:Override Permalink and Display Post Data Outside Wordpress Directory覆盖永久链接并在 Wordpress 目录之外显示帖子数据
【发布时间】:2017-01-30 22:47:08
【问题描述】:

我需要拉出一篇博文并显示在位于 Wordpress 文件夹之外的自定义 single.php 页面上。

我有一个index.php,该页面会拉出我最近页面的列表,但是,单击永久链接却无处可去。永久链接认为它在 Wordpress 文件夹中,所以链接是相对的。

我只想要 index.php 永久链接,点击后将用户带到我的博客文件夹外的single.php 并显示该帖子。

这是我到目前为止所拥有的,但我不知道如何让他的永久链接将用户发送到我的single.php 页面

我的文件夹结构可帮助您可视化我的布局

+ /blog/
    - All the standard wordpress stuff in this folder
- index.php (shows recent)
- single.php (where I want the user to go)

single.php

<?php include_once('_header.php');
require_once(constant('ROOT') . '/blog/wp-load.php'); 
 ?>   
    <div class="row">
        <div class="col-sm-12">
            <?php 
                if ( have_posts() ) : while ( have_posts() ) : the_post();
                    get_template_part( 'content-single', get_post_format() );
                    if ( comments_open() || get_comments_number() ) :
                        comments_template();
                    endif;
                endwhile; endif; 
            ?>
        </div> <!-- /.col -->
    </div> <!-- /.row -->
    <hr/>
<?php include_once('_footer.php'); ?>  

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    您可以使用 post_type_link 过滤器来更改永久链接。

    类似:

    add_filter('post_type_link', 'custom_links')
    
    function custom_links($post_link, $post) {
        if (some conditions of $post) {
            str_replace("what you want to replace", "it's replacement", $post_link)
        }
    return $postlink;
    }
    

    https://developer.wordpress.org/reference/hooks/post_type_link/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-22
      • 2012-04-06
      • 2015-08-21
      • 1970-01-01
      • 1970-01-01
      • 2012-09-11
      • 2012-07-01
      相关资源
      最近更新 更多