dou7466 2014-08-09 05:58 采纳率: 0%
浏览 51

如何保持url参数Wordpress

I create my own searching at my website and I have create page search result page which contains <php> code, I use plugin PHP-Exec at my search result page. I create pagination, but it seems not work properly. When I click "Next" for next result of my own searching the url parameter is redirect to wrong url.

The Url should be :

http://inindonesia.org/hasil-pencarian?phrase=sofa+bed&page=1

But, it redirect to :

http://inindonesia.org/hasil-pencarian/1?phrase=sofa bed

It is wrong URL exactly, and I feel stuck because automatically it can affect the search results of my own search :( . For information, I use Wordpress Multisite, any ideas for keeping my URL parameter?

Here my code :

<?php
$dbhost = 'myhost';
$dbuser = 'mydbuser';
$dbpass = 'mydbpass';
$hasil = $_GET[phrase];
$type = str_replace(' ','+',$hasil);
$rec_limit = 2;

$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ){
  die('Database tidak terkoneksi' . mysql_error());
}

mysql_select_db('mydb');
    $sql = "SELECT count(wp_mp_term_relationships.post_id) FROM `wp_mp_term_relationships` INNER JOIN wp_mp_products ON wp_mp_products.id = wp_mp_term_relationships.post_id INNER JOIN wp_mp_terms ON wp_mp_terms.term_id = wp_mp_term_relationships.term_id WHERE wp_mp_terms.name = '$hasil'";   
    $retval = mysql_query( $sql, $conn );

if(! $retval ){
  die('Tidak dapat Menerima Data: ' . mysql_error());
}

    $row = mysql_fetch_array($retval, MYSQL_NUM );
    $rec_count = $row[0];

if( isset($_GET{'page'} ) ){
   $page = $_GET{'page'} + 1;
   $offset = $rec_limit * $page ;
}else{
   $page = 0;
   $offset = 0;
}

$left_rec = $rec_count - ($page * $rec_limit);
$query = "SELECT * FROM `wp_mp_term_relationships` INNER JOIN wp_mp_products ON wp_mp_products.id = wp_mp_term_relationships.post_id INNER JOIN wp_mp_terms ON wp_mp_terms.term_id = wp_mp_term_relationships.term_id WHERE wp_mp_terms.name = '$hasil' LIMIT $offset, $rec_limit";
$query_retval = mysql_query( $query, $conn );

if(! $query_retval ){
  die('Tidak dapat menerima data ' . mysql_error());
}

while($result = mysql_fetch_array($query_retval, MYSQL_ASSOC)) {
    echo "<h3><a href=" . $result[post_permalink] . " target=_blank>" . $result[post_title] . "</a></h3>";
    $content = $result[post_content];
    $content_len = strlen($content);
    if ( $content_len > 150 ){
        echo "<div style='margin-left: 26px; margin-top: 6px; margin-bottom: -26px;'><h3 style='font-size: 13px; line-height: -0.5'>" . substr($content, 0, 150) . " ...<a href=" . $result[post_permalink] . " target=_blank> (more)</a></h3></div>";
    }else{
        echo "<div style='margin-left: 26px; margin-top: 6px; margin-bottom: -26px;'><h3 style='font-size: 13px; line-height: -0.5'>" . $content . "</h3></div>";
    }
    echo "<hr>"; 
 }

if( $page > 0 ){
   $last = $page - 1;
   echo "<a href=\"$_PHP_SELF?phrase=$type&page=$last\">Last 5 Records</a> |";
   echo "<a href=\"$_PHP_SELF?phrase=$type&page=$page\">Next 5 Records</a>";
}else if( $page == 0 ){
   echo "<p>" . $_PHP_SELF . "?phrase=" . $type . "&page=" . $page . "</p>";
   echo "<a href=\"$_PHP_SELF?phrase=$type&page=$page\">Next 5 Records</a>";
}else if( $left_rec < $rec_limit ){
   $last = $page - 1;
   echo "<a href=\"$_PHP_SELF?phrase=$&page=$last\">Last 5 Records</a>";
}

mysql_close($conn);
?>
  • 写回答

1条回答 默认 最新

  • duandang6352 2014-08-09 06:04
    关注

    Don't use key "page" for pagination. Instead use other keys to identify your page number because it is your custom coding for search.

    When you pass page in query string, wordpress will detect as page parameter and redirect to default URL structure for paging (http://inindonesia.org/hasil-pencarian/1)

    When you change key for your pagination, wordpress will not recognize paging and won't change your URL.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度