不太懂php,问一个关于wordpress的问题
这句代码报错的
页面上报错:
Fatal error: Call to undefined function wp_list_cats() in D:\phpnow\htdocs\mulan\wp-content\themes\muse\blog.php on line 48
意思好象是wp_list_pages()函数未定义。
想要自己用html css javascript写模板
index.php链接到blog.php时,在blog.php中调用就报错了
但是如果直接在index.php中调用就很正常,index.php和blog.php在同一个目录下,不明白是为什么。
回复讨论(解决方案)
index.php
有引入那个函数
而blog.php没有
你把index.php里面的一些require也加到blog.php试试
index.php
有引入那个函数
而blog.php没有
你把index.php里面的一些require也加到blog.php试试
好像没有引入什么的
PHP怎么引入函数啊
而且 wordpress中的wp_list_cats函数在什么地方 ?
总之,有人家的东西,就得守人家的规矩
总之,有人家的东西,就得守人家的规矩
可是应该怎么做?
解决了
在要调用函数的文件的前面加上 或者
路径由自己定 不过我有几个疑问
1. require 和 require_once 有什么区别 都是调用函数的 语法也是一样的 使用起来页面上没有看出区别。
2. php中怎么获得上一级目录,用绝对路径不是很理想,../ 好像不对哦
3. 调用wp_list_cats()函数以后,会出现 “页面”??“实例页面”这样的链接,怎么去掉
4. wp_list_cats()函数的源代码在哪里?
require_once就是php的引用啊
好比c的include
http://www.csharpwin.com/dotnetspace/5716r9253.shtml lz可以看看这个 require_once() 函数会先检查目标档案的内容是不是在之前就已经导入过了,如果是的话,便不会再次重复导入同样的内容。
嘿 .. 谢谢大家 .. 明白的差不多了 ..
php怎么获得上一级目录啊,比如要在D:/phpnow/htdocs/mulan/wp-content/themes/my/index.php文件中表示D:/phpnow/htdocs/mulan/wp-blog-header.php文件
../写是可以的,只不过这个相对路径是根据你当前运行的脚本的相对路径。如果你确认要引用的文件在上一层目录,那么很可能实际执行的那个页面不是你预期的那个。
举个例子:
目录结构:
test/1/a.php
test/2/b.php
test/2/c.php
a.php
-----------
require '../2/c.php';
b.php
-----------
echo $a;
c.php
-----------
$a = 123;
运行http://localhost/b.php
你可能会认为没错,因为c.php相对于a.php来说确实是../2/c.php这样的路径。不过很可惜,你实际执行的是b.php,那么当前脚本的目录和c.php处于相同目录。所以a.php中要引用c.php应该写为:
./c.php或c.php
这就是相对路径的坏处,当有文件相互引用时,相对路径会让逻辑看起来一塌糊涂。所以实际中我们都喜欢用相对路径。但直接写磁盘物理路径也不好,等你项目迁移了,那物理路径也许会变。
最好的写法是基于web根目录的绝对路径。
也就是以/开头,这个/就是你的网站根目录,然后向下写绝对路径。
或者用realpath和dirname来动态返回物理路径再拼凑出绝对路径。
上面有句话错了:
所以实际中我们都喜欢用绝对路径。或者用realpath、dirname等等动态获取相对路径。
关于require 和 require_once 有什么区别,具体区别你可以自己搜一下,到处都是说这个的,我就不阐述了。不过要告诉你的是实际项目中最好用require和include,不要用带once的那个,带once的只是让php本身避免一些重复包含的错误,但这会大大降低效率。而这些问题如果程序猿本身素质够高的话都是可以避免的,没必要让php降低性能去做这件事。
至于3、4两个问题,都属于wordpress系统本身的问题,严格来讲不属于php的范畴,你去他们官方论坛求助会比在这里问效果好很多。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
