• 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.

    https://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.

    https://codex.www.ads-software.com/Function_Reference/get_the_excerpt

    Any help would be greatly appreciated.

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