dpd7195 2013-08-27 19:31
浏览 23

将CSS类从一个页面设置为另一个页面 - WordPress,jQuery AJAX

In WP theme I have post.php (for single post item) and blog.php (for blog layout). On single post, CSS classes are added to post div via jQuery (on click).

How to get that classes (strings)from single post (post.php) and use them in blog.php?

EG. Single post (post.php) print this 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 posts (blog.php)

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

And also to get class from single post 1 and add it to blog post 1, post 2 to post 2, etc. First time trying AJAX, so I'm not sure what to do. jQuery in post.php

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
    }
});

now I need to GET data from ajax-class.php?

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

This is not working. If someone could just point me to right direction. Documentation and stuff. Thanx

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度