Skip to content

Instantly share code, notes, and snippets.

@danielck
Last active December 15, 2015 07:49
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 danielck/5225892 to your computer and use it in GitHub Desktop.
Save danielck/5225892 to your computer and use it in GitHub Desktop.
WordPress sidebar example. Conditional loading of a dynamic sidebar or a link, based on a custom variable.
<div id="sidebar">
<?php
// Check for the 'part' variable
$part = get_query_var('part');
// If this is a sidebar, show the dynamic content
if ( $part == 'sidebar' ) :
?>
<div id="sidebar-content">
<?php
dynamic_sidebar();
?>
</div>
<?php
// Else, just show a link pointing to the desired endpoint
else : ?>
<a href="part/sidebar/" id="load-asides">Related content</a>
<?php endif; ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment