【问题标题】:Wordpress child theme and files in foldersWordpress 子主题和文件夹中的文件
【发布时间】:2021-03-09 00:03:40
【问题描述】:

我有一个问题 - 我的 footer.php 文件包含这样一个函数:

<?php adios_footer_template(adios_get_opt('footer-template')); ?>

我认为代码正在调用一些内部函数。当我深入研究主题代码时,我发现这个函数有以下代码:

function adios_footer_template($layout) {
    if(class_exists('ReduxFramework') && !adios_get_opt('footer-enable-switch')) { return; }
    switch ($layout) {
      case 'footer-style5':
        get_template_part('templates/footer/footer-style5');
        break;
      case 'footer-style4':
        get_template_part('templates/footer/footer-style4');
        break;
      case 'footer-style3':
        get_template_part('templates/footer/footer-style3');
        break;
      case 'alternative':
        get_template_part('templates/footer/alternative');
        break;
      case 'default':
      default:
        get_template_part('templates/footer/default');
        break;
    }
  }

我想要实现的是或通过子主题添加一个案例并使其工作,或者至少有一个选项来编辑这些页脚样式。我尝试将整个模板/页脚目录复制到子主题中,然后添加更改(没有成功;在前端没有任何改变)。然后我什至尝试重命名该函数并将其粘贴到我自己的functions.php中,但同样 - 没有改变任何东西。它甚至可行吗?

【问题讨论】:

  • 我显然知道,但你检查过 adios_get_opt("footer-enable-switch is enabled") 吗?
  • 是的,我已经检查过:)

标签: php wordpress function themes


【解决方案1】:

您是否尝试过在您的子主题中完全重命名该函数?

function adios_child_footer_template($layout) {
  # Line about adios_get_opt removed
  switch ($layout) {
    case 'footer-style5':
      get_template_part('templates/footer/footer-style5');
      break;
    case 'footer-style4':
      get_template_part('templates/footer/footer-style4');
      break;
    case 'footer-style3':
      get_template_part('templates/footer/footer-style3');
      break;
    case 'alternative':
      get_template_part('templates/footer/alternative');
      break;
    case 'default':
    default:
      get_template_part('templates/footer/default');
      break;
  }
}

然后这样称呼它:

<?php adios_child_footer_template('alternative'); ?>

我的猜测是 adios_get_opt 正在选择一个您没有预料到的开关盒。当然,这只是一个捷径。更好的选择是找到一种方法来正确扩展函数并将您的页脚样式添加到 adios_get_opt

【讨论】:

  • 我做到了——什么也没发生:O
猜你喜欢
  • 1970-01-01
  • 2015-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多