制作Wordpress主题时要注意什么

发布于 2024-08-14 01:45:18 字数 474 浏览 6 评论 0原文

我制作 WordPress 主题已经有一两年了,在尝试使我的主题与其设置、插件等尽可能兼容和灵活时,我不断遇到需要记住的事情。

是否有一个资源可以保存清单WordPress 主题的所有“不要忘记”?在构建 WordPress 主题时,您会牢记哪些事项?

示例:

  • 检查作者/管理员是否禁用了特定帖子的评论。
  • 请记住在 标记末尾调用 wp_head()
  • 请记住在 标记末尾调用 wp_footer()
  • 使用 bloginfo() 变量而不是为字符集、html 类型、描述等设置静态值,以便管理员可以在站点设置中修改此类内容。
  • 在从插件调用函数之前使用 function_exists() ,这样如果未安装该插件,它就会正常失败。

I have been making Wordpress themes for a year or two and keep running into things I need to keep in mind when trying to make my themes as compatible and flexible as possible with their settings, plugins, etc.

Is there a resource that keeps a checklist of all the "don't forgets" of Wordpress theming? What things do you try to keep in mind when building your Wordpress themes?

Examples:

  • Checking if the author/admin has disabled comments for a particular post.
  • Remembering to call wp_head() at the end of the <head> tag.
  • Remembering to call wp_footer() at the end of the <body> tag.
  • Using bloginfo() variables instead of setting static values for charset, html type, description, etc. so admins can modify such things in the site settings.
  • Using function_exists() before calling a function from a plugin so it fails gracefully if that plugin isn't installed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

友欢 2024-08-21 01:45:18

WordPress 文档有一个有趣的主题,正好解决了您的问题:它称为设计公开发布的主题。还有主题开发一般指南模板文章也很棒。

我不知道其他官方资源,但在这三个指南中添加更多信息会很有趣。我对您的问题中可能有的其他一些答案感兴趣,以补充它们。

我已经习惯了 Wordpress,以至于您编写的示例在我开发时会自动流动,因为使用输出域信息(例如 bloginfo() )的函数而不是静态值是一个很好的做法任何网络开发。

Wordpress documentation has an interesting topic addressing exactly what you're asking: it's called Designing Themes For Public Release. There's also Theme Development General Guidelines. The Templates article is wonderful too.

I don't know other official resources, but it would be interesting to add more info into those three guides. I'm interested in some other answers we may have in your question to complement them.

I'm so used to Wordpress that the examples you wrote just flows automatically when I'm developing, since using a function that outputs domain information such asbloginfo() instead of static values is a good practice in any web development.

指尖凝香 2024-08-21 01:45:18

主题开发清单更多地取决于主题的目标受众。如果它超出了基本博客并转向 WordPress-as-CMS 领域,您需要研究:

  • 自定义小部件和动态侧边栏,以使功能更加便携和
  • 对自定义字段的灵活支持,或者像 MagicFields 这样的插件在中实现前者 全新方式
  • 使用 CSS 框架为网站的不同级别路由和创建自定义模板(例如:子类别由 Category-x.php 处理)的
  • ,因此无论谁修改样式都有更高的机会更好地理解它;确保包含 ie 支持
  • 自定义 wp-admin 部分及其自己的菜单、页面等;如果您的主题具有自定义功能,用户可以
  • 使用 wp_scripts 和 wp_styles 类和函数来添加样式和脚本来进一步自定义, 这一点尤其必要;这对于 javascript 尤其重要,因为它可以防止重复包含并与依赖脚本一起使用(在 jQ 脚本之前加载 jQuery)
  • 确保主题的设计不会像 WordPress
  • 编写主题类的其他内容一样看起来很无聊;除非您计划支持 PHP4,否则使用 PHP5 类和对象可以让您的生活更轻松,因为功能继承和无命名冲突。看看 CodeIgniter 和他们的单例模式; 它使模板文件中的自定义全局变量更容易管理
  • 如果您(并且应该)使您的主题更高级并且更像插件,那么 ,然后知道如何使用 WP_Cache 和 WP_Rewrite 对象,以便您的自定义查询 $ wpdb(是的,您需要偶尔执行这些操作才能获得某些自定义功能)的成本较低,并且您的新页面(如果您重写网址)可以正确路由,并且可以正确动态生成链接。
  • 最后也是最重要的是,尽最大努力将表示(html)与逻辑(php)分开;当您开始运行自定义 WP 循环时,这会变得很困难,一个好的解决方案是前面提到的主题类。

A theme development checklist depends more on the intended audience for your theme. If it's beyond the basic blog and moving towards WordPress-as-CMS territory, you'd want to look into:

  • custom widgets and dynamic sidebars to make features more portable and flexible
  • support for custom fields, or plugins like MagicFields that implement the former in a whole new way
  • routing and creating custom templates for different levels of the site (ex: sub-categories get handled by category-x.php)
  • using a css framework so whoever gets to modify the styles has a higher chance of understanding it better; make sure to include ie support
  • custom wp-admin section with its own menus, pages, etc.; this is especially necessary if your theme has custom functionality that can be further customized by the user
  • use the wp_scripts and wp_styles classes and functions to add styles and scripts; this is especially important for javascript, as it prevents duplicate includes and works with dependency scripts (loads jQuery before your jQ script)
  • make sure the design of the theme doesn't look boring like everything else out there for WordPress
  • write a theme class; unless you're planning to support PHP4, use PHP5 classes and objects to make your life easier, in terms of feature inheritance and no naming conflicts. look at CodeIgniter and their singleton pattern; it makes custom globals inside template files a lot easier to manage
  • if you are (and you should be) making your theme a lot more advanced and more like a plugin, then know how to use the WP_Cache and WP_Rewrite objects so your custom queries with $wpdb (yes, you'll need to do these once in a while to get certain custom functionality) are less expensive, and your new pages (if you're rewriting urls) route correctly and your links are correctly dynamically generated, respectively.
  • last and most importantly, try your hardest to separate presentation (html) from logic (php); this gets hard as you start running custom WP loops and a good solution is the aforementioned theme class.
樱花细雨 2024-08-21 01:45:18

我们公司还开发了很多各种WordPress和WordPress。 WordPress MU 主题 &我们还没有找到任何“官方”资源,但我们所做的一件事是创建一组基本的模板文件,可以用作“标准”设置,以加快我们的开发过程。

然后,每当需要开发新主题时,我们基本上都会将这组默认模板文件复制/粘贴到 WordPress 安装上的新主题文件夹中。对于我们来说,默认设置中包含的项目是预先填充的 header.php、footer.php、index.php、home.php、single.php、functions.php、comments.php、/images (dir)、 /functions (dir)、style.css、/css (dir)、/scripts (dir) 和一些其他项目。

然后我们还使用 Yahoo Grids 或 Google Blueprint css 框架来加速 css 工作。我还遗漏了一些其他项目/文件,但应该能让您大致了解什么最适合我们商店。

Our firm also develops a lot of various WordPress & WordPress MU themes & we haven't found any "Official" resources, but one thing we've done is create a basic set of template files can can be used as a "standard" setup in order to speed up our development process.

Then, whenever a new theme needs to be developed, we basically copy / paste this default set of template files into a new theme folder on the WordPress install. For us, items we've included in this default setup are pre-populated header.php, footer.php, index.php, home.php, single.php, functions.php, comments.php, /images (dir), /functions (dir), style.css, /css (dir), /scripts (dir), and a handfull of other items.

Then we've also used Yahoo Grids or Google Blueprint css frames works to also speed up the css work. There's a few other items / files I'm leaving out, but should give you a general idea of what works best for us in our shop.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文