简体   繁体   English

在Wordpress中查看自定义帖子类型时如何添加一些内容?

[英]How to add some content when viewing custom post type in wordpress?

I'm developing a wordpress plugin and I got a custom post types with some meta datas. 我正在开发一个wordpress插件,并获得了一些元数据的自定义帖子类型。 for example we got meta data "code" and "name". 例如,我们获得了元数据“代码”和“名称”。 the thing that I want is in viewing post page (example.com/?post_type=1) show the meta data first and then the content of that post. 我想要的是在查看帖子页面(example.com/?post_type=1)中首先显示元数据,然后再显示该帖子的内容。 is there anyway to do that ? 反正有这样做吗?

You will need to edit the template for your post type, this should be single-yourposttype.php if you don't have one create one - clone single.php if you need to. 您将需要为您的帖子类型编辑模板,如果您没有创建一个模板,则应为single-yourposttype.php如果需要,请克隆single.php。

Then within that page before the_content() use: 然后在该页面中使用the_content()之前:

global $post;    
echo get_post_meta( $post->ID, 'code', true );

Where "code" is the name of your meta field, repeat that second line for as many meta data fields you have and need. 其中“代码”是您的元字段的名称,请对您拥有和需要的许多元数据字段重复第二行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM