search
HomeBackend DevelopmentPHP Tutorial不太懂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的范畴,你去他们官方论坛求助会比在这里问效果好很多。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools