Skip to:
Content
Pages
Categories
Search
Top
Bottom

Pagination Issues with Custom Component


  • stoi2m1
    Participant

    @stoi2m1

    I have built a custom component which works with custom post types. I have the loops and queries all working to display my component within a Directory and within the members/custom-component section of the site. My queries work and filter to friends, fans and my items.

    There are pagination links displaying at the bottom of the page which add ?item_page=2 but when I click the same results are redisplayed. The pages are loaded by ajax. I hav found a way to get other ajax pages to load by adding in an action to catch the ajax request and executing a function to figure out which template file to load based on the variables posted during that ajax request. Now the ajax requests post a page number too, but I dont understand how to turn that into an argument that my loop can handle.

    Im also looking for how to get this to display in pretty permilinks too so that /page/2 is displayed rather then ?itempage=2

    Thanks,
    Jesse

Viewing 7 replies - 1 through 7 (of 7 total)

  • stoi2m1
    Participant

    @stoi2m1

    Update: Looks like I was missing a couple query args within my class for paged and per_page. Now I can enter the url manually and show the proper results with the proper pagination links displayed.

    Now my issue is getting things working with ajax. Im familiar with using wp_ajax_my_action. Im using this to determine what action item Im on and calling the proper template file. What Im having an issue with is passing the page variable to that template file and then my class.

    Jesse


    Henry Wright
    Moderator

    @henrywright

    Hi @stoi2m1

    What Im having an issue with is passing the page variable to that template file and then my class

    Do you mean you’re having an issue passing variables to your AJAX script (e.g. success or error functions) or are you trying to pass them from your AJAX script to your PHP function?


    stoi2m1
    Participant

    @stoi2m1

    I captured the ajax variable $_POST[‘page’] into a php variable within my ajax callback function. Where I am using locate_tempalte to insert my content area and loops.

    Now Im trying to get the page variable into the next iteration of my bp_component_has_items function. This is where Im pretty sure Im going about things the wrong way because I have found that my $item_template is not empty so Im not fetching the next page of posts.


    Henry Wright
    Moderator

    @henrywright

    Sounds like i’m doing the same thing as you. See this tutorial which works very well. I use a modified version of it everywhere on my site – to load more posts, load more members, load more messages and even load more search results. Hope it helps.

    Load Next WordPress Posts With AJAX


    stoi2m1
    Participant

    @stoi2m1

    Thanks for the article although it didnt have my answer it did help push me in a decent direction.

    I found that because my $item_template was already filled with the current pages data I had to compare the posted page to the current page and clear the variable if posted page was different then the current. Then my args would be evaluated and the query would be ran. Im sure this has to do with something with the skeleton custom component being set up a little different then the buddypress core components. Ive looked and compared and now that I have my queries working Im not really interested in why they are different.


    Henry Wright
    Moderator

    @henrywright

    @stoi2m1 what do you think the Skeleton component could be doing differently to the core component(s)?


    stoi2m1
    Participant

    @stoi2m1

    from what i can tell in the template.php bp_example_has_items() function it checks the items_template to be empty and runs a query if so. If a page has been fetch the template is not empty and the same results are returned.

    I just passed the page variable and compared it to the items_template and made it null if the page was different

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Pagination Issues with Custom Component’ is closed to new replies.
Skip to toolbar