Jump to content
php.lv forumi
  • 0

Wordpress + Wysija (JSON): Kļūda izvadot "posts" masīvu.


WHOAMi

Question

Labdien.

Saskāros ar sekojošu kļūdu. Mēģinu mazliet izmainīt Wordpress spraudni Wysija, nomainot pievienojamā satura formu.

Īsumā - iepriekš kodā ar vienu klikšķi varēja izvēlēties tikai vienu rakstu.. Katram elementam bija pievienots iepriekš selectArticle(), lai pie klikšķa tas pievienotos saturam dinamiski.

Pievienoju checkbox inputu un submit pogu, kas izsauc selectArticle() funkciju, to noņemot pārējiem elementiem un pievieno saturam izvēlētos (ieķeksētos rakstus).

Nekādīgi nevaru saprast kur ir kļūda un vispār, kā panākt multiple select, single select vietā. Ceru uz php.lv guru palīdzību. :)

 

Paldies jau iepriekš.

 

Re, kods:

function selectArticle(s) {
    window.parent.WysijaPopup.success(allposts[s].html)
}
var allposts = new Array, query_offset = 0, wysappend = 0, totalReached = !1;
jQuery(function(s) {
    function t() {
        var t = "<ul class='loading-ul'>";
        t += "<li><img title='Loading' alt='loading' src='../wp-content/plugins/wysija-newsletters/img/wpspin_light.gif' /></li>", t += "</ul>", wysappend ? s("#search-results").append(t) : s("#search-results").html(t), wysijaAJAX.task = "get_articles", wysijaAJAX.search = s("#search-box").val(), wysijaAJAX.cpt = s("select#cpt").val(), wysijaAJAX.status = s("select#status").val(), wysijaAJAX.query_offset = query_offset, s("#get-full-post").is(":checked") ? wysijaAJAX.fullarticle = 1 : delete wysijaAJAX.fullarticle, wysijaAJAX._wpnonce = s("#wysijax").val(), jQuery.ajax({type: "POST", url: wysijaAJAX.ajaxurl, data: wysijaAJAX, success: e, error: l, dataType: "json"})
    }
    
    function e(t) {
        if (t.result.result) {
            for (var e in t.result.posts)
                allposts.push(t.result.posts[e]);
            var l, a = '<ul class="posts">';
            s.each(t.result.posts, function(s, t) {
                l = {src: null, alt: "", title: ""}, null !== t.post_image && (l.src = t.post_image.src, l.alt = t.post_image.alt, l.title = t.post_title);
                var e = query_offset + s;
                a += '<li class="clearfix">', a += '<div class="article-cpt">', a+= '<div class="checkbox" style="float:left;padding:8px 15px 8px 0px;"><input type="checkbox" name="checkbox" /></div>', null !== l.src && (a += '<div class="thumbnail"><img width="60" title="' + l.title + '" src="' + l.src + '" alt="' + l.alt + '" />' + "</div>"), a += "<h3>" + t.post_title + '</h3></div><div class="cpt-type">' + t.post_type + " - <small>" + t.post_status + "</small></div></li>"
            }), a += "</ul>", a+= '<input type="submit" onClick="selectArticle(' + e + ')" />';
        } else if (t.result.append)
            var a = "";
        else {
            var a = "<ul>";
            a += "<li><strong>" + t.result.msg + "</strong></li>", a += "</ul>"
        }
        s("#search-results").find(".loading-ul").remove(), t.result.append ? "" !== a && s("#search-results").append("<hr/>" + a) : s("#search-results").html(a), wysappend = 0, totalReached = parseInt(t.result.total) === s("ul.posts li").length ? !0 : !1
    }
    
    
    
    function l(s) {
        wysappend = 0, alert("Request error not JSON:" + s.responseText)
    }
    
    
    
    function a() {
        query_offset += 10, wysappend = 1, t()
    }
    
    
    
    s("#gallery-form").submit(function() {
        return query_offset = 0, allposts = new Array, t(), !1
    }), s("#get-full-post").change(function() {
        return query_offset = 0, allposts = new Array, t(), !1
    }), s("select#cpt").change(function() {
        return query_offset = 0, allposts = new Array, t(), !1
    }), s("select#status").change(function() {
        return query_offset = 0, allposts = new Array, t(), !1
    }), s("#show-advanced-controls").click(function() {
        s("#search-advanced").toggle()
    }), s(function() {
        t()
    }), s(window).scroll(function() {
        totalReached === !1 && allposts.length >= 10 && !wysappend && s(window).scrollTop() === s(document).height() - s(window).height() && a()
    })
});
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Guest
This topic is now closed to further replies.
×
×
  • Create New...