donglang9880 2017-07-25 00:06
浏览 336
已采纳

如何在所有WordPress帖子中插入PHP代码

I need to add my own custom PHP script to all Wordpress pages of my blog.

I am not referring to adding PHP onto a single page (which can be done with a plugin).

Essentially, this is what I need to do:

  • Add a snippet of code directly to Wordpress script that handles display of posts.
  • The snippet needs to be able to grab a ID of the post.

Can someone show me the best way to do this?

This is what I need to figure out:

  • Which of the Wordpress php files handles the display of the Wordpress posts (is it post-template.php by any chance?)

  • How to grab the Post ID using PHP? I found the page which says this could be the possible way, is that correct way of getting the Post ID?

    $id = get_the_ID();

  • 写回答

2条回答 默认 最新

  • douhuxi4145 2017-07-25 00:11
    关注

    for single post, it single.php and to get post ID

    $post = get_post();
    $id = $post->ID;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据