sectsect/cfs-loop-field-query

修改“Loop Field”自定义字段中文章的查询到多个日期。

安装: 8

依赖: 0

建议者: 0

安全: 0

星标: 1

关注者: 4

分支: 1

开放问题: 0

类型:wordpress-plugin

v2.1.5 2017-11-15 15:09 UTC

This package is auto-updated.

Last update: 2024-09-25 06:49:11 UTC


README

Custom Field Suite "Loop Field"修改文章中的查询到多个日期。

功能

对于在“Loop Field”中设置的每个日期和时间,仅将计划事件输出到存档页面。

  • 在“Loop Field”中设置的日期和时间一个事件的形式输出。
  • 按最近的事件顺序显示(ASC)。
  • 不输出已关闭的事件。
  • 为日历提供函数 📅

要求

  • PHP 5.3+
  • 激活Custom Field Suite 插件。
  • 使用CFS 插件在“Loop Field”中创建循环字段和日期字段。
  • 一箱啤酒🍺(可选,我想。)

安装

  1. cd /path-to-your/wp-content/plugins/
  2. git clone git@github.com:sectsect/cfs-loop-field-query.git
  3. 通过WordPress中的“插件”菜单激活插件。
    您可以通过访问设置 -> CFS Loop Field Query来访问一些设置。
  4. 在“Loop Feld”中设置Post Type NameLoop Field NameDate Field Name
    (可选字段:Taxonomy NameStartTime FieldFinishTime Field
    就是这样:ok_hand:您的选择文章类型的主要查询将被修改。

字段结构示例

提示

  • 如果您想将其应用于某些现有文章,请重新保存文章。
  • 此插件包括在CFS中添加时间选择器字段。(使用CFS 时间选择器附加组件
  • is_date()的支持包括is_year()is_month()is_day()
  • 如果您设置了'FinishTime',则当时间超过您设置的时间时,不会显示该文章。(默认:全天)

使用示例

您可以使用new CFS_LFQ_Query()获取子查询。

示例:子查询

<?php
    $ary     = array();
    $page    = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $perpage = 10;
    $offset  = ( $page - 1 ) * $perpage;
    $args    = array(
        'posts_per_page' => $perpage
    );
    $query = new CFS_LFQ_Query( $args );
?>
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
    // something
<?php endwhile; ?>
<?php endif;?>
<?php wp_reset_postdata(); ?>

示例:带有cfs_lfq_calendar()的日历子查询

$dates   = array();
$args    = array(
    'posts_per_page' => -1,
    'calendar'       => true,       // Get the data for Not from the day but from the first day of the month.
);
$query = new CFS_LFQ_Query( $args );
if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post();
    $date = date( 'Ymd', strtotime( $post->date ) );
    array_push( $dates, $date );
}}
wp_reset_postdata();

// Passing array to cfs_lfq Calendar Class.
$dates  = array_unique( $dates );		// Remove some Duplicate Values(Day)
$months = get_months_from_now( 3 );
$args = array(
    'dates'        => $dates,		// (array) (required) Array of event Date ('Ymd' format)
    'months'       => $months,		// (array) (required) Array of month to generate calendar ('Ym' format)
    'weekdayLabel' => 'default',	// (string) (optional) Available value: 'default' or 'en' Note: 'default' is based on your wordpress locale setting.
    'weekdayBase'  => 0,		// (integer) (optional) The start weekday. 0:sunday ~ 6:saturday Default: 0
    'element'      => 'div',		// (string) (optional) The element for wraping. Default: 'div'
    'class'        => ''		// (string) (optional) The 'class' attribute value for wrap element. Default: ''
);
cfs_lfq_calendar( $args );

示例:使用Your Calendar Class的日历子查询

$ary     = array();
$args    = array(
    'posts_per_page' => -1,
    'calendar'       => true		// Get the data for Not from the day but from the first day of the month.
);
$query = new CFS_LFQ_Query( $args );
if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post();
    $date    = date( 'Ymd', strtotime( $post->date ) );
    $post_id = $post->ID;
    $perm    = get_the_permalink();
    $title   = get_the_title();
    array_push( $ary, array('date' => $date, 'id' => $post_id, 'permlink' => $perm, 'title' => $title) );
}}
wp_reset_postdata();

// Passing array to your Calendar Class.
require_once 'Calendar/Month/Weeks.php';
calendar( $ary, 0 );

示例:获取“日期”、“StartTime”和“FinishTime”

<div id="date">
    <?php echo date( 'Y-m-d', strtotime( $post->date ) ); ?>
</div>
<time>
    <?php echo date( "H:i", strtotime( $post->starttime ) ); ?> ~ <?php echo date( "H:i", strtotime( $post->finishtime ) ); ?>
</time>

函数

get_months_from_now($num)

参数
  • num(整数)(必需)要获取的月份数。
    默认:1
返回值

(数组)
格式为Ym

$months = get_months_from_now( 3 );

cfs_lfq_calendar($args)

参数
  • dates(数组)(必需)事件日期数组(Ymd格式)。

  • months(数组)(必需)要生成日历的月份数组(Ym格式)。

  • weekdayLabel(字符串)(可选)可用值:'default''en'
    默认:'default'
    📝 'default'基于您的WordPress区域设置。

  • weekdayBase(整数)(可选)起始工作日。0:星期天 ~ 6:星期六
    默认:0

  • element(字符串)(可选)包装元素。
    默认:'div'

  • class(字符串)(可选)包装元素的'class'属性值。
    默认:''

示例
$args = array(
	'dates'        => $dates,
	'months'       => $months,
	'weekdayLabel' => 'default',
	'weekdayBase'  => 0,
	'element'      => 'div',
	'class'        => 'myclass'
);
cfs_lfq_calendar( $args );

开发者注意

  • 此插件没有在wordpress.org 存储库中托管,以防止从广泛受众那里接收到大量的支持请求。

变更日志

查看CHANGELOG 文件。

贡献

  1. 创建一个问题并描述你的想法
  2. 将其Fork
  3. 创建你的功能分支(git checkout -b my-new-feature
  4. 提交你的更改(git commit -am '添加一些功能'
  5. 发布分支(git push origin my-new-feature
  6. 创建一个新的Pull Request
  7. 获利!✅

许可证

请参阅LICENSE文件。

相关插件

我还有一个具有相同功能的插件,用于Advanced Custom Field插件。

ACF Repeater Field Query