douxiapi4381 2016-02-08 13:06
浏览 72
已采纳

Wordpress作为端点

So, I'm building something and need to use wordpress as an endpoint.

I’ve a post url like http://example.com/sample-post. Now I’ve added a rewrite endpoint “edit”. So the url becomes http://example.com/sample-post/edit. Now whats the right way to print the url? Should it be like:

<?php echo get_permalink() . '/edit'; ?>

or is there any prefered way?

  • 写回答

1条回答 默认 最新

  • duancongjue9202 2016-02-08 13:14
    关注

    Yes, that would be the preferred way. However, I recommend writing a function in functions.php to do some additional checks before printing the link:

    function get_custom_edit_link() {
        // Check if we're on a Post page
        return is_single() ? get_permalink() . '/edit' : '';
    }
    

    And then in your template, call it with:

    echo get_custom_edit_link();
    

    However, if you're using this link to head to edit.php, you may want to consider using the get_edit_link() method of the WP_Posts_List_Table class.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥15 关于超局变量获取查询的问题
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能