小编Ian*_*Ian的帖子

Ionic Framework/AngularJS中的两组单选按钮

我有两组具有相同值的单选按钮.其中一个是用户输入,一个用于显示结果.

我能够正确保存值,但问题是任何时候只有一个单选按钮显示为活动状态.我真正想要的是每个集合都有一个无线电.

app.js:

angular.module('starter', ['ionic', 'starter.controllers'])

.config(function($stateProvider, $urlRouterProvider) {

  // Ionic uses AngularUI Router which uses the concept of states
  // Learn more here: https://github.com/angular-ui/ui-router
  // Set up the various states which the app can be in.
  // Each state's controller can be found in controllers.js
  $stateProvider

    // setup an abstract state for the tabs directive
    .state('tab', {
      url: "/tab",
      abstract: true,
      templateUrl: "templates/tabs.html"
    })

    .state('tab.dash', {
      url: '/dash',
      views: {
        'tab-dash': {
          templateUrl: 'templates/tab-dash.html',
          controller: 'DashCtrl'
        }
      }
    }) …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs ionic-framework

8
推荐指数
1
解决办法
9009
查看次数

在Yoast Wordpress SEO插件中设置自定义规范URL

由于没有回复而转贴.

我在使用Wordpress SEO API设置自定义规范标题时遇到了一些麻烦:http://yoast.com/wordpress-seo-api-docs/

我有一个名为designs的自定义帖子类型,它使用自定义URL重写.它需要基页/设计/并添加设计名称,如/ design/a-design /.Wordpress SEO中的规范默认为/ design/page.

我想要做的是编写一个函数来确定它是否是一个设计页面并返回一个不同的规范.我可以测试它是否是一个设计页面if ($design == ""){,我尝试使用自定义永久链接URL,但该功能只是完全删除了规范.

这是我的基本功能:

function design_canonical(){
    if ($design == "") {    
        // Leave blank and Yoast SEO will use default canonical for posts/pages
    }
    else {
        return $design['detailslink'];
    }
}
add_filter( 'wpseo_canonical', 'design_canonical' )
Run Code Online (Sandbox Code Playgroud)

很明显做错了什么,但我不完全确定是什么.

思考?

php wordpress seo wordpress-plugin

7
推荐指数
2
解决办法
9443
查看次数

未捕获错误:[$ injector:unpr]未知提供者Ionic Framework/AngularJS

按照Ionic博客上本地存储教程,我正在尝试在我的Ionic应用程序运行时设置/获取localStorage值,但是我收到错误消息:

Uncaught Error: [$injector:unpr] Unknown provider: $localstorageProvider <- $localstorage
Run Code Online (Sandbox Code Playgroud)

我的app.js代码:

angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])

.run(function($ionicPlatform, $localstorage) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }

    $localstorage.set('name', 'Ian');
    console.log($localstorage.get('name'));
  });
})
Run Code Online (Sandbox Code Playgroud)

和services.js:

angular.module('starter.services', [])

.factory('localstorage', ['$window', function($window) {
  return {
    set: function(key, value) {
      $window.localStorage[key] = value;
    },
    get: …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs ionic-framework

6
推荐指数
2
解决办法
2万
查看次数

使用number_format添加千位分隔符

我试图简单地将变量$ output中的数字转换为带有千位分隔符的数字.它当前输出的数字是49995,但我希望它显示为49,995.

有点麻烦.救命?

function twitter_followers($user = 'mytwitterusername'){
    // Build Twitter api url
    $apiurl = "http://api.twitter.com/1/users/show.json?screen_name={$user}";

    //cache request
    $transient_key = $user . "_twitter_followers";

    // If cached (transient) data are used, output an HTML
    // comment indicating such
    $cached = get_transient( $transient_key );

    if ( false !== $cached ) {
        return $cached;
    }

    // Request the API data, using the constructed URL
    $remote = wp_remote_get( esc_url( $apiurl ) );

    // If the API data request results in an error, return
    // an …
Run Code Online (Sandbox Code Playgroud)

php number-formatting

4
推荐指数
1
解决办法
1万
查看次数

如何在Wordpress模板文件中添加结束短代码?

好的,所以你可以在WP模板文件中添加短代码,例如:

<?php echo do_shortcode('[my_awesome_shortcode]'); ?>
Run Code Online (Sandbox Code Playgroud)

但是如果短代码打算包含这样的内容呢:

[my_awesome_shortcode]
Hey, this is the content within the awesome shortcode.
[/my_awesome_shortcode]
Run Code Online (Sandbox Code Playgroud)

我有点不确定如何将它放入模板文件中.

php wordpress templates shortcode

3
推荐指数
2
解决办法
8022
查看次数

多维关联数组上的 foreach 循环

我有一个数组 ($this->taxBand),它有 3 个键 => 值对。每个值都是另一个数组:

array(3) {
  ["basic"]=>
  array(3) {
    ["rate"]=>
    int(20)
    ["start"]=>
    int(0)
    ["end"]=>
    int(31865)
  }
  ["higher"]=>
  array(3) {
    ["rate"]=>
    int(40)
    ["start"]=>
    int(31866)
    ["end"]=>
    int(150000)
  }
  ["additional"]=>
  array(3) {
    ["rate"]=>
    int(45)
    ["start"]=>
    int(150001)
    ["end"]=>
    NULL
  }
}
Run Code Online (Sandbox Code Playgroud)

我不仅需要循环遍历键“basic”、“higher”和“additional”,还需要循环遍历它们内的数组。

我将把“开始”和“结束”值与另一个变量进行比较,并根据“速率”进行计算。

我已经使用我在这里找到的许多示例和官方文档以几种不同的方式尝试了嵌套 foreach ,并且只能让它返回“基本”数组元素。

例子:

foreach ($this->taxBand as $key => $band) {

            foreach ($band as $subKey => $value) {

                    // Do my stuff

            }

        }
Run Code Online (Sandbox Code Playgroud)

如果我返回 $band,我会得到:

array(5) {
  ["rate"]=>
  int(20)
  ["start"]=>
  int(0)
  ["end"]=>
  int(31865)
}
Run Code Online (Sandbox Code Playgroud)

$key 返回:

string(5) "basic" …
Run Code Online (Sandbox Code Playgroud)

php arrays foreach multidimensional-array

2
推荐指数
1
解决办法
2万
查看次数

Wordpress短信中的PHP

我有一个用于Wordpress的PHP短代码,我们称之为[myshortcode].

短代码允许您输入这样的下载URL [myshortcode download ="http://www.example.com/file.pdf"].

我想在模板文件中使用此短代码,但下载URL是变量.这是可能的,如果是的话,我该怎么做?

我试过这些,但它不起作用......

<?php echo do_shortcode('[myshortcode download="<?php echo $variable['dllink']; ?>"]'); ?>
<?php echo do_shortcode('[myshortcode download="echo $variable['dllink'];"]'); ?>
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

php wordpress shortcode

1
推荐指数
1
解决办法
3139
查看次数

在Ionic Framework(AngularJS)中获取并设置一个复选框

我需要跟踪用户何时更改Ionic中复选框的状态,将其保存到localStorage,然后再使用它再次加载 - 因此它会记住它们的设置.

我的切换代码如下所示:

<li class="item item-toggle">
     National Insurance {{ni_toggle}}
     <label class="toggle toggle-positive">
       <input type="checkbox" ng-model="ni_toggle" ng-click="updateLocalStorage()" id="has_national_insurance" name="has_national_insurance">
       <div class="track">
         <div class="handle"></div>
       </div>
     </label>
  </li>
Run Code Online (Sandbox Code Playgroud)

在我的控制器中,我有:

angular.module('starter.controllers', [])

.controller('SettingsCtrl', function($scope, $ionicPlatform) {
    $ionicPlatform.ready(function() {
    // Ready functions

    });

 $scope.updateLocalStorage = function() {

    window.localStorage.setItem( 'has_national_insurance', $scope.ni_toggle );
    console.log( $scope.ni_toggle );

}

})
Run Code Online (Sandbox Code Playgroud)

但是,它会以控制台的形式注销到控制台undefined.如果我明确设置$scope.ni_toggle = false;它将记录false,并且当我将复选框切换为on时不会更新为true.

编辑:

app.js:

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' …
Run Code Online (Sandbox Code Playgroud)

javascript checkbox angularjs ionic-framework

1
推荐指数
1
解决办法
2万
查看次数