WordPress 101 主题开发教程: 18 – 创建自定义文章类型Part1

WordPress 101 – Part 18: How to create Custom Post Type – Part 1

视频学习参考:https://www.youtube.com/watch?v=vSM7w3zzlSU&list=PLriKzYyLb28nUFbe0Y9d-19uVkOnhYxFE&index=18

1.在functions.php中加入

/**
* 自定文章
*/
function themes_custom_post_type() {
$labels = array(
'name' => 'Portfolio',
'singular_name' => 'Portfolio',
'add_new' => 'Add Portfolio Item',
'all_items' => 'All Items',
'add_new_item' => 'Add Item',
'edit_item' => 'Edit Item',
'new_item' => 'New Item',
'view_item' => 'View Item',
'search_item' => 'Search Portfolio',
'not_found' => 'No Items Found',
'not_found_in_trash' => 'No Items Found In Trash',
'parent_item_colon' => 'Parent Item',
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'publicly_queryable' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail',
'revisions',
),
'taxonomies' => array(
'category',
'post_tag',
),
'menu_position' => 5,
'exclude_from_search' => false,
);
register_post_type('portfolio', $args);
}
add_filter('init', 'themes_custom_post_type');

Happy coding!

WordPress 101 主题开发教程: 17 – 创建自定义归档页和404页面

WordPress 101 – Part 17: How to create a custom Archive and 404 page

视频学习参考:https://www.youtube.com/watch?v=5NdoDjukAVQ&list=PLriKzYyLb28nUFbe0Y9d-19uVkOnhYxFE&index=17

1.归档页archive.php

the_archive_title( '<h1 class="page-title">前', '后</h1>' );
the_archive_description( '<div class="taxonomy-description">', '</div>' );

2.404.php

<p><?php _e( 'It looks like nothing was found at this location. Maybe try a search?', 'twentyseventeen' ); ?></p>

<?php get_search_form(); ?>

<?php the_widget('WP_Widget_Recent_Posts'); ?>

WordPress 101 主题开发教程: 16 – 如何打印部L格信息

WordPress 101 – Part 16: How to print the Blog Info

学习视频参考:https://www.youtube.com/watch?v=wGJ0AgceWS4&list=PLriKzYyLb28nUFbe0Y9d-19uVkOnhYxFE&index=16

1.通过bloginfo函数显示站点名称

<?php bloginfo(‘name’); ?>

2.去除Wordpress版本号显示

/**
* 去除Wordpress版本号显示
*/
function remove_wp_version() {
return '';//传值也不显示 <meta name="generator" content="WordPress 5.2.9">
}
add_filter('the_generator', 'remove_wp_version');

WordPress 101 主题开发教程: 15 – 通过WalkerClass编辑菜单 Part 2

WordPress 101 – Part 15: Edit the menu with the Walker Class – Part 2

视频学习参考: https://www.youtube.com/watch?v=bTp3Pt_RQmA&list=PLriKzYyLb28nUFbe0Y9d-19uVkOnhYxFE&index=15

1.apply_filters 过滤器

function test_func(){
    return '修改值';
}
add_filter( 'test', 'test_func' );
echo apply_filters( 'test', '可以被修改的值' );

2. start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { … }

好麻烦啊 这个方法应该应用不广泛吧 好难写!

Everything is wonderful and beautiful!

WordPress 101 主题开发教程: 14 – 通过WalkerClass编辑菜单

WordPress 101 – Part 14: Edit the menu with the Walker Class – Part 1

视频学习参考:https://www.youtube.com/watch?v=ArEmwJV6M7s&list=PLriKzYyLb28nUFbe0Y9d-19uVkOnhYxFE&index=14

WalkerClass 真是之前没有发现的宝藏

通过这个类的子类Walker_Nav_menu 来实现

结构在主题根目录建立Inc文件夹

建立文件walker.php

在functions.php中编写 require get_template_directory() . ‘inc/walker.php’;

在walker.php中编写构建菜单的类

WordPress 101 主题开发教程: 13 – 创建并管理分页在你的部L格中

WordPress 101 – Part 13: Create and manage the Pagination in your blog loop

视频学习参考: https://www.youtube.com/watch?v=xEA2zviCakw&list=PLriKzYyLb28nUFbe0Y9d-19uVkOnhYxFE&index=13

1.在index.php的posts循环中加入, 多篇文章分页

<?php next_posts_link(‘<< Older Posts’); ?>

<?php previous_posts_link(‘Newer Posts >>’); ?>

2.在single.php中循环加入,单篇文章分页

<?php next_post_link(‘<< Older Posts’); ?>

<?php next_post_link(‘<< Older Posts’); ?>

3.自定义硬编码分页,通过query_posts()

$currentPage = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;

wp_reset_query();

Super Easily !

WordPress 101 主题开发教程: 12 – 创建自定义搜索表单管理搜索结果页

WordPress 101 – Part 12: Create a custom search form and manage the search results page

视频学习参考:https://www.youtube.com/watch?v=8Hn3k6Zsp9g&list=PLriKzYyLb28nUFbe0Y9d-19uVkOnhYxFE&index=12

通过下面的函数

get_search_form();
//参数可以传 html5

可以调用内置搜索表单或搜索表单的模板文件searchform.php

搜索结果通过 index.php 或者 search.php (如果存在) 展示

返回结果还可以组织 content-search.php组件页面来展示搜索结果!

See ya!

WordPress 101 主题开发教程: 11 – single.php,标签,编辑链接和commext模板(x->n)

WordPress 101 – Part 11: The single.php file, tags, edit links and comment template

视频学习参考:https://www.youtube.com/watch?v=CUefAciz5m8&list=PLriKzYyLb28nUFbe0Y9d-19uVkOnhYxFE&index=11

在这节课之前作者又发了一次在线交流修改并加入了轮播图和修改美化了列表页,得去恶补一下了 同样已经发到上一篇文章了可以参考

也可以直接看,在这里:https://www.youtube.com/watch?v=0UzwBRLfsbM&list=PLriKzYyLb28mwtQo8aF7GRBBZ_WJQm3_E&index=2

根据上节课的内容参考来说 还是挺有用的介绍了很多额外的知识点!

下面是本节课的知识点:

single.php是某篇文章的模板文件

the_cateogry(‘ ‘);

the_tags();

edit_post_link();

commext 要在文章的设置中勾选允许commext才行。(x->n)

Super Simple!

WordPress 101 主题开发教程: 10补 Q&A知识点交流2

WordPress Live Development Session + Q&A – Part 2

视频学习参考:https://www.youtube.com/watch?v=0UzwBRLfsbM&list=PLriKzYyLb28mwtQo8aF7GRBBZ_WJQm3_E&index=2

太机智了!原来还可以这么搞

就是先定义一个变量 在循环中把数据填写好

再在需要使用的地方展示

比如轮播图 在图片循环中把 信息填写好

再在循环外使用信息构建出导航的小点

机智!

引入了轮播组件

编写了1列2列3列并用图片作为背景的文章列表页

在循环展示列表页时 同样用了机制的方法 先在循环中处理 存储好本次需要展示的参数 而后在下面的代码直接加载展示

Super Simple!