acme.sh 用法

安装 acme.sh

curl https://get.acme.sh | sh -s email=your-email@outlook.com

设置别名,方便使用:

alias acme.sh=~/.acme.sh/acme.sh

申请证书:

acme.sh --issue -d notes.wujie.me  --nginx

或

acme.sh --issue -d notes.wujie.me  --webroot /var/www/notes.wujie.me

部署证书:

acme.sh --install-cert -d notes.wujie.me --key-file /etc/nginx/ssl/notes.wujie.me.key --fullchain-file /etc/nginx/ssl/notes.wujie.me.pem --reloadcmd "service nginx force-reload"

删除证书:

acme.sh --remove -d notes.wujie.me

删除后记得到 /root/.acme.sh/ 目录下找到域名文件夹,一并删除。

官方文档:https://github.com/acmesh-official/acme.sh/wiki/%E8%AF%B4%E6%98%8E

卸载xcode命令行工具

如果需要卸载xcode命令行工具,可以执行

sudo rm -rf /Library/Developer/CommandLineTools

接下来,运行以下命令来清理 xcode-select 的路径设置:

sudo xcode-select --reset

如果你还希望彻底删除与 Xcode 相关的文件,可以运行:

sudo rm -rf /Applications/Xcode.app

最后,验证命令行工具是否已成功删除:

xcode-select -p

如果没有输出或输出的是一个不存在的路径,则表示命令行工具已成功删除。

MacBook安装Homebrew

执行下面的命令以安装homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

在安装homebrew之前,需要先安装xcode命令行工具,上面的安装脚本会进行检查,如果没安装xcode命令行工具,会自动进行安装。

如果需要手动安装xcode命令行工具,可以执行:

xcode-select --install

WordPress自定义文章类型,在管理列表页显示分类名

只需要在register_taxonomy函数的第三个参数中,添加show_admin_column=>true即可。代码如下:

<?php

/**
 * 为产品 post type 添加分类功能
 */
add_action('init', 'my_taxonomies_product', 0);
function my_taxonomies_product() {
    $labels = array(
        'name'              => _x('产品分类', 'taxonomy 名称'),
        'singular_name'     => _x('产品分类', 'taxonomy 单数名称'),
        'search_items'      => __('搜索产品分类'),
        'all_items'         => __('所有产品分类'),
        'parent_item'       => __('该产品分类的上级分类'),
        'parent_item_colon' => __('该产品分类的上级分类:'),
        'edit_item'         => __('编辑产品分类'),
        'update_item'       => __('更新产品分类'),
        'add_new_item'      => __('添加新的产品分类'),
        'new_item_name'     => __('新产品分类'),
        'menu_name'         => __('产品分类'),
    );
    $args = array(
        'labels' => $labels,
        'hierarchical' => true,
        'show_admin_column' => true,
    );
    register_taxonomy('product_category', 'product', $args);
}

如果要在列表中添加自定义字段,即wp_postmeta表中的字段(通过meta_box添加的),可以使用下面的代码:

<?php

// 在列表中把加的字段显示出来
add_action("manage_posts_custom_column",  "product_custom_columns");
function product_custom_columns($column) {
    global $post;
    switch ($column) {
        case "product_director":
            echo get_post_meta($post->ID, '_product_director', true);
            break;
    }
}

add_filter("manage_edit-product_columns", "movie_edit_columns");
function movie_edit_columns($columns) {
    $columns['product_director'] = '产品分类';
    return $columns;
}

WordPress在single页面获取自定发布类型的分类

在详情页面,即single页面获取自定义发布类型的分类

<?php

/** 第一个参数表是当前文章的ID, 第二个参数表示所属的分类法,即taxonomy name。在single页面时可以直接使用 $post->ID **/
$terms = get_the_terms($post->ID, 'product_category');
if ($terms && !is_wp_error($terms)) :
    $terms_name_arr = array();
    foreach ($terms as $term) {
        $terms_name_arr[] = $term->name;
    }
    $terms_name_str = join(" ", $terms_name_arr);
endif;
echo $terms_name_str;

WordPress在archive.php页面获取文章列表

除了使用WP_Query函数之外,还可以使用query_posts函数来查询,如下:

<?php
query_posts(array(
    'post_type'   => 'case', // You can add a custom post type if you like
    'paged'     => get_query_var('paged', 1),
    'posts_per_page' => 1
));

while (have_posts()) :
    the_post();
?>
    <a href="<?php the_permalink() ?>" class="col-xs-12 col-sm-4 col-md-4 col-lg-4 block-four-list">
        <div class="block-four-list-wrap">
            <img src="<?php echo catch_that_image(); ?>" alt="">
            <div class="infos-right-view2 about-a-infos">
                <h5>成功案例</h5>
                <h1><?php the_title() ?></h1>
                <span class="a-more-4">了解更多<i class="iconfont icon-youjiantou6"></i></span>
            </div>
        </div>
    </a>


<?php
endwhile;

?>

WordPress修改默认发布类型(post)的一些参数

<?php
add_action('init', 'cp_change_post_object');
// Change dashboard Posts to News
function cp_change_post_object() {
    $get_post_type = get_post_type_object('post');
    $labels = $get_post_type->labels;
    //$labels->name = 'News';
    $labels->singular_name = '新闻资讯';
    // $labels->add_new = 'Add News';
    // $labels->add_new_item = 'Add News';
    // $labels->edit_item = 'Edit News';
    // $labels->new_item = 'News';
    // $labels->view_item = 'View News';
    // $labels->search_items = 'Search News';
    // $labels->not_found = 'No News found';
    // $labels->not_found_in_trash = 'No News found in Trash';
    // $labels->all_items = 'All News';
    // $labels->menu_name = 'News';
    // $labels->name_admin_bar = 'News';
}

WordPress搜索功能的制作

首先要创建一个搜索表单,示例代码如下:

<form method="get" action="" onsubmit="return checkForm();">
    <input type="text" placeholder="搜索" name="s" value="<?php the_search_query(); ?>">
    <button type="submit">
        <i class="iconfont icon-sousuo"></i>
    </button>
</form>

表单要注意的是,搜索关键词输入框的name一定要为s,不然wordpress识别不了,也就进不了search.php模板页面。

这样,在点击搜索按钮后,wordpress就会自动跳转到search.php模板页面。

search.php主要代码参考:

<div class="met-news-list" m-id="noset">
    <ul class="ulstyle met-pager-ajax imagesize" data-scale="400x400">
        <?php
        $paged = 1;
        if (get_query_var('page')) {
            $paged = get_query_var('page');
        }
        $s = get_search_query();
        $args = array(
            's' => $s,
            'paged' => $paged,
            'posts_per_page' => 20
        );

        // The Query
        $the_query = new WP_Query($args);
        if ($the_query->have_posts()) {
            while ($the_query->have_posts()) {
                $the_query->the_post();
        ?>
                <li>
                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                </li>

                <li class="media media-lg border-bottom1">
                    <div class="media-left">
                        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                            <img class="media-object" src="<?php echo catch_that_image(); ?>" alt="<?php the_title(); ?>" height="100" />
                        </a>
                    </div>
                    <div class="media-body">
                        <h4> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" target="_self"><?php the_title(); ?></a> </h4>
                    </div>
                </li>

            <?php
            }
        } else {
            ?>
            <!--未找到任何搜索结果-->

        <?php }
        ?>
    </ul>
    <div class="m-t-20 text-xs-center hidden-sm-down" m-type="nosysdata">
        共<strong><?php echo $the_query->max_num_pages; ?></strong>页 <strong><?php echo $wp_query->found_posts; ?></strong>条
    </div>
    <?php bootstrap_pagination($the_query); ?>
</div>