博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
json创创建_创建您自己的创世纪儿童主题
阅读量:2504 次
发布时间:2019-05-11

本文共 7444 字,大约阅读时间需要 24 分钟。

json创创建

There are so many WordPress theme frameworks out there, that it can be tough to choose which one is right for you. How do you know which one is a quality theme that will help promote your content, and which ones will hold it back? One of the most popular frameworks is the Genesis Theme framework. Let’s take a look at the Genesis Framework, and what you might expect when creating a Genesis child theme.

那里有许多WordPress主题框架,因此很难选择最适合您的主题框架。 您如何知道哪一个是有助于推广您的内容的优质主题,哪些会阻碍它的推广? 最受欢迎的框架之一是Genesis Theme框架。 让我们看一下Genesis框架,以及创建Genesis子主题时的期望。

WordPress and Genesis

The Genesis Framework by is designed to be used with child themes. Most WordPress themes are, but Genesis doesn’t add or require anything special that you need to import or bring into your child theme.

的Genesis Framework设计用于子主题。 大多数WordPress主题都是,但是Genesis不需要添加或要求导入或引入子主题所需的任何特殊内容。

档案结构 (File Structure)

The Child theme development process begins with a new directory. Go to the themes section of your development area and create a new folder under themes. If you’re using the default Genesis theme, or you’re using a specific theme, you’ll want to choose the name of the theme and add “-child” to the folder name. You can name it whatever you’d like, but if you’re working with a specific theme, I always recommend naming it the child of the theme you’re working on, to cut down on confusion. You’ll want to copy the style.css and the functions.php file into the empty child folder.

Child主题开发过程始于新目录。 转到开发区域的主题部分,然后在themes下创建一个新文件夹。 如果您使用默认的Genesis主题,或使用特定主题,则需要选择主题名称,然后在文件夹名称中添加“ -child”。 您可以随意命名,但是如果您使用的是特定主题,我总是建议您将其命名为您正在处理的主题的子类,以减少混乱。 您需要将style.cssfunctions.php文件复制到空的子文件夹中。

样式表 (Stylesheet)

You can leave all of the CSS in the stylesheet, or you can choose to remove it. Since the child theme overrides, or adds to the parent theme, you don’t really need it twice. In the CSS file, you’ll want to add a few lines of text to provide information about your theme. You’ll want to include:

您可以将所有CSS保留在样式表中,也可以选择删除它。 由于子主题会覆盖或添加到父主题,因此您实际上并不需要两次。 在CSS文件中,您需要添加几行文字以提供有关主题的信息。 您将要包括:

  • Theme name: The name of the child theme goes here.

    主题名称:子主题的名称位于此处。
  • Theme URI: This is a site where they can view a demo or find more information about the child theme.

    主题URI:这是一个站点,他们可以在其中查看演示或找到有关子主题的更多信息。
  • Description: Describe your child theme and it’s qualities.

    描述:描述您的孩子主题及其品质。
  • Author: Your name to give yourself credit.

    作者:您的名字值得称赞。
  • Author URI: Your personal website address goes here.

    作者URI:您的个人网站地址在此处。
  • Version: If you plan on refining and creating future versions. Start with 1.0.

    版本:如果您计划完善和创建将来的版本。 从1.0开始。
  • Tags: These tags are keywords that will help people find your theme. This could be colors, features, etc.

    标签:这些标签是可以帮助人们找到您主题的关键字。 这可能是颜色,特征等。
  • Template: The name matching the parent Genesis theme (case sensitive).

    模板:与父创世记主题匹配的名称(区分大小写)。

导入CSS (Importing CSS)

You can import the CSS styles from the parent Genesis theme, but you should only do this if you want all of the CSS from the Parent theme. If you’re looking at just the Default Genesis theme structure without any styles, you may not want to import anything at all, which is fine. You may want to start from scratch and build your own distinct look. Importing all of the existing styles and having to sift through them and modify them may only complicate things.

您可以从父Genesis主题导入CSS样式,但是仅当您希望从Parent主题获取所有CSS时才应该这样做。 如果仅查看没有任何样式的Default Genesis主题结构,则可能根本不希望导入任何内容,这很好。 您可能需要从头开始,并建立自己的独特外观。 导入所有现有样式并不得不对其进行筛选和修改可能只会使事情复杂化。

If you want to bring in the parent theme style, a good way of doing so is to enqueue in your functions.php file using the following script:

如果要引入父主题样式,一种好的方法是使用以下脚本将您的functions.php文件加入队列:

add_action( 'wp_enqueue_scripts', 'my_child_theme_scripts' );function my_child_theme_scripts() {    wp_enqueue_style( 'parent-theme-css', get_template_directory_uri() . '/style.css' );}

functions.php (functions.php)

This file is essential to your child theme for adding features and functionality. This is where you’ll add all of your hooks and filters, which Genesis makes use of extensively. First, we need to activate the core Genesis functions in our child theme.

此文件对于添加功能部件的子主题至关重要。 在这里,您将添加所有的钩子和过滤器,Genesis会大量使用它。 首先,我们需要激活子主题中的核心Genesis功能。

儿童主题如何运作 (How the Child Theme Works)

If you try to activate the child theme, you’ll notice that, unlike the other themes, your child theme’s image is blank. This may scare you a bit, but it’s an easy fix. Open up your graphics program. It could be Illustrator, Fireworks, Photoshop, or even free image editing software, just as long as it can produce a PNG file. Create a document that is 300px x 225px and drop in an image or a graphic that tells the user what child theme it is. Save it to your child theme folder as screenshot.png, and now it will show up.

如果您尝试激活子主题,则会发现与其他主题不同,子主题的图像为空白。 这可能会吓到您,但这很容易解决。 打开您的图形程序。 只要可以生成PNG文件,它就可以是Illustrator,Fireworks,Photoshop,甚至是免费的图像编辑软件。 创建一个300px x 225px的文档,并放下图片或图形,以告诉用户它是什么子主题。 将其另存为子主题文件夹screenshot.png ,现在它将显示出来。

To enable a child theme, you should install/activate the parent theme first. This is an essential step. Once you’ve done this, you can select your child theme and activate it. Now you’re all set, with your custom look and custom functionality.

要启用子主题,应首先安装/激活父主题。 这是必不可少的步骤。 完成此操作后,您可以选择您的子主题并激活它。 现在,您已具备自定义外观和自定义功能的所有设置。

加入创世纪 (Adding to Genesis)

To add functionality, we’ll be adding to the functions.php file we created in our child theme folder. There are two important parts of a function in WordPress, which are the hook and the filter.

要添加功能,我们将添加到在子主题文件夹中创建的functions.php文件中。 WordPress中函数的两个重要部分是hookfilter

挂钩和过滤器 (Hooks & Filters)

The hook is chunk of code that we call to in our functions. It’s a piece of code built into Genesis that we ‘hook’ into, which is where the name comes from.

钩子是我们在函数中调用的代码块。 这是Genesis中内置的一段代码,我们可以将其“钩住”,这就是该名称的来源。

Lets take a common example, which is the excerpt length of your blog page. I can’t stand the default number of words, which is 55. I think it’s too long. You’ll need to hook into the excerpt length and change it, and add it as a filter in your child theme. The code should look something like this.

让我们举一个常见的例子,它是您的博客页面的摘录长度。 我无法忍受默认的单词数55。我认为它太长了。 您需要插入摘录长度并进行更改,然后将其添加为子主题中的过滤器。 该代码应如下所示。

function the_excerpt_length( $length ) {$length = '25'; return $length; } add_filter( 'excerpt_length', 'the_excerpt_length' );

The code above creates a function called “the_excerpt_length” and the value in the parenthesis is set to an amount that you specify. The code is told to return that as the word length of your excerpt. Now, when you’re working on a page, such as the index.php or the archive.php, instead of the_content, you can substitute it for the_excerpt, cutting the words down to 25 at most. This is a useful example, but there’s much more that we can do – as we’ll see in future articles.

上面的代码创建了一个名为“ the_excerpt_length”的函数,并且括号中的值设置为您指定的数量。 告诉代码将其作为摘录的单词长度返回。 现在,当您在处理诸如index.php或archive.php之类的页面时,可以用the_excerpt代替the_content,最多将单词减少到25个。 这是一个有用的示例,但是我们可以做更多的事情-我们将在以后的文章中看到。

结论 (Conclusion)

Setting up your own Genesis child theme sounds intimidating, but it’s easier than it looks. You can create your own custom child theme quickly with just two necessary files. With hooks and filters, you can customize the functionality of your theme, without the worry of losing your changes when you update the parent theme.

设置自己的Genesis子主题听起来很吓人,但是比看起来容易。 您只需两个必要的文件,即可快速创建自己的自定义子主题。 使用挂钩和过滤器,您可以自定义主题的功能,而不必担心在更新父主题时丢失所做的更改。

翻译自:

json创创建

转载地址:http://ckrgb.baihongyu.com/

你可能感兴趣的文章
Notes on <High Performance MySQL> -- Ch3: Schema Optimization and Indexing
查看>>
Alpha冲刺(10/10)
查看>>
数组Array的API2
查看>>
为什么 Redis 重启后没有正确恢复之前的内存数据
查看>>
No qualifying bean of type available问题修复
查看>>
第四周助教心得体会
查看>>
spfile
查看>>
Team Foundation Service更新:改善了导航和项目状态速查功能
查看>>
WordPress资源站点推荐
查看>>
Python性能鸡汤
查看>>
android Manifest.xml选项
查看>>
Cookie/Session机制具体解释
查看>>
ATMEGA16 IOport相关汇总
查看>>
有意思的cmd命令
查看>>
js正則表達式语法
查看>>
Git学习系列-Git基本概念
查看>>
c#多个程序集使用app.config 的解决办法
查看>>
Linux+Apache+PHP+MySQL服务器环境配置(CentOS篇)
查看>>
Linux下获取本机IP地址的代码
查看>>
(C#)调用Webservice,提示远程服务器返回错误(500)内部服务器错误
查看>>