dongmeixian9665 2013-09-24 06:06
浏览 26
已采纳

是否可以定义短代码,然后在模板文件中加密 - Wordpress

I have a file a.php where I have defined <a href="abc.com/page_id=11?key=123">link</a>

I have created a custom template custom.php and created a page at wordpress backend that has page_id=11

So, from a.php I am sending a user to custom.php with the help of page_id and then fetching the key=123

This is working fine..

The only problem is that I am not sure about page_id = 11.

Is it possible to get the same using the shortcode so as I can avoid using the page_id in my template file.

  • 写回答

1条回答 默认 最新

  • doudouba4520 2013-09-24 07:17
    关注

    Function to create a shortcode to get the page id

    function id_shortcode( $atts ) {
        // extract the variables, if there is no ID attr, the default is 1
        extract( shortcode_atts( array(
            'id' => 1
        ), $atts ) );
        // set page id to either the id attr which defaults to one.
        $page_id = $id;
        $page_data = get_page( $page_id );
        return 
    }
    // shortcode registration
    add_shortcode( 'getid', 'id_shortcode' );
    

    Then you can simply use [getid] shortcode on your page to get that page id

    I hope i have understood and solved your problem...

    And you can call this shortcode also in your template file

    <?php echo do_shortcode("[getid]"); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集