dongpao5658 2012-03-23 15:17
浏览 35
已采纳

WordPress自定义帖子类型

I am building a custom post type and looking for a solution either to have a custom meta box on there so that the admin could choose which page the custom post type appears on.

E.g. I have a custom post type called Testimonials.

This is a list of testimonials on a page which contains a featured image, the title, and the content.

There will be a page which all are listed and I can do this using a standard WP Query

On certain pages (e.g. about, news, case-studies) I want to be able to print testimonials in the sidebar of the page. A certain testimonial that the admin can choose from a drop down to put the testimonial on that page.

1 Testimonial per page.

I look forward to your response and feedback

  • 写回答

2条回答 默认 最新

  • douzengjian1535 2012-03-23 16:55
    关注

    You can add a custom meta box to the custom post type using add_meta_box.

    http://codex.wordpress.org/Function_Reference/add_meta_box

    add_meta_box(
        'meta_box_id', //The ID of the Meta Box
        'Meta Box Title', //The Title of the Meta Box
        'meta_box_id_meta_box', //Callback Function
        'page', //Post type to apply to, in this case you would want 'page', or the ID of a Custom Post Type
        'normal', //Priority 
        'default' //Callback Agruments
    );
    

    You can find out more information about how this function is added to a hook, saved etc. here: http://wp.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/

    From there, you just need to make a select menu that consists of all of the page IDs for your custom content type (by using WP_Query, and looping through the results). When you save the form, it saves the ID, and then you use that ID in conjunction with your WP_Query to pull the single post and display it on the page template.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line