University of Southern California

ITS Information Technology Services

Building a Custom Results Page

ITS Web Services has developed a PHP script which parses the XML results from USC's Google Site Search (GSS) and and presents them as CSS-tagged XHTML. Site maintainers can design their own results pages and include the PHP script in the location where search results should be displayed. The CSS tags allow designers to apply custom styles to their search results.

A working demo can be viewed at http://www.usc.edu/search/gss-demo/.

Procedure

  • Design your custom results page. It should be named with the '.php' extension.

  • Copy the following PHP code to the location on your page where search results should be displayed:
    <?php 
    include ('/www/assets/php/curl_inc.php');
    $ref='http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
    $querystr = $_SERVER['QUERY_STRING'];
    curl_inc ('http://web-app.usc.edu/webapps/gss/index.php?ref=
    '.$ref.'&'.$querystr); //do not break line
    ?>
    
    Note: This exact code will only work for websites on www.usc.edu. If you would like to use the included PHP script on another server, you will need to revise the code. For instance, if your server uses PHP and allows "HTTP includes," then there is no need to use PHP curl and you could instead use the code:
    <?php 
    $ref='http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
    $querystr = $_SERVER['QUERY_STRING'];
    include ('http://web-app.usc.edu/webapps/gss/index.php?ref=
    '.$ref.'&'.$querystr); //do not break line
    ?> 
  • If you would like to capture the search term for display in the page title or elsewhere, include the following PHP code at the top of your results page:
    <?php
    $remquery = $_SERVER['QUERY_STRING'];
    parse_str($remquery,$testarray);
    if ($testarray['q']) {
      $query_term = $testarray['q']; 
    }
    ?>
    
    and then display the search term with the code <?php echo $query_term ?>.

  • Create a CSS stylesheet to define how elements of the search results will be displayed. The stylesheet used for the demo can be viewed at http://www.usc.edu/search/gss-demo/search.css. A description of the CSS markup in search results is also provided.
  • Last updated:
    November 02, 2010

    Web Publishing Documentation

    The use of all USC computing resources is governed by the USC Computing Policies.