Skip to content

Instantly share code, notes, and snippets.

@jimmyandrade
Last active March 17, 2017 17:46
Show Gist options
  • Save jimmyandrade/51dd6f5e1551a97b1f96 to your computer and use it in GitHub Desktop.
Save jimmyandrade/51dd6f5e1551a97b1f96 to your computer and use it in GitHub Desktop.
User menu
<?php
global $current_user;
$my_page_args = array(
'post_type' => 'page',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => '_wp_page_template',
'value' => 'page-profile.php', // template name as stored in the dB
)
),
);
$my_page = new WP_Query( $my_page_args );
get_currentuserinfo();
?>
<ul class="user-menu">
<?php
if ( !is_user_logged_in() ) {
wp_register();
?>
<li>
<a href="<?php echo wp_login_url( home_url() ); ?>" >
<?php _e( 'Login', 'bookpress' ); ?>
</a>
</li>
<?php
} else {
?>
<?php
while ( $my_page->have_posts() ) {
$my_page->the_post();
?>
<li>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php echo $current_user->user_firstname; ?>
</a>
</li>
<?php
}
?>
<li>
<a href="<?php echo wp_logout_url( home_url() ); ?>" >
<?php _e( 'Logout', 'bookpress' ); ?>
</a>
</li>
<?php
}
?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment