Archive for the ‘php’ Category

WordPress: Get template variables (post id, category id)

Monday, September 7th, 2009

Get current category

<?php $current_category = single_cat_title("", false); ?>

Source: codex.wordpress.org – single_cat_title

Get current post in a loop

<?php $current_post = get_the_ID() ?>

Source: codex.wordpress.org – getId

WordPress: PHP is user logged in > is_user_logged_in()

Saturday, March 21st, 2009

<?php
if ( is_user_logged_in() ) {echo ‘WordPress says you’re logged in!';}
else if ( !is_user_logged_in() ) {echo ‘WordPress says you’re not logged in!';}
?>

Particularly useful to avoid adding Google Analytic code when the user is logged-in. For example, if you are editing you blog from different access point, the Google Analytic filters can become cumbersome to manage.