如何修复 wordpress 自定义主题以使用插件? [英] How do I fix a wordpress custom theme to work with plugins?

查看:35
本文介绍了如何修复 wordpress 自定义主题以使用插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次尝试编写自定义 wordpress 主题,我快完成了.任何东西都有一些错误,但我尝试了几种不同的方法来修复它们,但都没有成功.

This is my first attempt at coding a custom wordpress theme and I'm almost there. There are a few bugs as there are with anything, but I've tried a few different options at fixing them but with no success.

链接是 www.studiosimplicit.com/wp.

The link is www.studiosimplicit.com/wp.

我的第一个问题是事件页面 (www.studiosimplicit.com/wp/events) 上的 nivo 滑块.最初我遇到了插件本身的问题,图像被堆叠在一起.为了纠正这个问题,我手动输入了代码来调用 nivo .js 文件,这似乎解决了这个问题.但是现在加载图像在那里,但图像没有加载.

My first issue is with nivo slider on the events page (Www.studiosimplicit.com/wp/events). Initially I was having an issue with the plugin itself, where the images were being stacked on top of each other. To correct this I manually put in code to call in the nivo .js files, and that seemed to fix that issue. But now the loading image is there but the images don't load.

我已经检查了图像的 URL,这不是问题.我还启用了后缩略图"功能(如 nivoslider 网站上建议的那样作为我的问题的常见解决方案),但这似乎并没有解决它.当我切换到默认主题时,滑块可以正常工作,这毫无价值.当我激活我的自定义主题时,它会中断.

I've checked the URL of the images and that's not the issue. I also enabled the "post-thumbnails" feature (as suggested on the nivoslider website as a common fix to my issue) but that doesn't appear to have fixed it. It's worth nothing that when I switch to a default theme, the slider works fine. It's when I activate my custom theme that it breaks.

我的第二个问题是一个插件,它应该设置全屏背景图像,自动调整大小以适应浏览器宽度.同样,该插件在我切换到默认主题时可以工作,但在我切换到自定义主题时会中断.

My second issue is with a plugin that is supposed to set a full screen background image, automatically resized to fit browser width. Again, the plugin works when I switch to a default theme but it breaks when I switch to my custom theme.

请帮忙!

推荐答案

从表面上看,您的自定义主题缺少允许插件更改/输出其代码的通用挂钩.

By the sounds of it, your custom theme is missing the common hooks that allow plugins to alter/output their code.

举一个简单的例子,每个主题都应该调用 wp_head()输出页面的 部分.这允许插件挂钩"到您的 ,例如,输出代码以加载其 Javascript.

To take a simple example, every theme should have a call to wp_head() somewhere in the <head> section of the output page. This allows a plugin to "hook" into your <head>, and for example, output code to load its Javascript.

这是一个真实的例子.WordPress 211 主题在其 header.php 文件(传统上是输出任何页面的 <head> 部分的主题的一部分)中有这个:

Here's a real-life example. The WordPress Twentyeleven theme has this in its header.php file (traditionally the part of a theme that outputs the <head> section of any page):

... other <head> stuff
    wp_head();
?>  
</head>

WP Nivo Slider 在调用 wp_enqueue_script 时使用此代码例如,在它的 wp-nivo-slider.php 文件中.在幕后,wp_enqueue_script 使用 211 主题中的 wp_head() 钩子输出请求的 Javascript 包含在 部分(通过一个稍微迂回的路线,默认情况下在 wp_print_head_scripts 结束.)

The WP Nivo Slider uses this code when it calls wp_enqueue_script, for example, in its wp-nivo-slider.php file. Behind the scenes, wp_enqueue_script uses the wp_head() hook in the Twentyeleven theme to output the requested Javascript include in the <head> section (via a slightly circuitous route that ends up in wp_print_head_scripts by default.)

因此,基本上,如果插件适用于提供的主题,但不适用于您的自定义主题,则您的任务是找到插件尝试使用的主题中缺少的挂钩.

So, basically, if a plugin works with a provided theme, but doesn't work with your custom theme, your task is to find the hooks that are missing from your theme that the plugin is trying to use.

如果您查看 WordPress 主题开发文档,您会发现主题应包含的钩子列表在插件 API 挂钩"部分下.这些具体是:

If you check the WordPress Theme Development documentation you'll find a list of hooks that themes should include under the section "Plugin API hooks". These are, specifically:

  • wp_head
  • wp_footer
  • wp_meta
  • comment_form

对于大多数插件来说,重要的是 wp_headwp_footer.这是大多数 Javascript 被包含的地方,无论是在头部还是在页脚部分(就在 结束标记之前.)

The important ones for most plugins will be wp_head and wp_footer. This is where most Javascript gets included, either in the head or the footer section (just before the closing <body> tag.)

大多数插件,如 Javascript 滑块、图片库等,只会在网站的 <head> 或页脚部分添加一两个新脚本,并且可能包含 CSS 文件以设置样式它们的内容,同样在 部分,所以这两个通常是他们唯一需要的钩子.

Most plugins like Javascript sliders, image galleries, etc., will simply add a new script or two in the <head> or footer section of the website, and perhaps include CSS files to style their content, again in the <head> section, so those two are generally the only hooks they need.

因此,我最初的建议是确保您的自定义主题在其 <head> 部分的末尾包含对 wp_head() 的调用(复制代码)以及对 wp_footer() 的调用,就在结束 </body> 标记之前.这很有可能使大多数基于 Javascript 的插件都能正常工作.

So, my initial advice would be to make sure your custom theme includes a call to wp_head() at the end of its <head> section (copy the code from that working theme you've got) and also a call to wp_footer(), just before the closing </body> tag. The chances are good that that'll get most Javascript-based plugins working.

这篇关于如何修复 wordpress 自定义主题以使用插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆