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!

WordPress 101 主题开发教程: 10 – 通过分类过滤WP_Query结果

WordPress 101 – Part 10: Filter the WP_Query with categories

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

本节课的重点函数是 get_categories();

$args_cat = array( ‘include’ => ‘1, 9 ,8’);

$categories = get_categories($args_cat);

foreach($categories as $category):

$args = array(
    'type' => 'post',
    'posts_per_pages' => 1,
    'offset' => 0,
    //'category__in' => array(),
    //'category__not_in' => array(),
   'category__in' => array($category->term_id), 
);
$lastBlog = new WP_Query($args);
if ( $lastBlog -> have_posts() ) :
    while ( $lastBlog -> have_posts() ) :
        $lastBlog -> the_post();
        the_title();
    endwhile;
endif;

endforeach;

** 当一篇文章选择归属于2个分类时 会同时属于2个分类

Super happy!

WordPress 101 主题开发教程: 09 – 创建自定义菜单

WordPress 101 – Part 9: Edit the query_posts with WP_Query

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

1.可以建立一个新的模板页面 比如 page-home.php

2.重点学习使用 WP_Query()和参数传递

$lastBlog = new WP_Query(‘type=post&posts_per_page=2&offset=1’);

$lastBlog = new WP_Query(array(

‘type’ => ‘post’, ‘posts_per_page’ => 2, ‘offset’ => 1

));

//重置查询

wp_reset_postdata();

Super Simple!

WordPress 101 主题开发教程: 08 – 创建侧边栏和小插件

WordPress 101 – Part 8: How to create Sidebar and Widgets areas

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

在这节课之前 作者进行了主题的Q&A并优化美化了主题:https://www.youtube.com/watch?v=OSYbTkzuyDg

在这个视频中可以查看之前的变化更新,补充的开发教程也记录在上一篇文章中

本节课主要说明了如何激活并加载侧边栏和插件区域,虽然写做“和”,但是他们其实指的是同一个内容。

1.在functions.php激活侧边栏插件功能

function twentyseventeen_widgets_init() {
register_sidebar(
array(
'name' => __( 'Blog Sidebar', 'twentyseventeen' ),
'id' => 'sidebar-1',
'class' => 'customxsidebar',/*此处的class仅会在后台编辑的时候出现*/
'description' => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'twentyseventeen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',/*注意此处的id 和 class 的 %1$s 使用的是各自小组件的id和class*/
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'twentyseventeen_widgets_init' );

2.编写sitebar.php 侧边栏插件区的结构文件 用于展示侧边栏

<?php
if
( ! is_active_sidebar( 'sidebar-1' ) ) {
return;
}
?>

<aside id="secondary" class="widget-area" role="complementary" aria-label="<?php esc_attr_e( 'Blog Sidebar', 'twentyseventeen' ); ?>">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</aside><!-- #secondary -->

3.在index.php 或者 page.php中开启侧边栏插件区显示

<?php get_sidebar(); ?>

Super Easy!

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

WordPress Theme Development Live Session + Q&A

视频学习参考: https://www.youtube.com/watch?v=OSYbTkzuyDg

作者在下节课和上节课中间加入了一节在线交流

重点讲解了以下内容:

1.加入内置jquery

wp_enqueue_script(‘jquery’);

2.加入第三方组件: bootstrap

wp_enqueue_style( 'bootstrap-css' , get_template_directory_uri() . '/assets/libs/bootstrap/css/bootstrap.min.css', array(), '5.0.0', 'all' );
wp_enqueue_script( 'bootstrap-js', get_template_directory_uri() . '/assets/libs/bootstrap/js/bootstrap.min.js', array(), '5.0.0', true );

3.引入bootstrap css框架

4.合并到bootstarap顶部导航菜单 复制bootstrap导航代码 结合下方代码

<?php wp_nav_menu( array( ‘theme_location’ => ‘primary’, ‘container’ => false, ‘menu_class’ => ‘nav navbar-nav navbar-right’ ) );

5.修改文章列表

//the_title( before, after);
//参数1 前半段标签及标题
//参数2 后半段闭合标签
the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );

6.推荐参考codex.wordpress.org进行开发

https://codex.wordpress.org/

中文:https://codex.wordpress.org/zh-cn:Main_Page

7.作者使用插件

Akismet

Contact Form 7

Caryon Syntax Highlighter

Disqus Comment System

Jetpack by WordPress.com

TinyMCE Advanced

WordPress SEO

WP-PageNavi

WP Lightbox 2

Hopefully!

WordPress 101 主题学习教程: 07 – 创建并加入文章格式(展示类型)

WordPress 101 – Part 7: How to add and create Post Formats

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

1.启用文章类型功能支持, 打开functions.php

//一共有9种支持的文章类型 从4.1.2版本开始

add_theme_support(‘post-formats’, array(‘aside’, ‘image’, ‘video’));

2.通过 get_post_format() 返回 当前文章的格式

3.在index.php的post循环中 加入

<?php get_template_part(‘content’, get_post_format()); ?> //会自动寻找content-xxx.php作为底板,如果content-xxx.php不存在则用content.php

取代原来的内容展示 并将内容展示移入 content.php中

4.创建不同的content-xxx.php

Super Simple!

P.S. aside是日志的意思