Skip to content

Instantly share code, notes, and snippets.

@joshuadavidnelson
Created January 3, 2016 20:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuadavidnelson/18918faa099ea5f20aba to your computer and use it in GitHub Desktop.
Save joshuadavidnelson/18918faa099ea5f20aba to your computer and use it in GitHub Desktop.
Basic Transient function
<?php
/**
* Featured projects.
*
* @since 1.0.0
*
* @return void
*/
function child_home_projects() {
// The pre-compiled output is empty
$output = '';
// Grab the tranisent
$projects = get_transient( 'home_projects' );
if( false === $projects || ( defined( 'DISABLE_TRANSIENTS' ) && true == DISABLE_TRANSIENTS ) ) {
$projects = '';
// do the stuff
// if we have output, save it
if( !empty( $projects ) )
set_transient( 'home_projects', $projects, 10 ); // change 10 to seconds transient is stored
}
// add another wrap or alter the output
if( !empty( $projects ) )
$output = $projects;
// Print the output
if( !empty( $output ) )
echo '<div class="row" id="projects">' . $output . '</div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment