[wordpress插件] Cursorial游标

wordpress 插件 文章 2020-04-07 03:40 395 0 全屏看文

AI助手支持GPT4.0

评分
0
描述

With this plugin you can create your own loops

使用此插件,您可以创建自己的循环

/>

/>

and manage them with a simple drag-and-drop interface.

并通过简单的拖放界面进行管理。

Register one or more loops in your theme's function.php and then use them as any other loop in your theme with have_posts(), the_post()

在主题的 function.php 中注册一个或多个循环,然后通过 have_posts() the_post()将它们用作主题中的任何其他循环



etc. Editors can then manage these loops in the administration by simply drag posts to these loops or between them and override the posts’ content if they like.

然后,编辑者可以在管理中管理这些循环,只需将帖子拖到这些循环中或它们之间,并根据需要覆盖帖子的内容。

They’ll find posts in a search box just next to the loops.

他们将在循环旁边的搜索框中找到帖子。

The loops can be configured to …

可以将循环配置为...

    • allow just a limited number of posts,
    • 只允许发表有限数量的帖子,

    • allow just a specified set of post types,
    • 只允许指定一组帖子类型,

    • to have posts with children (like nested loops, related content etc),
    • 拥有带孩子的帖子(例如嵌套循环,相关内容等)

    • make posts’ content overrideable and optional,
    • 使帖子的内容可替代和可选

    • be set together in the administration,
    • 在管理部门中设置在一起,

    • and use images fetched from content or the featured image.
    • 并使用从内容或精选图片中提取的图片。

    This plugin also comes with a widget that …

    此插件还带有一个小部件,...

      • displays a registered loop
      • 显示已注册的循环

      • or creates one for you.
      • 或为您创建一个。

      No additional database tables or writeable directories are added

      未添加其他数据库表或可写目录

      This plugin will simply register a hidden custom post type and

      此插件将仅注册一个隐藏的自定义帖子类型,

      a custom taxonomy.

      自定义分类法

      It’s therefore installableunnable on most kinds of web hosts/environments.

      因此,它可以在大多数类型的网络主机/环境中安装/运行。

      More info, wiki and issue tracker

      更多信息,Wiki和问题跟踪器

      https://github.com/klandestino/cursorial

      https://github.com/klandestino/cursorial

安装步骤

1.

1。

Install the plugin

安装插件

You can install Cursorial using the built in WordPress plugin installer.

您可以使用内置的WordPress插件安装程序来安装Cursorial。

If you wish to install Cursorial manually, make sure you’ve uploaded the plugin to wp-content/plugins/cursorial.

如果您希望手动安装Cursorial,请确保已将插件上传到 wp-content / plugins / cursorial

Activate the plugin in the Plugins admin panel using the Activate

使用激活
插件管理面板中激活插件。

link.

链接。

You’ll then be able to register your loops and use the widget that follows with this plugin.

然后,您将能够注册循环并使用此插件随附的小部件。

2.

2。

How to use the widget

如何使用小部件

Drag the Cursorial Widget to any preferable sidebar in Widget admin panel found in Appearence.

Cursorial Widget 拖动到 Appearence 中找到的 Widget 管理面板中任何更喜欢的侧边栏中。

You’ll then see a list of available loops, called blocks, if you’ve registered any.

如果您已注册任何循环,则将看到可用循环的列表,称为块。

If not, you’ll be able to create one for the current widget by checking the Custom block

如果没有,您可以通过选中自定义块
为当前小部件创建一个

radio button.

单选按钮。

You can set the maximum number of posts and what fields that will be available.

您可以设置帖子的最大数量以及可用的字段。

All widget-created blocks are then found in the Custom Widget Blocks

然后在自定义窗口小部件块
中找到所有窗口小部件创建的块

admin panel found in the Cursorial menu.

Cursorial 菜单中找到管理面板。

3.

3。

Register your loops in the theme’s function.php

在主题的function.php中注册您的循环

Use register_cursorial() to register loops.

使用 register_cursorial()注册循环。

This function takes two arguments.

该函数有两个参数。

First an array with the loops you want, and then another array with information about how your loops will be shown for the editors in the administration.

首先是一个包含所需循环的数组,然后是另一个包含有关如何在管理中为编辑者显示循环的信息的数组。

Here’s some lines of code:

下面是几行代码:

add_action( 'after_setup_theme', 'your_theme_setup' );

  add_action('after_setup_theme','your_theme_setup');

function your_theme_setup() { if ( function_exists( 'register_cursorial' ) ) { register_cursorial(array( // Array with the custom loops 'main-feed' => array( // The key is the name of the loop 'label' =>

函数your_theme_setup(){if(function_exists('register_cursorial')){register_cursorial(array(//带有自定义循环的数组'main-feed'=> array(//键是循环'label'的名称=>

__( 'Main Feed' ), // The official label of the loop 'max' => 2, // The maximum amount of allowed posts 'post_type' => array( 'page' ), // Limit posts with post type

__('Main Feed'),//循环的正式标签'max'=> 2,// //允许的帖子数量上限'post_type'=> array('page'),//限制帖子类型的帖子

. Can be defined as an array or a string 'childs' => array( // If set, all posts in this loop can have childs 'max' => 2, // The maximum amount of allowed childs posts 'post_type' =

可以定义为数组或字符串'childs'=> array(//如果设置,则此循环中的所有帖子都可以具有childs'max'=> 2,//允许的最大childs帖子数量'post_type'=

> 'post', // Limit child posts with post type 'fields' => array( // Set the displayable child post field 'post_title' => array( // The key is the name of the post field 'optional' =

>'post',//限制帖子类型为'fields'的子帖子=> array(//设置可显示的子帖子字段'post_title'=> array(//键是帖子字段的名称'optional'=

> false, // If s

> false,//如果s

et to true, the field can be hidden by the editor in the admin 'overridable' => true // If set to true, the field's content can be overridden by the editor in the admin ), 'post_date' => array( '

设为true时,该字段可以由编辑器在admin'overridable'=> true中隐藏// //如果设置为true,则该字段的内容可以由admin的编辑器覆盖)'post_date'=> array('

optional' => true, 'overridable' => false ) ) ), 'fields' => array( // Set the displayable post field 'post_title' => array( 'optional' => false, 'overridable' => true

optional'=> true,'overridable'=> false)))),'fields'=> array(//设置可显示的帖子字段'post_title'=> array('optional'=> false,'overridable'=> true

), 'post_excerpt' => array( 'optional' => false, 'overridable' => true ), 'image' => array( // This field will fetch the first occuring image from the post

),'post_excerpt'=> array('optional'=> false,'overridable'=> true),'image'=> array(//此字段将从帖子中获取第一个出现的图像

'optional' => true, 'overridable' => true ) ) ), 'second-feed' => array( 'label' => __( 'Secondary Feed' ), 'max' => 4, 'fields' =

'optional'=> true,'overridable'=> true)))),'second-feed'=> array('label'=> __('Secondary Feed'),'max'=> 4,'fields'=

> array( 'post_title' => array( 'optional' => false, 'overridable' => false ), 'post_excerpt' => array( 'optional' => true, 'overridable' => true ), 'post_date'

> array('post_title'=> array('optional'=> false,'overridable'=> false),'post_excerpt'=> array('optional'=> true,'overridable'=> true),'post_date'

=> array( 'optional' => false, 'overridable' => false ) ) )),array( // Second argument is an array with some admin config __( 'Home'

=> array('可选'=> false,'overridable'=> false))))),array(//第二个参数是带有一些管理员配置的数组__('Home'

) => array( // The key is the name of the page where editors can edit specified loops 'main-feed' => array( // The key is the name of the loop that will be editable 'x' => 0

)=> array(//键是编辑者可以在其中编辑指定循环的页面的名称'main-feed'=> array(//键是将可编辑的循环的名称'x'=> 0

, // In what column this loop should be placed 'y' => 0, // In that row this loop should be placed 'width' => 2, // How many columns this loop is wide 'height' => 7

,// //该循环应放在哪一列'y'=> 0,//该循环应在那一行中放置'width'=> 2,2,//此循环宽多少列'height'=> 7

// How many rows this loop is tall ), 'banner-space-1' => array( // If there's no matched loop with this name, the space will be occupied by a dummy placeholder 'x' => 2, '

//这个循环有多高行),'banner-space-1'=> array(//如果没有与此名称匹配的循环,该空间将被一个虚拟占位符'x'=> 2,'

y' => 0, 'width' => 1, 'height' => 2, 'dummy-title' => __( 'Banners' ), // A customized title 'dummy-description' => __( 'On

y'=> 0,'width'=> 1,'height'=> 2,'dummy-title'=> __('Banners'),//自定义标题'dummy-description'=> __('On

front page there are a couple of banners here.' ) // A customize

首页上有几个横幅。')//自定义

d description ), 'second-feed' => array( 'x' => 2, 'y' => 2, 'width' => 1, 'height' => 3 ) ), __( 'Sub pages' )

d description),'second-feed'=> array('x'=> 2,'y'=> 2,'width'=> 1,'height'=> 3)),__('子页面')

=> array( // Another admin page with a set of loops '_dummy' => array( 'x' => 0, 'y' => 0, 'width' => 2, 'height' => 7, '

=> array(//具有一组循环的另一个管理页面'_dummy'=> array('x'=> 0,'y'=> 0,'width'=> 2,'height'=> 7,'

dummy-title' => __( 'Page or post content' ), 'dummy-description' => __( 'The current page or post content.' ) ), 'second-feed' => array( 'x' =

dummy-title'=> __('页面或帖子内容'),'dummy-description'=> __('当前页面或帖子内容。')),'second-feed'=> array('x'=

> 2, 'y' => 0, 'width' => 1, 'height' => 7 ) )) );

> 2,'y'=> 0,'width'=> 1,'height'=> 7))));

} }

}}

4.

4。

Query the posts

查询帖子

There are two ways to print the posts from your customized loops.

有两种方法可以从自定义循环中打印帖子。

You can embed a loop anywhere in your theme with query_cursorial_posts().

您可以使用 query_cursorial_posts()在主题的任何位置嵌入循环。

This will work almost exactly as if you used query_posts() (see reference).

食品法典委员会” rel =“ nofollow”>参考)。

The only difference is that you’ll not be able to customize the loop with arguments.

唯一的区别是您将无法使用参数自定义循环。

query_cursorial_posts() takes only one argument, and that’s the name of the loop that you want to get posts from.

query_cursorial_posts()仅接受一个参数,这就是您要从中获取帖子的循环的名称。

If you omit this argument, the function will query posts from the first occuring registered loop.

如果省略此参数,则该函数将从第一个出现的注册循环中查询帖子。

Example:

示例:

  <?php query_cursorial_posts('main-feed'); 

?>

?> <?php while(have_posts()):the_post();

?>

?>

<?php the_title();

?>

?> <?php the_cursorial_image();

?>

?> <?php the_excerpt();

?>

?> <?php同时;

?>

?>

Here with the get_template_part():

此处带有 get_template_part()

  <?php query_cursorial_posts('main-feed'); 

?>

?> <?php while(have_posts()):the_post();

?>

?> <?php get_template_part('content',get_post_type());

?>

?> <?php结束;

?>

?>

If you want to place all your custom loop code in some other template files you can use get_cursorial_block().

如果要将所有自定义循环代码放在其他模板文件中,则可以使用 get_cursorial_block()

It will call templates called cursorial.php or cursorial-LOOP-NAME.php.

它将调用名为 cursorial.php cursorial-LOOP-NAME.php 的模板。

Example:

示例:

// In home.php 

  // in home.php <?php get_cursorial_block('main-feed'); 

?> // In cursorial-main-feed.php

?> //在cursorial-main-feed.php <?php while(have_posts()):the_post();

?>

?> <?php get_template_part('content',get_post_type());

?>

?> <?php结束;

?>

?>

5.

5。

Print images, get it’s depth and check if a post field is hidden

打印图像,获取图像的深度,并检查发布字段是否隐藏

If you are using the field image (witch is a non wordpress field, added by this plugin), an image is fetched either from a featured image or the first occuring image in the content.

如果您使用的是 image 字段(witch是一个非wordpress字段,由此插件添加),则会从精选图片或内容中的第一个出现的图片中获取图片。

It can then be overrided by the editor if you set the field to be overrideable.

如果将字段设置为可覆盖,则编辑器可以覆盖它。

In order to print this image you need to call the_cursorial_image() or get_the_cursorial_image() (witch will return the image tag instead of printing it).

为了打印此图像,您需要调用 the_cursorial_image()或get_the_cursorial_image()(女巫将返回图像标签,而不是打印它)。

If you’ve set a loop to support child posts, then you’ll need to know what posts are childs or not.

如果您设置了一个循环来支持子帖子,那么您需要知道哪些帖子是子帖子。

With the_cursorial_depth() and get_the_cursorial_depth() you’ll get an integer for what depth the current post has.

使用 the_cursorial_depth()和get_the_cursorial_depth(),您将获得一个整数,表示当前帖子的深度。

0 for parents and 1 for childs.

父母0个,儿童1个。

An important thing to know is that both parents and childs are found in the same loop.

要知道的重要一点是,父母和孩子都位于同一循环中。

There are no nested loops of any kind.

没有任何嵌套循环。

If you’ve set a field to be optional, an editor may have hidden some posts’ fields.

如果您将字段设置为可选,则编辑者可能隐藏了某些帖子的字段。

You’ll notice that the template tag for that field will not return anything.

您会注意到,该字段的模板标记不会返回任何内容。

But in some cases you may want to also hide some HTML that wraps the field.

但是在某些情况下,您可能还希望隐藏一些包装该字段的HTML。

With is_cursorial_field_hidden( 'field_name' ) you’ll know if the field is set to be hidden.

使用 is_cursorial_field_hidden('field_name'),您将知道该字段是否设置为隐藏。

Example:

示例:

  <?php while(have_posts()):the_post(); 

?>

?>

?>" title="

?>“ title =” <?php esc_attr(get_the_title());

?>">

?>“> <?php the_title();?> <?php if(!is_cursorial_field_hidden('image')):?>

<?php the_cursorial_image(

); ?>

);?> <?php endif;?> <?php endwhile;?>

下载地址
https://downloads.wordpress.org/plugin/cursorial.1.1.zip
-EOF-

AI助手支持GPT4.0