하위 도메인이 "m"인지 확인하고 다른 템플릿을 표시하고 싶습니다. Wordpress API에서 내가 찾고있는 것을 찾지 못했습니다.Wordpress 플러그인의 템플릿 변경
if ($subdomain == "m") { ... } else { ... }
하위 도메인이 "m"인지 확인하고 다른 템플릿을 표시하고 싶습니다. Wordpress API에서 내가 찾고있는 것을 찾지 못했습니다.Wordpress 플러그인의 템플릿 변경
if ($subdomain == "m") { ... } else { ... }
는이 작업을 수행하기 위해 PHP의 parse_url() 기능을 사용할 수 있습니다 다른 _template 필터 중 하나가로드되는 템플릿을 변경합니다.
<?php
/**
* Plugin Name: Theme swithwer
* Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
* Description: Custom theme switcher
* Version: 0.1
* Author: XXX XXX
* Author URI: http://URI_Of_The_Plugin_Author
* License: A "Slug" license name e.g. GPL2
*/
add_filter('stylesheet', 'switch_ma_theme');
add_filter('template', 'switch_ma_theme');
function switch_ma_theme()
{
global $wpdb;
// condition to test ad theme to load
if ($_SERVER['HTTP_HOST'] == 'blog.xxxx.xxx')
return 'xxxthemexxx';
// else default theme
$theme = $wpdb->get_results("SELECT option_value FROM wp_options where option_name='template' ");
$theme = array_pop($theme);
return $theme->option_value;
// Return the theme directory name
}
그런 다음 관리자에 가서 당신을 위해 새로운 플러그인을보고 수 :
like for 'wp_switch_template ('theme_name ');'= 3 – user1139252
그건 내가 아는 한 존재하지 않는다. 위의 IF 문을 사용하여 머리글에 다른 스타일 시트를로드하거나보다 복잡하면 WP의 네트워크/다중 사이트 기능을 사용하는 것이 좋습니다. – Justin
당신은 'template_redirect'필터를 사용한다, 또는 : 당신은 당신의 자신의 if 문을 추가 할 수 있습니다, 그리고
$parsed = parse_url($_SERVER['HTTP_HOST']);
$host = explode('.', $parsedUrl['host']);
$subdomain = $host[0];
:
나는 하나의 스크립트로 당신에게 자신의 플러그인을 작성하고 WP-내용에 넣어 이런 코드/플러그인을하는 것이 좋습니다 그것
활성 HTTP 요청에 다른 템플릿을 일시적으로 사용하려면 [template_include' 필터] (https://codex.wordpress.org/Plugin_API/Filter_Reference/template_include)가 필요합니다. 이후의 모든 요청에 사용되도록 변경 사항을 유지 *하고 싶다면'wp_options' 테이블에서'template'과'stylesheet' 옵션을 직접 업데이트해야합니다. ['template'와'stylesheet'는 동일하지 않습니다.] (https://wordpress.stackexchange.com/a/40220/10388). – rinogo
[switch_theme()] (https://developer.wordpress.org/reference/functions/switch_theme/)도 참조하십시오. 다양한 옵션이 많이 있습니다. 나는 너희들과 함께 이것을 알아 낸거야! :) – rinogo