WordPress的jQuery:如何在div的click事件上使用jquery调用wordpress函数? [英] Wordpress & Jquery: How to call a wordpress function with jquery on click event of a div?
问题描述
我使用导航菜单之类的get_pages()
功能在主题顶部加载了wordpress页面标题:
I loaded wordpress page titles in top of my theme using get_pages()
function like a navigation menu:
<ul>
<?php $pages = get_pages('child_of=0&parent=0&echo=0');
foreach($pages as $page){
echo '<li class=pages id=menu_'.$page->ID.' >';
echo $page->title;
echo '</li>';
}
?>
</ul>
注意:
- 打印的
page titles
没有链接到页面. - 和所有
<li>
标签具有相同的class=pages
- ,每个
<li>
标签都有一个与当前$page->ID
相关的
id
- that the printed
page titles
doesn't have link to the page. - and all
<li>
tags have sameclass=pages
- and each
<li>
tag has anid
related to current$page->ID
,并且我已经使用Jquery
调用了一个函数,以在单击每个<li>
标记时显示每个页面的子级,并带有id
属性的最后两个字符,如下所示:
and I've used Jquery
for call a function to show children of each page on click of each <li>
tag with 2 last character of id
attribute like below:
<script type=text/javascript>
$(document).ready(function(){
$('.pages').click(function(){
var id = $(this).attr('id');
id = id.substring(5,7);
$('body').append(<?php get_pages('child_of=id&echo=1'); ?>);
});
});
</script>
Bu它不起作用,页面加载时似乎调用了PHP block code
.
请帮助我在每个<li>
的click事件上调用wordpress get_pages
函数,以加载页面的子页面.
Bu It doesn't work, it seems the PHP block code
called when page loaded.
Please help me to call the wordpress get_pages
function on click event of each <li>
to load children of pages.
推荐答案
没有人会为您做这件事,但是这里有一些资源可以帮助您弄清楚并引导您走上正确的路:
Nobody is going to do this for you, but here are a few resources that may help you figure it out and lead you down the right path:
AJAX简介: http://www.w3schools.com/Ajax/ajax_intro.asp
AJAX简介(视频): http://www.youtube.com/watch?v=tJXLRLDWjn4
Intro to AJAX (video): http://www.youtube.com/watch?v=tJXLRLDWjn4
您需要了解有关AJAX以及如何将其与WordPress一起使用的所有信息: http://codex.wordpress.org/AJAX 提示:请点击开发者信息"部分下的链接.
Everything you need to know about AJAX and how to use it with WordPress: http://codex.wordpress.org/AJAX Hint: follow the links under the "Developer Information" section.
这篇关于WordPress的jQuery:如何在div的click事件上使用jquery调用wordpress函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!