WordPress 루트 디렉터리 경로를 검색하시겠습니까?
WordPress CMS에서 루트 디렉터리에 대한 경로를 검색하려면 어떻게 해야 합니까?
wordpress root 디렉토리의 wp-config.php 파일 하단을 보면 다음과 같은 것을 찾을 수 있습니다.
if(!defined('ABSPATH'))정의('ABSPATH', dirname(_FILE__) ./' );
파일의 예에 대해서는, 여기를 참조해 주세요.
http://core.trac.wordpress.org/browser/trunk/wp-config-sample.php
ABSPATH라는 이 상수는 워드프레스 스크립트의 다른 곳에서 사용할 수 있으며 대부분의 경우 워드프레스 루트 디렉토리를 가리킵니다.
메아리치다ABSPATH;// WordPress의 절대 경로를 보여줍니다.
ABSPATH는 wp-config.filename 파일에 정의되어 있는 상수입니다.
주의: 이 답변은 매우 오래된 것으로, Word Press round에서는 그 이후 상황이 바뀌었을 가능성이 있습니다.
플러그인이나 테마에서 WordPress root을 검출해야 할 것 같습니다.FireStats에서 다음 코드를 사용하여 FireStats가 WordPress 플러그인을 설치한 루트 WordPress 디렉토리를 검출합니다.
function fs_get_wp_config_path()
{
$base = dirname(__FILE__);
$path = false;
if (@file_exists(dirname(dirname($base))."/wp-config.php"))
{
$path = dirname(dirname($base))."/wp-config.php";
}
else
if (@file_exists(dirname(dirname(dirname($base)))."/wp-config.php"))
{
$path = dirname(dirname(dirname($base)))."/wp-config.php";
}
else
$path = false;
if ($path != false)
{
$path = str_replace("\\", "/", $path);
}
return $path;
}
이 질문의 URL과 디렉토리에는 2개의 답변이 있습니다.어느 쪽이든 나중에 사용할 수 있도록 두 개의 상수를 정의하는 것이 좋습니다.
define (ROOT_URL, get_site_url() );
define (ROOT_DIR, get_theme_root() );
오래된 질문이지만, 새로운 답이 있습니다.이 1행은 템플릿 내의 경로를 반환합니다. : )
$wp_root_path = str_replace('/wp-content/themes', '', get_theme_root());
Please try this for get the url of root file.
첫 번째 방법:
$path = get_home_path();
print "Path: ".$path;
// Return "Path: /var/www/htdocs/" or
// "Path: /var/www/htdocs/wordpress/" if it is subfolder
두 번째 방법:
And you can also use
"ABSPATH"
this constant is define in wordpress config file.
테마 루트 디렉터리 경로 코드
<?php $root_path = get_home_path(); ?>
print "Path: ".$root_path;
하위 폴더인 경우 "경로: /var/www/htdocs/" 또는 "경로: /var/www/htdocs/wordpress/"를 반환합니다.
테마 루트 경로
$theme_root = get_theme_root();
echo $theme_root
결과: - /home/user/public_html/wp-content/temes
경로를 검색하기 위해 함수를 사용할 수 있습니다.<?php $path = get_home_path(); ?>여기서 이미 말한 것을 반복하고 싶지는 않지만, 한 가지 더 덧붙이고 싶습니다.
WordPress 설치에서는 드물게 Windows 서버를 사용하지만 여전히 가끔 발생하는 경우 경로 출력에 문제가 발생할 수 있습니다.어딘가 "\"가 누락될 수 있으며 이러한 경로를 사용할 경우 오류가 발생합니다.따라서 출력할 때 경로를 반드시 삭제하십시오.
<?php
$path = get_home_path();
$path = wp_normalize_path ($path);
// now $path is ready to be used :)
?>
다음은 다양한 WorPress 솔루션에서 제공하는 디렉토리입니다.필요에 따라 아무나 선택할 수 있습니다.
echo "<br/>".get_home_url(); // https://mysiteurl.com
echo "<br/>".ABSPATH; // /app/
echo "<br/>".get_home_path(); // /app/
echo "<br/>".get_site_url(); // https://mysiteurl.com
echo "<br/>".get_template_directory(); // /app/wp-content/themes/mytheme
echo "<br/>".dirname(__FILE__); // /app/wp-content/plugins/myplugin/includes
echo "<br/>".get_theme_root(); // /app/wp-content/themes
echo "<br/>".plugin_dir_path( __FILE__ ); // /app/wp-content/plugins/myplugin/includes/
echo "<br/>".getcwd(); // /app/wp-admin
이게 효과가 있을 것 같아
function get_wp_installation()
{
$full_path = getcwd();
$ar = explode("wp-", $full_path);
return $ar[0];
}
저는 @Omry Yadan의 솔루션을 좋아하지만, 만약 당신이 디렉토리 트리를 계속 따라 올라가길 원할 경우 루프를 사용하는 것이 개선될 수 있다고 생각합니다.wp-config.php제로살살 살살살다다되고 정상 값, 정상 값)이 됩니다.false를 참조해 주세요.
function wp_get_web_root() {
$base = dirname(__FILE__);
$path = false;
while(!$path && '/' != $base) {
if(@file_exists(dirname($base)).'/wp-config.php') {
$path = dirname($base);
} else {
$base = dirname($base);
}
}
return $path;
}
WordPress 부트스트랩이 로드되어 있는 경우 함수를 사용하여 WordPress 루트 디렉토리로의 경로를 가져올 수 있습니다.
인정된 답변과 @cfx의 솔루션은 마음에 들지만, 좀 더 통합할 수 있습니다.
function base_dir () {
$path = dirname(__FILE__);
while (true) {
if (file_exists($path."/wp-config.php")) {
return $path."/";
}
$path = dirname($path);
}
}
이를 통해 동적으로 생성된 javascript 및 css 파일 등 WordPress에 의해 로드되지 않은 파일에서 기본 디렉토리를 찾을 수 있습니다.
이게 왜 이렇게 복잡해졌지?1개의 명령어:
엔긴스
grep -i 'root' /etc/nginx/sites-enabled/*
아파치
grep -i 'DocumentRoot' /etc/apache2/sites-enabled/*
get_site_url() 함수를 사용하여 워드프레스 사이트의 기본 URL을 가져올 수 있습니다.
상세한 것에 대하여는, http://codex.wordpress.org/Function_Reference/get_site_url 를 참조해 주세요.
루트 디렉토리 패스를 취득하려면 , 다음의 함수를 사용해 주세요.
get_template_directory_uri();
언급URL : https://stackoverflow.com/questions/2354633/retrieve-wordpress-root-directory-path
'programing' 카테고리의 다른 글
| Angular에서 텍스트를 지우는 방법UI 자동 검색 입력 (0) | 2023.03.20 |
|---|---|
| Oracle에서 사용자에게 부여된 권한과 역할을 찾으려면 어떻게 해야 합니까? (0) | 2023.03.20 |
| ng-bind-html의 angularjs 코드 컴파일 방법 (0) | 2023.03.20 |
| angularjs 단위로 이벤트를 트리거한 요소에 접근하는 방법 (0) | 2023.03.20 |
| 한 페이지 어플리케이션이 필요한 이유는 무엇입니까? (0) | 2023.03.20 |