覆盖永久链接并在Wordpress目录外显示发布数据

时间:2017-01-30 14:37:09

标签: php wordpress

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

我有一个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'); ?>  

1 个答案:

答案 0 :(得分:0)

您可以使用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/