嘿家伙,所以我试图让所有在wordpress中查询的文章的概述产品功能工作。 这里是我的设置:
<?php $i = 0; $j = 1;?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part('content', get_post_format());
$postid[$i] = get_the_ID();
echo "<input type='hidden' value='".$postid[$i]."' id='hiddenpostitle".$j."' name='hiddenpostitle'/> ";
echo "<input type='hidden' value='".$j."' id='hiddenpostnumfield'/> ";
?>
<script type="text/javascript">
$(function() {
$('.item-post a').click(function() {
var num;
$(this).num = $('#hiddenpostnumfield').val();
var prodname ;
$(this).prodname = $('#hiddenpostitle' + num).val();
$.post('overviewcheck-515adfzx8522', {
'ProdName': prodname
},
function(response) {
},
'json'
);
});
$('.item-post a').colorbox({
opacity:0.3,
href:"../overviewa512454dzdtfa"
});
});
</script>
<?php
$i++;
$j++;
?>
<?php endwhile; endif; ?>
因此,这将得到一堆从WordPress的帖子,并将其粘贴到网页,jQuery代码,然后想获取指定的产品编号在此基础上从.item-post a
点击后
当我运行此我得到的最后的帖子,不是什么都不会发生 - 例如1,2,3,4,5
它会选择总是5.
让我知道,如果这是有道理的,我不,我用正确的思考$(本)。但并不是肯定的是,如果你能给我一只手我将不胜感激:)
更新:
<?php /*query_posts('test');uncategorized*/ $i = 0; $j = 1;?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part('content', get_post_format());
$postid[$i] = get_the_ID();
echo "<input type='hidden' value='".$postid[$i]."' id='hiddenpostitle".$j."' name='hiddenpostitle'/> ";
echo "<input type='hidden' value='".$j."' id='hiddenpostnumfield'/> ";
?>
<?php
$i++;
$j++;
?>
<?php endwhile; endif; ?>
<script type="text/javascript">
$(function()
{
$('.item-post a').each("click" ,function(e) {
$(this).click(function(e) {
var num;
num = $('#hiddenpostnumfield').val();
var prodname ;
prodname = $('#hiddenpostitle' + num).val();
$.post('overviewcheck-515adfzx8522',
{
'ProdName': prodname
},
function(response) {
},
'json'
);
});
});
$('.item-post a').colorbox({opacity:0.3, href:"../overviewa512454dzdtfa"});
});
</script>
我得到一个错误,说点击有没有方法“应用”
好了,所以WordPress的querys后 -
<?php /*query_posts('test');uncategorized*/ $i = 0; $j = 1;?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part('content', get_post_format());
$postid[$i] = get_the_ID();
echo "<input type='hidden' value='".$postid[$i]."' id='hiddenpostitle".$j."' name='hiddenpostitle'/> ";
echo "<input type='hidden' value='".$j."' id='hiddenpostnumfield'/> ";
?>
<?php
$i++;
$j++;
?>
<?php endwhile; endif; ?>
这将创建一个输入字段 - 2级隐藏的和递增值,hiddenpostitle1,hiddenpostitle2等..和hiddenpostnumfield值将增加1,2,3等C。当帖子被张贴。与JQuery代码相比,将选择哪个图像(image-post a),而不是发送到基于传递的数据创建会话的文件,并且colorbox会以概览的形式打开它。
我的问题:
我不能得到通过正确的数据基础上,他们选择什么刺。不管它总是放在现场的最后一个帖子。
好吧,现在我们到了某个地方!
检查它的行动去prodjsoundlighting.com - 点击图像,但仍然越野车,不知道为什么。
<?php /*query_posts('test');uncategorized*/ $i = 0; $j = 1;?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part('content', get_post_format());
$postid[$i] = get_the_ID();
echo "<input type='hidden' value='".$postid[$i]."' id='hiddenpostitle".$j."' name='hiddenpostitle'/> ";
echo "<input type='hidden' value='".$j."' id='hiddenpostnumfield".$j."'/> ";
?>
<?php
$i++;
$j++;
?>
<?php endwhile; endif; ?>
<script type="text/javascript">
$(function()
{
$('.item-post a').each(function(i) {
$(this).on("click", function(e) {
var num;
num = $('#hiddenpostnumfield' +(i+1)).val();
var prodname ;
prodname = $('#hiddenpostitle' + (i+1)).val();
$.post('overviewcheck-515adfzx8522',
{
'ProdName': prodname
},
function(response) {
},
'json'
);
});
});
$('.item-post a').colorbox({opacity:0.3, href:"../overviewa512454dzdtfa"});
});
</script>
So now it is putting up, but it is taking like 3 above what it is suppose...best way is to see it so check it out and let me know.
'$(this).num'应该做什么?也许你的意思是'$(this).data('num',...)'? – Blender
这是什么类型的网址? 'overviewcheck-515adfzx8522' – undefined
该网址是WordPress的一部分,它只是这样做。 –