首页 问答 正文

WordPress中的目录插件有哪些?

注册会员 / 悠然自学 / 2023-06-11/ 浏览 138 次

  1. WP File Download - 目录管理插件,支持文件和文件夹的创建、编辑、删除等操作。

  2. Simple Custom Post Order - 可以对WordPress中的所有文章、页面、分类目录、标签进行排序。

  3. Category Order and Taxonomy Terms Order - 为分类目录、标签、自定义分类法等提供排序功能。

示例代码:

  1. WP File Download:
// 创建目录
$fileDownload = new wpfd_folder();
$fileDownload->name = 'test';
$fileDownload->parent = 0;
$fileDownload->save();

// 创建文件夹
$fileDownload = new wpfd_file();
$fileDownload->name = 'test.docx';
$fileDownload->parent = 1; //设置为上一级目录的ID
$fileDownload->path = '/wp-content/uploads/';
$fileDownload->save(); 
  1. Simple Custom Post Order:
//shortcode: [simple_cpo_order]
// 可以使用orderby参数进行排序
function get_custom_post_type(){
    $args = array(
        'post_type' => 'custom_post_type',
        'orderby' => 'menu_order', //使用自定义排序
        'order' => 'ASC'
    );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    //在此处输出文章内容
    endwhile;
} 
  1. Category Order and Taxonomy Terms Order:
//shortcode: [catlist id=1 order_by=menu_order order=asc]
function my_custom_categories_shortcode($atts){
    $atts = shortcode_atts( array(
        'id' => 0,
        'order_by' => 'name', //使用分类名进行排序
        'order' => 'ASC'
    ), $atts, 'catlist' );

    $cat_args = array(
        'orderby' => $atts['order_by'],
        'order' => $atts['order'],
        'hide_empty' => 0,
        'include' => $atts['id']
    );

    $categories = get_categories( $cat_args );

    //在此处输出分类目录信息
} 
大家谈论
    我的见解