我已经编写了一些php代码并使用了该类。标页码php,我可以根据我在代码中设置的每页最大帖子数对其分页。这很有效。
然而,它只返回了11个帖子,我知道我有186个帖子,我太困了,任何帮助都将不胜感激。
这是我的代码:
<?php
define ("WP_USE_THEMES", false);
define ("MAX_PER_PAGE", 3);
include ("wp-load.php");
include ("pagination.class.php");
// posts_per_page=-1
$query = new WP_Query(array(\'post_type\' => \'any\'));
$posts = $query->get_posts();
$sAllTitles = array();
$sAllDates = array();
$sAllContent = array();
$iCount = 0;
foreach($posts as $post)
{
$sAllTitles[$iCount] = $post->post_title;
$sAllDates[$iCount] = $post->post_date;
$sAllContent[$iCount]= $post->post_content;
$iCount++;
}
$iCount = 0;
foreach($posts as $post)
{
$PostData[] = array(
\'PTitle\' => $sAllTitles[$iCount],
\'PDate\' => $sAllDates[$iCount],
\'PCont\' => $sAllContent[$iCount],
);
$iCount++;
}
?>
<html>
<head>
</head>
<body>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>BLOG POSTS</title>
<style>
body
{
font-family : Arial;
font-size : 12px;
}
h2
{
font-family : Arial;
font-size : 18px;
color : #3279BB;
}
.InfoText
{
font-family : Arial;
font-size : 14px;
}
.pagination
{
clear : both;
padding : 20px 0;
position : relative;
font-size : 11px;
line-height : 13px;
}
.pagination span, .pagination a
{
display : block;
float : left;
margin : 2px 2px 2px 0;
padding : 6px 9px 5px 9px;
text-decoration : none;
width : auto;
color : #fff;
background : #555;
}
.pagination a:hover
{
color : #fff;
background : #3279BB;
}
.pagination .current
{
padding : 6px 9px 5px 9px;
background : #3279BB;
color : #fff;
}
</style>
</head>
<?php
if (count($PostData))
{
$pagination = new pagination($PostData, (isset($_GET[\'page\']) ? $_GET[\'page\'] : 1), MAX_PER_PAGE);
$pagination->setShowFirstAndLast(true);
$PostPages = $pagination->getResults();
echo $pageNumbers = \'<div class="pagination">\'.$pagination->getLinks().\'</div>\';
if (count($PostPages) != 0)
{
print("<br/>");
foreach ($PostPages as $PostArray)
{
print (\'<div class=\\"post\\">\');
print (\'<h2>\' . $PostArray[\'PTitle\'] . \'</h2>\');
print (\'<div class=\\"InfoText\\">\' . $PostArray[\'PDate\'] . \'</div>\');
print (\'<div class=\\"entry BlogText\\">\');
print ($PostArray[\'PCont\']);
print (\'</div>\');
print (\'</div>\');
print (\'<br/>\');
}
print ($pageNumbers);
print ("<br/><br/><br/>");
}
}
wp_reset_query();
wp_reset_postdata();
?>
</body>
</html>