2012-02-17 66 views
0

我在我的WordPress模板使用同位素(JQuery的),我想使用添加項目選項(前置)。你可以在這裏看到:http://isotope.metafizzy.co/demos/adding-items.html顯示PHP代碼中的JavaScript函數

,我使用作品的腳本:

$('#prepend a').click(function(){ 
     var $newItems = $(<div>Hello World</div>); 
     $('#container').prepend($newItems) 
     .isotope('reloadItems').isotope({ sortBy: 'original-order' }); 
       }); 

當我點擊此鏈接:

<li id="prepend"><a href="#">More</a></li> 

該腳本將你好我的網頁上。

的問題是,我不希望添加一個div,但我想補充一個帖子。

這裏是郵政代碼,我想用:

<?php query_posts('category_name=offers'); while (have_posts()) : the_post(); ?> 
<a href="<?php echo get_permalink(); ?>" class="element <?php $posttags = get_the_tags(); 
if ($posttags) { foreach($posttags as $tag) { echo $tag->slug . " "; } } ?>"> 

<div>       
<?php the_title("<h3>", "</h3>"); ?> 

</div> 
</a> 
<?php endwhile;?> 

你知道一種方法,使它的工作原理?

(對不起,我可怕的英語......)

回答

1

你需要Ajax。這個工作方式是,你從服務器獲取你想要的,然後prepend

var postsData = { param1: "value", param2: "value" }; 
$.get('www.example.com/get_posts.php', postsData, 
    function(content) { 
    var $newItems = $('<div/>').html(content); 
    $('#container').prepend($newItems); 
    } 
); 

並製作一個打印HTML片段的get_posts.php。您可以從$_GET[]得到的postsData結構的東西,或者你可以完全離開postsData參數,如果你不需要任何。

+0

你必須做出或使用你的WordPress博客的網址,以獲取渲染您的文章。嘗試找到並閱讀關於WordPress的帖子ajax的一些文檔。 – Sebastien 2012-02-17 14:57:17

+0

(我不知道如何,但我刪除了我的評論...)。 我會環顧Ajax和WordPress。謝謝你們的幫助! – 2012-02-19 21:08:42

0

如果你想一個PHP的渲染,你必須使用一個Ajax請求。你習慣了這個可怕的名字'AJAX'嗎?

隨着使用jQuery Ajax調用:http://api.jquery.com/jQuery.get/,你可以得到,如果後呈現的HTML,並將其寫入您的網頁上。

你是否瞭解?

勒布

+0

我聽說了很多關於Ajax的知識,但我真的需要做更深入的挖掘...我會看看你的鏈接。 Merci Seb – 2012-02-17 14:54:39