2014-05-14 24 views
0

我正在使用wordpress的「json-API」插件,我正試圖將該信息稱爲phonegap應用程序。wordpress json api phonegap handlebars custom_fields

我正在關注http://alexbachuk.com/wordpress-and-phonegap-part3/的帖子,我正在嘗試瞭解如何在我的內容中調用custom_fields。

我已經包含了這樣的自定義字段: 'http://www.example.com/?json=get_recent_posts&custom_fields=store-icon'在ajax請求。

Ajax請求如下:

product: function(){ 
     function getProducts() { 
      var dfd = $.Deferred(); 

      $.ajax({ 
       url: 'http://delectable.site40.net/blog/?json=get_recent_posts&custom_fields=store-icon', 
       type: 'GET', 
       dataType: 'json', 
       success: function(data){ 
        var source = $("#product-template").html(); 
        var template = Handlebars.compile(source); 
        var blogData = template(data); 
        $('#product-data').html(blogData); 
        $('#product-data').trigger('create'); 
        dfd.resolve(data); 

       }, 
       error: function(data){ 
        console.log(data); 
       } 
      }); 
      return dfd.promise(); 
     }; 

     getProducts().then(function(data){ 
      $('#all-posts').on('click','li', function(e){     
       localStorage.setItem('postData', JSON.stringify(data.posts[$(this).index()])); 
      }); 
     }); 


    } 

和模板目前看起來是這樣的:

<script id="product-template" type="text/x-handlebars-template"> 
      <ul data-role="listview" data-icon="false" class="mainContent" data-theme="a" id="all-posts"> 

      {{#each posts}} 

       <li class="center productss"><p class="photo circle center" style="margin-left: 31%;"><img src="{{thumbnail}}" width="85" height="57" /></ br><a data-ajax="false" data-transition="slide" href="single.html?{{@index}}"><h3 class="main_product">{{title}}</h3></a></ br><h5 class="left">R4200-00</h5><h5 class="right"><img src="{{custom_fields[0].url}}" width="150" height="20" /></h5></p></li> 

      {{/each}} 
      </ul> 
     </script> 

我怎麼會去將那到我的HTML。 alexbachuk.com文章使用句柄來解析json,所以帖子標題以{{title}}和縮略圖形式輸出爲{{thumbnail}}。有沒有類似的方式輸出custom_fields?

回答

0

是的。

用途:

{{custom_fields.fieldname}}