0

在 WP 主题中,我有post.php(用于单个帖子项目)和blog.php(用于博客布局)。在单个帖子中,CSS 类通过 jQuery(点击时)添加到帖子 div。

如何从单个帖子(post.php)中获取这些类(字符串)并在 blog.php 中使用它们?

例如。单个帖子 (post.php) 打印此 html

<article class="single-post post-1">
<p>sometext</p>
<a>click</a>
</article>
<script>
jQuery("a").click(function(){
   jQuery("article").addClass("singleClass");
});
</script>

博客文章 (blog.php)

<article class="blog-post post-1">
<p>sometext</p>
</article>
<article class="blog-post post-2">
<p>sometext</p>
</article>

并且还从单个帖子 1 中获取课程并将其添加到博客帖子 1、帖子 2 到帖子 2 等。第一次尝试 AJAX,所以我不知道该怎么做。post.php 中的 jQuery

var postClass = voteText+'-'+voteNumber; //some variables declared earlier
jQuery.ajax({
    type: "POST",
    url: "ajax-class.php", //or /wp-admin/admin-ajax.php? This mean that data is posted to this file?
    data: { 'dataString': postClass },
    cache: false,
    success: function() {
        alert("Classes: "+postClass); // alert goes fine
    }
});

现在我需要从 ajax-class.php 获取数据?

<?php  echo 'Classes: '. $_POST['postClass']; ?>

这是行不通的。如果有人能指出我正确的方向。文档和东西。谢谢

4

0 回答 0