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 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图