Skip to content

Instantly share code, notes, and snippets.

@tollmanz
Created October 12, 2012 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tollmanz/3882203 to your computer and use it in GitHub Desktop.
Save tollmanz/3882203 to your computer and use it in GitHub Desktop.
Cache Google Analytics Data with Variable Args
<?php
function zt_generate_top_posts( $args ) {
// Queries GA, relates to internal posts
$top_post_objects = zt_magic_GA_querier( $args );
// If no objects are returned, exit the function
if ( false === $top_post_objects )
return false;
// Start building the HTML
$html = '<ul>';
// Loop through post objects and generate HTML
foreach ( $top_post_objects as $post_object ) {
$html .= '<li>';
$html .= '<a href="' . esc_url( $post_object['permalink'] ) . '">';
$html .= esc_html( $post_object['post_title'] );
$html .= '</a>';
$html .= '</li>';
}
$html .= '</ul>';
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment