找出哪个php文件在WordPress中生成了一行html代码的最佳方法

时间:2021-11-23 01:04:32

Using Chrome you can right click - Inspect element to see the html code behind that element:

使用Chrome,您可以右键单击 - 检查元素以查看该元素后面的html代码:

找出哪个php文件在WordPress中生成了一行html代码的最佳方法

I wonder how to find which php file has generated that html. Maybe there is some tool to put a breakpoint into the html so the php server will stop when trying to generate it again?

我想知道如何找到哪个php文件生成了那个html。也许有一些工具可以将断点放入html中,以便php服务器在尝试再次生成时停止运行?

I'm using WordPress locally. I'm on Ubuntu 14.04LMS. I'm using Sublime Text 3 with XDebug.

我在本地使用WordPress。我在Ubuntu 14.04LMS上。我正在使用Sublime Text 3和XDebug。


UPDATE 1

A WordPress plugin able to put, in every file, something like the following would be a good solution (I think from my beginner's viewpoint):

一个WordPress插件能够在每个文件中放入类似下面的内容,这将是一个很好的解决方案(我想从我的初学者的角度来看):

echo '<!-- name_of_the_php_file.php -->';

8 个解决方案

#1


15  

Use this plugin "what the file" to find out the php file. Then rest it is to find out a function or something else by CTRL + F in any editor.

使用这个插件“什么文件”来找出php文件。然后休息是在任何编辑器中通过CTRL + F找到一个函数或其他东西。

I want to add one more plugin which is not exactly for this purpose but it is very popular among WordPress developers and it solves this problem very well. The plugin is Query Monitor.

我想添加一个不完全用于此目的的插件,但它在WordPress开发人员中非常受欢迎,它很好地解决了这个问题。该插件是Query Monitor。

#2


5  

Put an echo in your PHP pages to print their name in an HTML comment based on whether a session variable is set. Then set that session variable and enjoy.

在PHP页面中放置一个echo,根据是否设置了会话变量,在HTML注释中打印其名称。然后设置该会话变量并享受。

if(isset($_SESSION['printPageName']) && $_SESSION['printPageName']=='true')
{
   echo '<!-- ' . $_SERVER['PHP_SELF'] . ' -->';
}

The reason I say to use a session variable is so you can create some mechanism to where you can occasionally look at this for debug purposes, but users don't normally encounter it.

我说使用会话变量的原因是你可以创建一些机制,你可以偶尔看看这个用于调试目的,但用户通常不会遇到它。

#3


5  

Unfortunately with wordpress you need to do some digging:

不幸的是,使用wordpress你需要做一些挖掘:

  1. Is it a page/ post / custom post (i.e. you can find the page in the admin section and edit it)
  2. 是页面/帖子/自定义帖子(即您可以在管理部分找到该页面并进行编辑)

  3. If yes - look the the template assigned (posts don't usually have a template select field unless custom code added) and find the matching page template in your theme (page-whatever.php)(it might not be called what you see in the dropdown field, but in its notes it will have the name you see), or if a post you are looking for single.php or if custom post look for single-whatever.php.
  4. 如果是 - 查看分配的模板(帖子通常没有模板选择字段,除非添加了自定义代码)并在主题中找到匹配的页面模板(page-whatever.php)(它可能不会被称为你在下拉字段,但在其注释中它将具有您看到的名称),或者如果您要查找的帖子是single.php,或者如果自定义帖子查找single-whatever.php。

  5. The above is default and will cover 60% of situations. But if you add a plugin and it adds new pages, the page template will be in the plugin and the real fun starts.
  6. 以上是默认情况,将覆盖60%的情况。但是如果您添加插件并添加新页面,则页面模板将位于插件中,并开始真正的乐趣。

  7. If a plugin is developed with user mods in mind, it should have its pages in 1 location or in a functional set folder. Have a look for the above files in these locations if they exist or in the general plugin folders.
  8. 如果开发插件时考虑了用户mod,则应将其页面放在1个位置或功能集文件夹中。如果存在这些位置或在常规插件文件夹中,请查看上述文件。

  9. If still no luck, have a look for add_action('save_post', 'whatever'); there may be code stating return $template , this will prob also have the post type in the function. Look for the path its calling
  10. 如果仍然没有运气,请查看add_action('save_post','what');可能有代码声明返回$ template,这也可能在函数中有post类型。寻找它的召唤之路

  11. Another way to add a page is through a url rewrite (search through the files for rewrite). It will contain a path somewhere to the file (there are a couple of methods of doing this so look them up so you will recognise them).
  12. 添加页面的另一种方法是通过URL重写(搜索文件进行重写)。它将包含文件某处的路径(有几种方法可以执行此操作,因此您可以查看它们以便识别它们)。

If you think you have found the correct template, try a echo to see if it appears on screen. If yes you have found the template, look at what you have follow the includes/ requires to appropiate .php files, you'll find your html somewhere either as html or php code creating html.

如果您认为找到了正确的模板,请尝试使用回声查看它是否出现在屏幕上。如果是,你已经找到了模板,看看你有什么跟随包含/要求合适.php文件,你会发现你的HTML在某处作为html或PHP代码创建HTML。

hopefully you find what you are looking for, but there are no rules really and other methods can exist including htaccess rewrites to point to php file, etc or a functions file creating pages on the fly

This might be a good point to mention if you ever create a entire plugin, store files logically and include from a file controller or plugin file. Store pages in a pages folder so they are easy to find.

如果你创建一个完整的插件,逻辑地存储文件并包含文件控制器或插件文件,这可能是一个很好的点。将页面存储在页面文件夹中,以便于查找。

Good luck!

update: filter to output path on template files

更新:过滤到模板文件的输出路径

add_filter( 'template_include', 'show_path', 99 );

function show_path( $template ) {

            if($template):
                echo $template;
            else:
                echo "template path not found";
            endif;

    return $template;
}

#4


1  

Another possibility would be to copy an id or class from the html. Then search that string through the source code of the WordPress web application to put a breakpoint at every place where the string appears.

另一种可能性是从html中复制id或类。然后通过WordPress Web应用程序的源代码搜索该字符串,在字符串出现的每个位置放置一个断点。

However, the string could be in the database. In that case, this method won't work.

但是,字符串可以在数据库中。在这种情况下,此方法将不起作用。

#5


1  

First tack a backup of whole websiter, suppose /my-website

首先是整个网站服务器的备份,假设/我的网站

1.Right click on element for that you want to find php code

2.Cope CLASS or ID selector of that line

3.Search that CLASS or ID selector in editor inside /my-website folder, for this notepad++ and Dreamweaver editor is best.

1.右键单击元素,找到你要找到的PHP代码2.Cope CLASS或该行的ID选择器3.在编辑器/ my-website文件夹中搜索CLASS或ID选择器,对于这个记事本++和Dreamweaver编辑器是最好的。

#6


1  

Start page code

开始页面代码

<?php
ob_start();
?>

HTML content

...
...

<sapan>Original text</span>

....
...

end page code.

结束页面代码。

<?php
/*    get and delete current buffer      &&  start a new buffer */
if ((($html = ob_get_clean()) !== false) && (ob_start() === true))
{
    echo preg_replace('~<sapan>Original text</span>~i', '<!-- name_of_the_php_file.php -->', $html, 1);
}
?>

Note: Sory, my English not good.

注意:索里,我的英语不好。

#7


1  

Hope to find this plugin useful. use to search in files amd wasting enough time. Also i use What the file plugin as suggested before, it is a great way. But i think combining the String Locator this will have extra fun! String Locator

希望找到这个插件有用。用来搜索文件和浪费足够的时间。另外我使用之前建议的文件插件,这是一个很好的方法。但我认为结合字符串定位器这将带来额外的乐趣!字符串定位器

#8


0  

Not all data is stored in html or php files in Wordpress.

并非所有数据都存储在Wordpress中的html或php文件中。

It may be possible that the string you are looking for is coming from database since wordpress uses database to store variable data.

您正在寻找的字符串可能来自数据库,因为wordpress使用数据库来存储可变数据。

Please search database also

请搜索数据库

#1


15  

Use this plugin "what the file" to find out the php file. Then rest it is to find out a function or something else by CTRL + F in any editor.

使用这个插件“什么文件”来找出php文件。然后休息是在任何编辑器中通过CTRL + F找到一个函数或其他东西。

I want to add one more plugin which is not exactly for this purpose but it is very popular among WordPress developers and it solves this problem very well. The plugin is Query Monitor.

我想添加一个不完全用于此目的的插件,但它在WordPress开发人员中非常受欢迎,它很好地解决了这个问题。该插件是Query Monitor。

#2


5  

Put an echo in your PHP pages to print their name in an HTML comment based on whether a session variable is set. Then set that session variable and enjoy.

在PHP页面中放置一个echo,根据是否设置了会话变量,在HTML注释中打印其名称。然后设置该会话变量并享受。

if(isset($_SESSION['printPageName']) && $_SESSION['printPageName']=='true')
{
   echo '<!-- ' . $_SERVER['PHP_SELF'] . ' -->';
}

The reason I say to use a session variable is so you can create some mechanism to where you can occasionally look at this for debug purposes, but users don't normally encounter it.

我说使用会话变量的原因是你可以创建一些机制,你可以偶尔看看这个用于调试目的,但用户通常不会遇到它。

#3


5  

Unfortunately with wordpress you need to do some digging:

不幸的是,使用wordpress你需要做一些挖掘:

  1. Is it a page/ post / custom post (i.e. you can find the page in the admin section and edit it)
  2. 是页面/帖子/自定义帖子(即您可以在管理部分找到该页面并进行编辑)

  3. If yes - look the the template assigned (posts don't usually have a template select field unless custom code added) and find the matching page template in your theme (page-whatever.php)(it might not be called what you see in the dropdown field, but in its notes it will have the name you see), or if a post you are looking for single.php or if custom post look for single-whatever.php.
  4. 如果是 - 查看分配的模板(帖子通常没有模板选择字段,除非添加了自定义代码)并在主题中找到匹配的页面模板(page-whatever.php)(它可能不会被称为你在下拉字段,但在其注释中它将具有您看到的名称),或者如果您要查找的帖子是single.php,或者如果自定义帖子查找single-whatever.php。

  5. The above is default and will cover 60% of situations. But if you add a plugin and it adds new pages, the page template will be in the plugin and the real fun starts.
  6. 以上是默认情况,将覆盖60%的情况。但是如果您添加插件并添加新页面,则页面模板将位于插件中,并开始真正的乐趣。

  7. If a plugin is developed with user mods in mind, it should have its pages in 1 location or in a functional set folder. Have a look for the above files in these locations if they exist or in the general plugin folders.
  8. 如果开发插件时考虑了用户mod,则应将其页面放在1个位置或功能集文件夹中。如果存在这些位置或在常规插件文件夹中,请查看上述文件。

  9. If still no luck, have a look for add_action('save_post', 'whatever'); there may be code stating return $template , this will prob also have the post type in the function. Look for the path its calling
  10. 如果仍然没有运气,请查看add_action('save_post','what');可能有代码声明返回$ template,这也可能在函数中有post类型。寻找它的召唤之路

  11. Another way to add a page is through a url rewrite (search through the files for rewrite). It will contain a path somewhere to the file (there are a couple of methods of doing this so look them up so you will recognise them).
  12. 添加页面的另一种方法是通过URL重写(搜索文件进行重写)。它将包含文件某处的路径(有几种方法可以执行此操作,因此您可以查看它们以便识别它们)。

If you think you have found the correct template, try a echo to see if it appears on screen. If yes you have found the template, look at what you have follow the includes/ requires to appropiate .php files, you'll find your html somewhere either as html or php code creating html.

如果您认为找到了正确的模板,请尝试使用回声查看它是否出现在屏幕上。如果是,你已经找到了模板,看看你有什么跟随包含/要求合适.php文件,你会发现你的HTML在某处作为html或PHP代码创建HTML。

hopefully you find what you are looking for, but there are no rules really and other methods can exist including htaccess rewrites to point to php file, etc or a functions file creating pages on the fly

This might be a good point to mention if you ever create a entire plugin, store files logically and include from a file controller or plugin file. Store pages in a pages folder so they are easy to find.

如果你创建一个完整的插件,逻辑地存储文件并包含文件控制器或插件文件,这可能是一个很好的点。将页面存储在页面文件夹中,以便于查找。

Good luck!

update: filter to output path on template files

更新:过滤到模板文件的输出路径

add_filter( 'template_include', 'show_path', 99 );

function show_path( $template ) {

            if($template):
                echo $template;
            else:
                echo "template path not found";
            endif;

    return $template;
}

#4


1  

Another possibility would be to copy an id or class from the html. Then search that string through the source code of the WordPress web application to put a breakpoint at every place where the string appears.

另一种可能性是从html中复制id或类。然后通过WordPress Web应用程序的源代码搜索该字符串,在字符串出现的每个位置放置一个断点。

However, the string could be in the database. In that case, this method won't work.

但是,字符串可以在数据库中。在这种情况下,此方法将不起作用。

#5


1  

First tack a backup of whole websiter, suppose /my-website

首先是整个网站服务器的备份,假设/我的网站

1.Right click on element for that you want to find php code

2.Cope CLASS or ID selector of that line

3.Search that CLASS or ID selector in editor inside /my-website folder, for this notepad++ and Dreamweaver editor is best.

1.右键单击元素,找到你要找到的PHP代码2.Cope CLASS或该行的ID选择器3.在编辑器/ my-website文件夹中搜索CLASS或ID选择器,对于这个记事本++和Dreamweaver编辑器是最好的。

#6


1  

Start page code

开始页面代码

<?php
ob_start();
?>

HTML content

...
...

<sapan>Original text</span>

....
...

end page code.

结束页面代码。

<?php
/*    get and delete current buffer      &&  start a new buffer */
if ((($html = ob_get_clean()) !== false) && (ob_start() === true))
{
    echo preg_replace('~<sapan>Original text</span>~i', '<!-- name_of_the_php_file.php -->', $html, 1);
}
?>

Note: Sory, my English not good.

注意:索里,我的英语不好。

#7


1  

Hope to find this plugin useful. use to search in files amd wasting enough time. Also i use What the file plugin as suggested before, it is a great way. But i think combining the String Locator this will have extra fun! String Locator

希望找到这个插件有用。用来搜索文件和浪费足够的时间。另外我使用之前建议的文件插件,这是一个很好的方法。但我认为结合字符串定位器这将带来额外的乐趣!字符串定位器

#8


0  

Not all data is stored in html or php files in Wordpress.

并非所有数据都存储在Wordpress中的html或php文件中。

It may be possible that the string you are looking for is coming from database since wordpress uses database to store variable data.

您正在寻找的字符串可能来自数据库,因为wordpress使用数据库来存储可变数据。

Please search database also

请搜索数据库