Title: Top Posts Page
Last modified: August 20, 2016

---

# Top Posts Page

 *  [chadkjackson](https://wordpress.org/support/users/chadkjackson/)
 * (@chadkjackson)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/top-posts-page/)
 * Hey folks. Looking for a little help on a project I am running.
 * As part of a customized child template that I am using, I have created a page
   template that lists top post. Here is the code.
 *     ```
       $thispost = 1;
         $start = date('Y-m-d', (time() - (60 * 60 * 24 * $days)));
         $end = date('Y-m-d');
   
         $login = new GADWidgetData();
         $ga = new GALib(‘oauth’, NULL, $login->oauth_token, $login->oauth_secret, $login->account_id);
   
         // $login = new GADWidgetData(get_option('gad_auth_token'), get_option('gad_account_id'));
         // $ga = new GALib('client', $login->auth_token, '', '', $login->account_id);
   
         $pages = $ga->pages_for_date_period($start, $end);
         echo "<ol>";
         foreach($pages as $page) {
           $url = $page['value'];
           $title = $page['children']['value'];
           // $excerpt = get_the_excerpt_id($page->ID);
           // $excerpt = get_the_excerpt($page);
           // $excerpt = get_post_meta($page, 'key_1', true);
           // $excerpt = "this will be the excerpt";
           // ignore these page titles
           $ignore = array(
             '(not set)',
             'engineering-matters',
             'engineering-matters.com',
             'engineering-matters.com - Part 2',
             'engineering-matters | Engineering Executives',
             'About the Blog | engineering-matters.com',
             'About the Blog |',
             'About Lifecycle Insights | engineering-matters.com',
             'engineering-matters | The blog about the issues that matter to engineering',
             'About Chad Jackson | engineering-matters.com'
           );
           if(!in_array($title, $ignore)){
             // list any strings you would like to remove from the titles
             $remove = array(
               " | engineering-matters.com",
               " |",
               "engineering-matters.com",
               " « Company Name"
             );
             $newtitle = str_replace($remove, "", $title);
             echo '<strong><li><a href="' . $url . '" rel="nofollow">' . $newtitle . '</a></li></strong>';
            // echo get_the_excerpt($page);
             $thispost++;
           }
           if($thispost > $showposts) break;
         }
         echo "</ol>";
   
       ?>
       ```
   
 * I have it running successfully. You can see the result here.
 * [http://www.engineering-matters.com/top-posts-all-time/](http://www.engineering-matters.com/top-posts-all-time/)
 * I would like to also list the excerpt of each post in the list after the title.
   I have tried using the get_the_excerpt function within the foreach loop, but 
   it returns an array (and shows that on the page when I echo it). Here is the 
   citation to that function.
 * [http://codex.wordpress.org/Function_Reference/get_the_excerpt](http://codex.wordpress.org/Function_Reference/get_the_excerpt)
 * Any help would be greatly appreciated.

The topic ‘Top Posts Page’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 0 replies
 * 1 participant
 * Last reply from: [chadkjackson](https://wordpress.org/support/users/chadkjackson/)
 * Last activity: [14 years, 3 months ago](https://wordpress.org/support/topic/top-posts-page/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
