1

我目前正在使用插件Google Calendar Events。我想添加让用户选择(通过选择下拉菜单)他们正在查看的提要的功能,然后让日历自动显示所选提要。有谁知道如何做到这一点?

我知道您可以使用简码来选择要显示的提要,但我不想为每个提要创建单独的页面,然后有指向它们的链接(有 10 多个提要,并且会定期添加和删除一个提要,因此为每个单独的提要手动创建日历是不可行的)。

我已将此代码添加到插件中的 gce-script.js 文件中:

    function changeFeeds(){
    var values = jQuery("#gce-view-feed").val();
    jQuery("#result").replaceWith(values);
}

jQuery("option").click(function(){
    location.reload();
});

jQuery("select").change(changeFeeds);
changeFeeds();

... id "gce-view-feed" 是选择菜单的 id,id "result" 是我显示结果的地方。这很好用,除了我如何将该结果传递给插件以便它使用它?

Feed id 由 PHP 变量 $feed_ids 定义。我认为编辑变量的最佳位置是 google-calendar-events.php 文件中的这行代码:

//Check that any feeds have been added
        if ( is_array( $options ) && ! empty( $options ) ) {
            extract( shortcode_atts( array(
                'id' => '',
                'type' => 'grid',
                'title' => null,
                'max' => 0,
                'order' => 'asc'
            ), $atts ) );

            $no_feeds_exist = true;
            $feed_ids = array();

            if ( '' != $id ) {
                //Break comma delimited list of feed ids into array
                $feed_ids = explode( ',', str_replace( ' ', '', $id ) );

                //Check each id is an integer, if not, remove it from the array
                foreach ( $feed_ids as $key => $feed_id ) {
                    if ( 0 == absint( $feed_id ) )
                        unset( $feed_ids[$key] );
                }

                //If at least one of the feed ids entered exists, set no_feeds_exist to false
                foreach ( $feed_ids as $feed_id ) {
                    if ( isset($options[$feed_id] ) )
                        $no_feeds_exist = false;
                }
            } else {
                foreach ( $options as $feed ) {
                    $feed_ids[] = $feed['id'];
                }

                $no_feeds_exist = false;
            }

但我不知道如何将 jQuery 值传递给 $feed_ids 变量。有没有办法做到这一点?如果没有,是否有另一种方法来动态选择一个选项,然后将其传递给 PHP 变量?

4

0 回答 0