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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?