我有这个动态发布的href链接,我想获取single.php文件,并将动态帖子重定向到我的single.php文件以下是我的链接:
<a href="/single-<?php the_ID();?>-<?php the_slug(); ?>" class="wrapper" style="background-image:url('<?=$url?>')">
当我点击链接时,URL就是这样:
/single-137-2014-inaugural-diversity-abroad-conference-4
我希望将该页面重定向到我的single.php文件。我怎么能这样做?
任何帮助都非常感激。 TIA
答案 0 :(得分:1)
我已解决您的问题,但请阅读get_permalink()
功能
<a href="<?php echo get_permalink(); ?>" class="wrapper" style="background-image:url('<?=$url?>')">
get_permalink()
- 检索当前帖子或帖子ID的完整固定链接(帖子的链接)。此链接将在单页后打开,这意味着如果这是一个自定义的帖子类型,并且您将其创建为单独的单post-type.php,那么它将作为一个开放的单post-type.php页面。否则它显示为single.php。
有关您的信息,在使用page.php打开页面时,已在single.page中打开帖子。阅读此链接https://codex.wordpress.org/Post_Type_Templates