具有 Ailurotech 公司背书,获得项目经验,适合阿德莱德
Wordpress.com vs Wordpress.org
为什么学 Wordpress
学习难点
WordPress database migration and file management are crucial for various tasks like moving your site to a new host, staging development changes, or backing up your site.
Note: This is an easy safe way of updating the live site for the client.
WordPress consists of two main components: the files and the database. The files include WordPress core, themes, plugins, and uploads, while the database stores your site's content and settings.
wp_posts
table.wp_comments
table.wp_users
table.wp_options
.Adjust the DB_NAME
, DB_USER
, DB_PASSWORD
, and DB_HOST
values in your wp-config.php
file to match the new database details.
If your domain remains the same, URLs in the database should be fine. However, if the domain changes, you’ll need to update URLs in the database. This can be done with:
UPDATE wp_options SET option_value = replace(option_value, '<http://www.oldurl>', '<http://www.newurl>') WHERE option_name = 'home' OR option_name = 'siteurl';
After migrating, go to Settings > Permalinks in the WordPress dashboard and simply click "Save Changes" to reset the permalink structure.
docker-compose.yml
.docker-compose.yml
file in a text editor and add the following content.docker-compose.yml
file.http://localhost:8000
.This command stops and removes the containers created by docker-compose up
. The db_data
volume persists even after the containers are removed, ensuring your database data is saved across container restarts.
db_data
volume stores your database content. If you want to start fresh, you can delete this volume by running docker volume rm <volume_name>
.WordPress is a powerful content management system (CMS) written in PHP that allows you to create and manage websites easily. It's known for its flexibility, extensibility through plugins and themes, and a large supportive community.
Understanding the WordPress folder structure is essential for development and debugging. Here’s a brief overview:
wp-admin
: Contains administrative files. This directory has the files necessary to create the WordPress dashboard.wp-content
: The heart of your WordPress site from a developer's perspective. It includes:wp-content/themes
, this is where WordPress themes are stored. Each theme has its own directory.wp-content/plugins
, here you'll find the plugins that add functionality to your WordPress site.wp-content/uploads
. This includes images, videos, etc., uploaded through the WordPress media uploader.wp-includes
: Contains most of WordPress core software, including libraries and functions used by themes and plugins.wp-config.php
(crucial for setting up your WordPress installation's configuration), wp-load.php
(boots WordPress), and several others essential for WordPress to run.PHP is a server-side scripting language designed for web development. WordPress is built on PHP, making it crucial for WordPress development.
<?php
and ?>
. Everything outside these tags is treated as HTML.//
for single-line comments and /* */
for multi-line comments.$
sign followed by the name of the variable. For example, $text = "Hello, World!";
.get_header()
: Includes the header.php file.wp_footer()
: Hooks into the footer. Always include this before the closing </body>
tag in your theme to ensure scripts and admin bar are correctly output.have_posts()
and the_post()
: Used in a loop to display posts.get_template_directory_uri()
: Retrieves the URL of the current theme's directory.Debugging is an essential part of development. To enable debugging in WordPress:
wp-config.php
.define('WP_DEBUG', false);
. Change false
to true
.define('WP_DEBUG_LOG', true);
.jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, and animation much simpler with an easy-to-use API that works across a multitude of browsers.
$(selector).action()
, where $(selector)
is used to find HTML elements, and .action()
is the action to be performed on the element(s).A typical web project involves integrating these technologies to create a complete, functional website.
By mastering these technologies, you can develop rich, interactive web applications. Practice is key, so consider building small projects to apply what you've learned.
wp-content/themes
directory.my-first-theme
.In your theme directory (my-first-theme
), you'll need to create at least two files:
style.css
: This CSS file contains the styling rules for your theme. At the top of this file, you need to add the theme details in a comment block.index.php
: This is the main template file for your theme. It controls what is displayed on your site's homepage by default.index.php
, you can start with a simple structure.style.css
to style the <div>
or any other elements as you prefer.script.js
, in your theme folder. You can enqueue this script in your theme by adding the following function to your functions.php
file (create this file if it doesn't exist).First, install Timber as a plugin in your WordPress site. You can do this by:
wp-content/plugins
directory.Activate the Timber plugin through your WordPress dashboard by going to Plugins and clicking the "Activate" link under Timber.
Create a new theme directory in wp-content/themes
, for example, my-timber-theme
. The basic files you'll need are:
style.css
: To define your theme's metadata and styles.functions.php
: To enqueue styles/scripts and initialize Timber.index.twig
: To define the HTML structure of your theme's main page using Twig syntax.functions.php
functions.php
, initialize Timber and set up theme support features.index.twig
)Create a templates
directory inside your theme, and within it, create your first Twig file, index.twig.
In your theme's functions.php
, you'll need to tell WordPress to use Timber and Twig for rendering templates. For the homepage.
single-my_custom_post_type.twig
.functions.php
, you can modify the context.Advanced Custom Fields (ACF) is a powerful plugin for WordPress that allows you to add custom fields to your content. When combined with Timber and Twig, you can create highly customized and dynamic WordPress themes. Here's how to use ACF with Twig in your Timber-powered WordPress theme:
First, ensure that the Advanced Custom Fields plugin is installed and activated on your WordPress site.
To access ACF fields in Timber, you can use Timber's Post
object which automatically integrates with ACF. For example, if you've added custom fields to a post, you can access them like this in your Twig template:
twigCopy code {% set post = Timber\\Post(post.ID) %} <p>{{ post.meta('your_custom_field_name') }}</p>
Alternatively, if you want to directly access ACF fields without using meta()
, Timber allows you to access ACF fields directly by their names for the current post:
twigCopy code <p>{{ post.your_custom_field_name }}</p>
ACF's Repeater fields allow you to create a set of sub-fields which can be repeated again and again. In Timber and Twig, you can iterate over these fields as follows:
twigCopy code {% if post.get_field('repeater_field_name') %} <ul> {% for item in post.get_field('repeater_field_name') %} <li>{{ item.sub_field_name }}</li> {% endfor %} </ul> {% endif %}
ACF's Flexible Content field is a versatile type that allows you to create a set of layouts. Accessing and displaying these fields in Twig requires iterating over the layouts and displaying them based on their layout name:
twigCopy code {% for layout in post.flexible_content_field_name %} {% if layout.acf_fc_layout == 'layout_name' %} <div>{{ layout.some_sub_field }}</div> {% endif %} {% endfor %}
If you're using ACF's Options Page feature to store global settings, you can access these fields in Timber as follows:
twigCopy code {% set options = Timber::get_options() %} <p>{{ options.your_options_field_name }}</p>
For fields you want to be globally accessible across all templates, you can add them to the Timber context in your theme's functions.php
file:
phpCopy code add_filter('timber/context', function ($context) { $context['options'] = get_fields('option'); return $context; });
Now, any ACF field defined in an Options Page can be accessed directly in Twig templates via the options
variable:
twigCopy code <p>{{ options.your_global_option_field }}</p>
Combining Yoast SEO with proper robots.txt
management can significantly improve your website's search engine optimization (SEO). Yoast SEO is a comprehensive WordPress plugin that helps optimize your site's content, while the robots.txt
file instructs search engines on how to crawl your website. Here's how to use both effectively:
Yoast SEO is a plugin for WordPress that provides tools for optimizing your site's content for search engines. Some of its key features include:
robots.txt
The robots.txt
file is a text file located in the root directory of your site. It tells search engine crawlers which pages or sections of your site should not be crawled and indexed. Proper management of this file is crucial for SEO as it can prevent search engines from indexing duplicate pages, admin pages, or sensitive sections of your site.
robots.txt
with Yoast SEOYoast SEO does not directly create or edit the robots.txt
file. However, it allows you to edit the file from the WordPress dashboard:
robots.txt
: If you already have a robots.txt
file, Yoast SEO will display its contents. If not, you can create one by entering your directives and clicking the "Save changes to robots.txt
" button.robots.txt
robots.txt
file allows access to your XML sitemap. You can do this by adding a line like Sitemap: <http://www.yourwebsite.com/sitemap_index.xml
>.Disallow
directive to prevent crawlers from accessing specific directories or pages. For example, Disallow: /wp-admin/
blocks access to the WordPress admin area.地址
Level 10b, 144 Edward Street, Brisbane CBD(Headquarter)Level 2, 171 La Trobe St, Melbourne VIC 3000四川省成都市武侯区桂溪街道天府大道中段500号D5东方希望天祥广场B座45A13号Business Hub, 155 Waymouth St, Adelaide SA 5000Disclaimer
JR Academy acknowledges Traditional Owners of Country throughout Australia and recognises the continuing connection to lands, waters and communities. We pay our respect to Aboriginal and Torres Strait Islander cultures; and to Elders past and present. Aboriginal and Torres Strait Islander peoples should be aware that this website may contain images or names of people who have since passed away.
匠人学院网站上的所有内容,包括课程材料、徽标和匠人学院网站上提供的信息,均受澳大利亚政府知识产权法的保护。严禁未经授权使用、销售、分发、复制或修改。违规行为可能会导致法律诉讼。通过访问我们的网站,您同意尊重我们的知识产权。 JR Academy Pty Ltd 保留所有权利,包括专利、商标和版权。任何侵权行为都将受到法律追究。查看用户协议
© 2017-2024 JR Academy Pty Ltd. All rights reserved.
ABN 26621887572