Marcus主题首页无法使用自定义sql查询如何调取后台设置的HTML内容


Define页面默认不执行php,本主题的/includes/languages/english/html_includes/marcus/define_homepage_v*都是。所以首页想调用一些在后台自定义的HTML代码,只能通过如下方法:
1、在/includes/languages/english/html_includes下新建define_home_content_1.php、define_home_content_2.php ……等多个空白文件,然后在后台Tools -> Define Pages Editor里可以找到它们
2、define_homepage_v里,在想放置指定HTML的地方设置占位符
3、在/includes/templates/marcus/common/tpl_main_page里,第235行($body_code = pzen_marcus_home_shortcode($homepage_html);)之后增加以下代码

$extra_home_defines = array(
    '<!--HOME_CONTENT_1-->' => 'home_content_1.php',
    '<!--HOME_CONTENT_2-->' => 'home_content_2.php',
    '<!--HOME_CONTENT_3-->' => 'home_content_3.php'
);
foreach ($extra_home_defines as $marker => $def) {
    $path = zen_get_file_directory(
        DIR_WS_LANGUAGES . $_SESSION['language'] . '/html_includes/',
        'define_' . $def,
        'false'
    );
    if (is_file($path)) {
        $html = pzen_marcus_home_shortcode(file_get_contents($path));

        if (strpos($body_code, $marker) !== false) {
            // 如果找到占位符 → 替换
            $body_code = str_replace($marker, $html, $body_code);
        } else {
            // 没找到占位符 → 直接追加到尾部
            //$body_code .= $html;
        }
    }
}

案例应用:激光的金币站

声明:Windows 10 专业版|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - Marcus主题首页无法使用自定义sql查询如何调取后台设置的HTML内容


Carpe Diem and Do what I like