Sicario
Members
-
Joined
-
Last visited
Reputation Activity
-
Sicario reacted to fisicx in Help me to add load more button in my category.phpIt's because you are not formatting the query correctly:
$query = new WP_Query( array( 'posts_per_page' => 5, 'cat' => 99 ) ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); //do something; } wp_reset_postdata(); } It's all detailed in the links I provided.
Once you understand how the loop works you will discover a whole load of WP functions you can use.
-
Sicario reacted to fisicx in Help me to add load more button in my category.phpThat's a very complicated way to do this.
If you just use a WP query you can set the category and limit the number of posts. You then just add the prev/next navigation.
https://css-tricks.com/snippets/wordpress/run-loop-on-posts-of-specific-category/
https://developer.wordpress.org/reference/functions/query_posts/
Wordpress has done all the hard work for you - no need to reinvent the wheel.
-
Sicario reacted to Jack in Help me to add load more button in my category.phpYour best bet here would be to do the whole lot using Javascript and avoid mixing PHP and JS together, otherwise it's going to be tricky to keep track of state of already loaded items. I think for this I would use the Wordpress API and pull out all posts under that category, then use posts per page and offset to change the items displayed https://developer.wordpress.org/rest-api/using-the-rest-api/pagination/. Your load more will need to work out how many items are currently displayed and use that as your offset every time a new request is made.