dt614037527 2012-06-24 00:30
浏览 21

从Wordpress自定义元框调用数据

Alright, I have created a custom meta box on the post edit screens for my custom post type. What I'd like to be able to do with it is allow the user to input a link and then have a button where the post is displayed to take the user to the specified link. What hook would I use to call the meta boxes data?

Thanks!

JWinton

  • 写回答

1条回答 默认 最新

  • duanci3845 2012-06-24 02:34
    关注

    I am not sure that I understand the question, but :

    1 - to display custom meta data you do not need a hook, but a function.

    it is called is get_post_meta() (click the link to learn more.)

    2 - If you want to create a link , usually what is done is to have 2 meta fields, One for the URL itself and one for the URL Display text ( or your button) .

    Then you cann do , for example :

    $my_URL = get_post_meta($post_id, $my_URL, true); ?>
    $my_URL_mask = get_post_meta($post_id, $my_URL_mask, true); ?>
    

    And then

     <a href="<? echo $my_URL; ?>" rel="whatever" title = "go to <?echo $my_URL;?>" alt="<?php echo $my_URL; ?>" /> <? echo $my_URL_mask ?> </a>
    

    Now , if your custom fields values will be for example :

    $my_URL = 'CLICK HERE';
    $my_URL = 'http://codex.wordpress.org/Function_Reference/get_post_meta';
    

    That will create you a link text link that will be like the one above .

    If you do not want the url mask, and only the URL to display as text - then just use one value .

    3 - If you want it to show in a BUTTON , that is a nother story, and it is CSS related - it will depend how you want your button to look, and in that case - you just put those values inside the markup.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?