Archive Page

Archive Page Example

Welcome to the Archive Page sample code. This code is meant to be added to your existing website and will integrate Listpipe content seamlessly with your own design, increasing your SEO and client interest.

This article will assume that you have already taken the steps necessary to begin the development process.

Open the code for your website, and insert the following lines AFTER your header, and BEFORE your footer. Change the words "YOUR ACCESS CODE HERE" to your access code from your Listpipe account.

Don't forget to download and copy to your web folder the helper functions from RelayPipeFunctions.php

<?php /* *  This is an example script (not a plugin) of how to utilize the RelayPipe system and provided without warrenty of any kind with  *  explicit instructions that this script should not be implemented directly.  */ //Basic information needed to connect to RelayPipe $access_code = "YOUR ACCESS CODE HERE"; //This value can be found inside your RelayPipe account. $relay_pipe_url = "http://api.listpipe.net/"; //This is the URL where we will send our REST requests $base_url = $relay_pipe_url.$access_code."/"; //This is the custom URL to retrieve your data.  include "RelayPipeFunctions.php";  // Helper functions  /* *  RETRIVING POSTS * *  First we will retrieve a the posts to display. Post can be retrieved based on "post_id", "search", "category_id", "offset", *  "start_date", "end_date", and "limit". We have the page set up to read these parameters from the $_REQUEST array *  and to retrieve the appropriate posts. * *  Accepted _REQUEST Parameters *     post_id     : An ID for a post that you wish to view, format Integer *     search      : A Search String. Will search Title and Content of each post, format String *     category_id : An ID for a category of posts that you wish to view, format Integer *     offset      : How many posts you wish to skip from the beginning, format Non-negative Integer, default: 0 *     start_date  : The first date allowed for posts in this query, format 2000-01-01+00:00:00  *     end_date    : The last date allowed for posts in this query, format 2000-01-01+00:00:00   *     limit       : The number of articles to be returned, default "10" accepted values: "none" or Integer     */  //Retrieve Posts if(count($_REQUEST) == 0) //if we have no _GET or _POST variables   $content = get_all_articles($base_url); else   $content = get_restricted_articles($base_url, $_REQUEST);  //Now we will display our posts ?>
 
<style type="text/css">
       .RelayPipeLeftColumn{width:75%;text-align:left;vertical-align:top;}      
       .RelayPipeRightColumn{padding-left:25px;text-align:left;vertical-align:top;}
</style>
 
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
  <td class="RelayPipeLeftColumn">
    <hr/>
    <?php /* Display the which type of posts were requested */ ?>
    <?php if(!empty($_REQUEST["archive_title"])) { ?><h3>Archive for <em><?php echo $_REQUEST["archive_title"]; ?></em></h3><?php } ?>
<?php     /* *  Post Object Variables *     post_id    : A Unique ID for each post  *     post_date  : The date this post was published, formatted 2000-01-01+00:00:00  *     title      : Title of this Archive, format String *     content    : The Contents of the post, format String *     category   : The CategoryID of the post, Only appears if there IS a category for this post. format Integer  */     /* Display Posts */      foreach($content as $post) { ?>
			<div>
      <h2 id="post_<?php echo $post->post_id; ?>">
      <a href="<?php $_SERVER["PHP_SELF"]; ?>?post_id=<?php echo $post->post_id; ?>">
      <?php echo $post->title; ?></a></h2>
      <small><em>Posted <?php echo date("F j, Y g:i A",strtotime($post->post_date)); ?></em></small><br/>
      <?php echo $post->content; ?>
      <br/>
      <?php if(!empty($post->category)) echo "Posted in the <em>$post->category</em> category<br/><br/>"; ?>
      <hr/>
      </div>
    <?php } ?>
 
 
    <?php          /*If there are more posts than can fit on the page, we will display "older" and "newer" post links */     ?>
    <?php if(count($content) < 1) { ?><center>Your Criteria Returned No Results</center><?php } ?>
    <?php if(empty($_REQUEST["limit"]) || $_REQUEST["limit"] != "none") { ?> 
      <div style="text-align:right">
        <?php         //Get Current Offset         $offset = 0;         if(!empty($_REQUEST["offset"]) && is_numeric($_REQUEST["offset"]) && $_REQUEST["offset"] > 0)
          $offset = $_REQUEST["offset"];
        //Get Total Number of Posts
        $num_posts = get_number_articles($base_url);
        if(count($content) == 10 || $offset != 0) { ?>
          <?php if($offset > 0) { ?><a href="<?php $_SERVER["PHP_SELF"]; ?>?offset=<?php echo ($offset-10);?>">Newer Posts</a><?php } ?>
          <?php if($offset > 0 && ($offset+10) < $num_posts) { ?> | <?php } ?>
          <?php if(($offset+10) < $num_posts) { ?><a href="<?php $_SERVER["PHP_SELF"]; ?>?offset=<?php echo ($offset+10); ?>">Older Posts</a><?php } ?>
        <?php } ?>
      </div>
    <?php } ?>
  </td>
 
  <td class="RelayPipeRightColumn">    
<?php /* *  ARCHIVES * *  Now we will retrieve our list of archives from RelayPipe and display them. *  *  Archive Object Variables *     start_date : Start date of this Archive, formatted 2000-01-01+00:00:00  *     end_date   : End date of this Archive, formatted 2000-01-01+00:00:00  *     title      : Title of this Archive, format String *     post_count : Number of Posts in this archive, format Integer * *  Archive Query Parameter *     interval   : The interval for which you which archives to appear *        accepted values: "year", "month" *        default: "month" * */ ?>
    <h3>Archive</h3>
    <?php      $interval = null;     $archives = get_archive_list($base_url, $interval);     foreach($archives as $archive) {        $link = $_SERVER["PHP_SELF"]."?start_date=".urlencode($archive->start_date);
      $link .= "&amp;end_date=".urlencode($archive->end_date);
      $link .= "&amp;limit=none"; //This is if you do not want the number of posts returned to be limited
      $link .= "&amp;archive_title=".urlencode($archive->title); //This is for display purposes (RelayPipe does not accept an archive_title)
      ?>
      <a href="<?php echo $link;?>"><?php echo $archive->title;?> (<?php echo $archive->post_count;?>)</a><br/>
    <?php } ?>
    <hr/>    
  </td>
  </tr>
</table>