Jquery 为Wordpress插件添加同位素项目
这里有个棘手的问题(我想)。。我正在使用插件将我的帖子拉入同位素网格。所有的工作都很好,除了我不能让任何一个工作。以下是我正在尝试的内容(目标是向网格中添加三篇新帖子):Jquery 为Wordpress插件添加同位素项目,jquery,wordpress,jquery-isotope,Jquery,Wordpress,Jquery Isotope,这里有个棘手的问题(我想)。。我正在使用插件将我的帖子拉入同位素网格。所有的工作都很好,除了我不能让任何一个工作。以下是我正在尝试的内容(目标是向网格中添加三篇新帖子): var$container=$('.mintthemes_同位素_container'); 变量$items=$(''); $('#insert')。单击(函数(){ $('.mintthemes_同位素_容器')。同位素('insert',$items); }); $container.imagesLoaded(函数(){
var$container=$('.mintthemes_同位素_container');
变量$items=$('');
$('#insert')。单击(函数(){
$('.mintthemes_同位素_容器')。同位素('insert',$items);
});
$container.imagesLoaded(函数(){
$container.com({
animationEngine:“最佳可用”,
transformsEnabled:是的,
项目选择器:'.hentry',
砌体:{
列宽:1,
排水沟宽度:5
},
});
我想我的问题在于我定义的$items是什么。上面的代码添加了三个新的容器,样式正确,但没有内容。我想我需要调用实际的posts,而不是“.hentry”但我不确定如何在插件提供的.js文件中实现这一点。以下是如何在我的index.php中调用帖子:
<?php mintthemes_isotopes(); ?>
<?php
// Blog post query
$linksPosts = new WP_Query();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts( array( 'post_type' => 'post', 'paged'=>$paged, 'showposts'=>3) );
if (have_posts()) : while (have_posts() ) : the_post();?>
<div <?php post_class(); ?>>
<div class=".mintthemes_isotopes_container">
<div class=".isotope-item">
<p><a href="<?php the_permalink(); ?>" title="<?php the_title();?>"><?php the_title();</p></a>
</div> <!-- /isotope item -->
</div> <!--/.mintthemes_isotopes_container-->
</div> <!-- /.post_class -->
<?php endwhile; endif; ?>
我不能在外部.js文件中调用php post_class();对吗?有没有其他方法可以调用这些帖子?任何想法都值得赞赏。您可以轻松插入更多元素,就像您所做的那样。不起作用的部分是添加页面上不存在的元素 要使WordPress帖子在页面上“存在”,PHP必须以某种方式对其进行查询 您可以使用自定义查询-就像使用WP_query()一样: 您还可以使用诸如get_posts之类的功能: 但是,除非您以某种方式通过WP查询它们,否则它们在页面上不存在,并且无法在运行时添加 您可以单独查询所需的额外帖子,并将它们放在一个div中,CSS设置为display:none 这样,您就可以使用JS引用它们,因为它们将存在于页面上 大概是这样的:
global $post;
//First Query
$args = array(
'post_type' => "post",
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => 'my_category_name,
'operator' => 'IN'
)
)
);
$posts_main_group = get_posts($args);
foreach($posts_main_group as $post) :
?><div class="<?php post_class(); ?>" style="block;"><?php the_title(); ?></div><?php
endforeach;
//Second hidden query
$args = array(
'post_type' => "post",
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => 'my_hidden_category_name_with_extra_posts,
'operator' => 'IN'
)
)
);
$posts_extra_group = get_posts($args);
foreach($posts_extra_group as $post) :
?><div class="<?php post_class(); ?>" style="display:none;"><?php the_title(); ?></div><?php
endforeach;
global$post;
//第一个问题
$args=数组(
“帖子类型”=>“帖子”,
“tax_query”=>数组(
'关系'=>'和',
排列(
“分类法”=>“类别”,
“字段”=>“id”,
“术语”=>“我的类别名称”,
'运算符'=>'输入'
)
)
);
$posts\u main\u group=get\u posts($args);
foreach($posts\u main\u组为$post):
?>
global $post;
//First Query
$args = array(
'post_type' => "post",
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => 'my_category_name,
'operator' => 'IN'
)
)
);
$posts_main_group = get_posts($args);
foreach($posts_main_group as $post) :
?><div class="<?php post_class(); ?>" style="block;"><?php the_title(); ?></div><?php
endforeach;
//Second hidden query
$args = array(
'post_type' => "post",
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => 'my_hidden_category_name_with_extra_posts,
'operator' => 'IN'
)
)
);
$posts_extra_group = get_posts($args);
foreach($posts_extra_group as $post) :
?><div class="<?php post_class(); ?>" style="display:none;"><?php the_title(); ?></div><?php
endforeach;