English 中文(简体)
语言 如何在某个职位被汇总时重新打造想象?
原标题:Wordpress jQuery How to reset pagination when a post is toggled?

Surely, someone must have an idea of how t get this to work...

My blog is currently set where I have a custom page that displays only posts in a given category. Each post has a toggle button. When the toggle button is pressed, the post hides (the ENTIRE div is hidden with title and all post content). This works as desired.

The page is also set to display 10 posts per page. If I have 11 posts, the 11th is pushed to page 2. This works as desired.

问题是,当一个员额(第3员额)合并时,我在这个网页上总共剩下9个员额,11个员额留在网页上。 2. 结 论 我本来想要的是,当3个员额被汇总时,11个员额应结转到第1页,第2页基本上消失(因为没有员额可以显示)。

For illustration purposes: Page 1 displays Posts 1,2,3,4,5,6,7,8,9,10 Page 2 displays Posts 11...and so on.

If Post 3 is toggled: Page 1 displays Posts 1,2,4,5,6,7,8,9,10,11 Page 2 disappears (unless there is a post 12,13, etc)

谁知道如何执行?

页: 1

<?php
    $paged = (get_query_var( paged )) ? get_query_var( paged ) : 1;
    $args = array(
         category_name  =>  post ,
         paged  => $paged,
         posts_per_page  => 10
    );
    query_posts($args);
    while (have_posts()) : the_post();
?>

..........the posts are displayed.............

    <?php endwhile; ?>

<script type="text/javascript">
var pager = new Imtech.Pager();
$(document).ready(function() {
pager.paragraphsPerPage = 5; // set amount elements per page
pager.pagingContainer = $( #paginate ); // set of main container
pager.paragraphs = $( div.z , pager.pagingContainer); // set of required containers
pager.showPage(1);
});
</script>

toggle.js

    $(document).on("click", ".toggle", function(){
    postID = $(this).attr( id ).replace( toggle_ ,   );

    // Declare variables
    value =  0 ;

    myajax();

    return false;
});

function myajax(){
    // Send values to database
    $.ajax({
        url:  check.php ,
        //check.php receives the values sent to it and stores them in the database
        type:  POST ,
        data:  postID=  + postID +  &value=  + value,
        success: function(result) {
             $( #post_  + postID).toggle();
                    }
    });
}

pagination.js

var Imtech = {};
Imtech.Pager = function() {
this.paragraphsPerPage = 3;
this.currentPage = 1;
this.pagingControlsContainer =  #pagingControls ;
this.pagingContainerPath =  #contained ;
this.numPages = function() {
    var numPages = 0;
    if (this.paragraphs != null && this.paragraphsPerPage != null) {
        numPages = Math.ceil(this.paragraphs.length / this.paragraphsPerPage);
    }
    return numPages;
};
this.showPage = function(page) {
    this.currentPage = page;
    var html =   ;
    this.paragraphs.slice((page-1) * this.paragraphsPerPage,
        ((page-1)*this.paragraphsPerPage) + this.paragraphsPerPage).each(function() {
        html +=  <div>  + $(this).html() +  </div> ;
    });
    $(this.pagingContainerPath).html(html);
    renderControls(this.pagingControlsContainer, this.currentPage, this.numPages());
}
var renderControls = function(container, currentPage, numPages) {
    var pagingControls =  Page: <ul> ;
    for (var i = 1; i <= numPages; i++) {
        if (i != currentPage) {
            pagingControls +=  <li><a href="#" onclick="pager.showPage(  + i +  ); return false;">  + i +  </a></li> ;
        } else {
            pagingControls +=  <li>  + i +  </li> ;
        }
    }
    pagingControls +=  </ul> ;
    $(container).html(pagingControls);
}
}

因此,是否有任何想法?

问题回答

我的答复是,通过一个jax将现有网页上载员额。

  • there is no problem with generating pagination through javascript and php
  • you have same behaviour for initial load and subsequent loads(when user hides a post)
  • you can make the pagination work with jquery pretty easy




相关问题
Pagination problem

I m using this code for my pagination, and I d like the user s choice to be persistent throughout the site (this has been solved so far)...the only problem now is that the session variable now is ...

mod rewrite problem with 2 parameters

I m trying to rewrite the categoy file of my shop system, I also integrated a pagination so I need to rewrite 2 parameters. it almost works, otherwise I wouldn t be posting in here this is the ...

Issues with pagination in ASP.NET MVC

I am trying to implementation the same pagination that is used in the NerdDinner ASP.NET. I am receiving the following error in my view, whenever the pagination starts to kick in. "A route named ...

Pagination in SQL Server

How do i limit the result of a query (in my case about 60K rows) and select only from the X row to the Y row? If I use ROW_NUMBER() I don t like my query because it involves 2 select queries .. one ...

Cakephp 1.2 Paginator and PassedArgs

Problem: when i have a search resultset with pagination, the links next, prev and numbers do not keep the search parameters. Seems to be a common problem. I searched everywhere on the internet, and ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

热门标签