內容簡介
以下是我建議如何使用這個類別的方式。
啟用此外掛或將該類別包含在您自己的外掛程式檔案中。
當您開始渲染帶有文章列表的頁面時,使用引數陣列來實體化分頁類別,例如: $pargs = array( ‘get_per_page_key’ => ‘perpage’, ‘get_paged_key’ => ‘current_page’, ‘per_page’ => 15 ); $pagination = new BBG_CPT_Pag( $args );
建構查詢引數(用於 query_posts() 或 WP_Query),您可以使用類別從 $_GET 參數中獲取您的分頁引數。例如: $args = array( … ‘posts_per_page’ => $pagination->get_per_page, ‘paged’ => $pagination->get_paged … ); query_posts( $args );
在啟動查詢後,使用 setup_query() 方法填充類別的其餘部分。如果您使用 query_posts(),您不需要引數:$pagination->setup_query(); 如果您使用 new WP_Query,您必須傳遞該查詢物件:$my_query = new WP_Query; $pagination->setup_query( $my_query );
隨後,您就可以使用許多有趣的方法,例如 $pagination->paginate_links(); $pagination->currently_viewing_text();
外掛標籤
開發者團隊
原文外掛簡介
Here’s how I recommend using the class.
Either activate this plugin, or include the class in your own plugin file.
When you start to render the page with the post list, instantiate the pagination class, using an argument array if you’d like: $pargs = array( ‘get_per_page_key’ => ‘perpage’, ‘get_paged_key’ => ‘current_page’, ‘per_page’ => 15 ); $pagination = new BBG_CPT_Pag( $args );
When constructing your query arguments (for query_posts() or WP_Query), you can use the class to get your pagination arguments out of the $_GET parameters. For instance: $args = array( … ‘posts_per_page’ => $pagination->get_per_page, ‘paged’ => $pagination->get_paged … ); query_posts( $args );
After firing the query, use the setup_query() method to populate the rest of the class. If you used query_posts(), you don’t need an argument: $pagination->setup_query(); If you use new WP_Query, you’ll have to pass the query object: $my_query = new WP_Query; $pagination->setup_query( $my_query );
Then you can use all sorts of fun methods, like $pagination->paginate_links(); $pagination->currently_viewing_text();
