Uly.me

cloud engineer

  • Home
  • About
  • Archives
Home/2014/Archives for June 2014

Archives for June 2014

June 12, 2014

Display Full Content Per Category

By the default, the Genesis child theme called Outreach Pro displays categories posts as excerpts. If you want to display the full content on just one category, Sridhar Katakam talks about it in his blog post. I changed the function names to fit my own, so here’s my own version of the code:

// display full content on blog category
add_action( 'genesis_before_loop', 'urr_full_content_specific_category' );
 
function urr_full_content_specific_category() {
  if (is_category('blog')) {
		remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
		add_action( 'genesis_entry_content', 'urr_do_post_content' );
	}
}
function urr_do_post_content() {
	the_content();
}

// display full content on blog category add_action( 'genesis_before_loop', 'urr_full_content_specific_category' ); function urr_full_content_specific_category() { if (is_category('blog')) { remove_action( 'genesis_entry_content', 'genesis_do_post_content' ); add_action( 'genesis_entry_content', 'urr_do_post_content' ); } } function urr_do_post_content() { the_content(); }

Filed Under: PHP, WP Tagged With: full content

June 11, 2014

Display Post From A Year Ago

Here’s a cool little WordPress script to display a post from a year ago. You can display your old content to entice your readers to view older articles. You can display your old posts on your theme’s sidebar, after your post content, or just anywhere on your theme. Here’s the code.

// current day of the month without leading zeros, e.g. 1-31.
$current_day = date('j');
// last year
$last_year = date('Y')-1;
// perform a query based on today's date last year
query_posts('day='.$current_day.'&year='.$last_year);
if (have_posts()):
    while (have_posts()) : the_post();
       the_title();
       the_excerpt();
    endwhile;
endif;

// current day of the month without leading zeros, e.g. 1-31. $current_day = date('j'); // last year $last_year = date('Y')-1; // perform a query based on today's date last year query_posts('day='.$current_day.'&year='.$last_year); if (have_posts()): while (have_posts()) : the_post(); the_title(); the_excerpt(); endwhile; endif;

The result will depend if you have a post last year on the exact date as today, otherwise you’ll get a blank result. I suppose to be on the safe side, you can query all posts of the current month last year. Your chances of getting results is much better. You can use the date(‘n’) function to extract the current month. Your query would look something like this:

$current_month = date('n');
query_posts('month='.$current_month.'&year='.$last_year);

$current_month = date('n'); query_posts('month='.$current_month.'&year='.$last_year);

Filed Under: PHP, WP Tagged With: last year

June 6, 2014

Hide WordPress Admin Bar

There are reasons why you want to hide the Admin Bar from your users. If users don’t have edit rights, then there’s really no use for an Admin bar. Another reason is if the account is shared with others, you don’t want users to reset the password. There are ample reasons why you want to hide the Admin bar.

Here’s the code:

if (!current_user_can(‘edit_posts’)) {
  show_admin_bar(false);
}

if (!current_user_can(‘edit_posts’)) { show_admin_bar(false); }

Here’s another:

function my_function_admin_bar(){ return false; }
add_filter( 'show_admin_bar' , 'my_function_admin_bar');

function my_function_admin_bar(){ return false; } add_filter( 'show_admin_bar' , 'my_function_admin_bar');

Here’s another for users that can’t manage options:

if ( ! current_user_can( 'manage_options' ) ) {
  show_admin_bar( false );
}

if ( ! current_user_can( 'manage_options' ) ) { show_admin_bar( false ); }

And one more for good measure:

add_action('set_current_user', 'csstricks_hide_admin_bar');
function csstricks_hide_admin_bar() {
  if (current_user_can('edit_posts')) {
    show_admin_bar(false);
  }
}

add_action('set_current_user', 'csstricks_hide_admin_bar'); function csstricks_hide_admin_bar() { if (current_user_can('edit_posts')) { show_admin_bar(false); } }

Filed Under: PHP, WP Tagged With: admin bar

  • 1
  • 2
  • Next Page »
  • Cloud
  • Linux
  • Git

Copyright © 2012–2021