2013-07-11 25 views
1

首先,我已经遍及Google,StackExchange和Codex,但仍然无法解决我的问题。它可能很简单;我不确定。我有以下函数列出自定义帖子。该页面有多个查询,但只有一个(这一个)使用分页。它在首页 - 设置为静态。我不能得到以前的帖子链接显示

下面是函数:

function wight_listings() 
{ 
    global $wp_query; 
    global $page; 

    $backup = $wp_query; 
    $wp_query = NULL; 
    $cur_page = $page; //get_query_var('page') ? get_query_var('page') : 1; 

    $args = array(
      'post_type' => array('wight_listing'), 
      'posts_per_page' => 7, 
      'paged'=>$cur_page 
     ); 
    $wp_query = new WP_Query($args); 
    ?> 
    <?php if ($wp_query->have_posts()) : ?> 
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?> 
     . 
     . 
     . 
    <?php endwhile; ?> 
     <div id="nav-posts" style="margin-top: .5em;"> 
      <div style="float:left;"><?php previous_posts_link('Previous Listings &laquo;'); ?></div> 
      <div style="float:right;"><?php next_posts_link('&raquo; Next Listings'); ?></div> 
      <div class="clear"></div> 
     </div> 
<?php else: ?> 
    <p>Oh no! There's nothing to show. :(</p> 
<?php endif; ?> 
<?php 
    $wp_query = NULL; 
    $wp_query = $backup; 
} 

“下一步列表”链接显示了只连接到第2页无论是什么网页上我和“上一个第”链接从未露面。

我在做什么错?

WP:3.5.2

+0

你错过了你的开启和关闭的PHP标记,或者它是复制/粘贴问题? – Bun

+0

感谢您的回复。究竟在哪里?我把这个功能缩短了,因为它很长。 – Joe

+0

'<?php $ wp_query = NULL; $ wp_query = $ backup;''在您提供的代码中永远不会关闭。但是如果你没有提供完整的代码,这可能是正确的。 – Bun

回答

1

我找到了解决方案。我查看了/wp-includes/link-template.php并找到了对我的mysery负责的两个函数。我将它们复制到我的主题并修改了一下,一切都非常有效。

function wight_get_previous_posts_page_link($cur_page) 
{ 
    if ($cur_page > 1) 
    { 
     $nextpage = intval($cur_page) - 1; 
     if ($nextpage < 1) 
      $nextpage = 1; 
     return '<a href="' . get_pagenum_link($nextpage) . '">&laquo; Previous Listings</a>'; 
    } 
} 

function wight_get_next_posts_page_link($cur_page, $max_page) 
{ 
    $paged = $cur_page; 

    if (!$paged) 
     $paged = 1; 
    $nextpage = intval($paged) + 1; 

    if ($max_page >= $nextpage) 
     return '<a href="' . get_pagenum_link($nextpage) . '">Next Listings &raquo;</a>'; 

} 

使用那些来代替previous_posts_link和next_posts_link。

<?php echo wight_get_previous_posts_page_link($cur_page); ?> 
<?php echo wight_get_next_posts_page_link($cur_page, $query->max_num_pages); ?> 
+0

做好了回来发布你的答案和解释。记住你应该接受你自己的答案,以表明它已经被解决了 - 接下来是如何接受和回答。 http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work欢迎来到SO :) – McNab

+0

哦,很酷。谢谢!我接受了。 – Joe

相关问题