RSS

Category Archives: Wordpress

Good Reading on WordPress Plugin Performance

http://www.dev4press.com/2011/tutorials/wordpress/practical/how-to-optimize-plugin-loading/

 
Leave a comment

Posted by on April 26, 2012 in Wordpress

 

Tags: , ,

WordPress Custom Post Type Archive

I have problem showing custom post type archive page. I want to share the code to create a custom widget which you can input the post type name and it will show you the archive (year and month) for that custom post type. You can edit it as needed.

<?php
class custom_archive extends WP_Widget {
function custom_archive() {
parent::WP_Widget(false, 'Custom Archive');
}
function form($instance) {
// outputs the options form on admin
$post_type = $instance['post_type'];
$title = $instance['title'];
?>
<p>Title:<br /> <input name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /></p>
<p>Post Type:<br /> <input name="<?php echo $this->get_field_name( 'post_type' ); ?>" type="text" value="<?php echo esc_attr( $post_type ); ?>" /></p>
<?php
}
function update($new_instance, $old_instance) {
// processes widget options to be saved
$instance = $old_instance;
$instance['post_type'] = strip_tags( $new_instance['post_type'] );
$instance['title'] = strip_tags( $new_instance['title'] );
return $instance;
}
function widget($args, $instance) {
// outputs the content of the widget
extract( $args, EXTR_SKIP );
$post_type = $instance['post_type'];
$title = $instance['title'];
?>
<?php echo $before_widget; ?>
<?php echo $before_title . $title . $after_title; ?>
<ul>
<?php
global $wpdb;
/**/
$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = '".$post_type."' ORDER BY post_date DESC");
foreach($years as $year) :
$years_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = '".$post_type."' AND YEAR(post_date) = ".$year.";" ) );
?>
<li class="year"><a href="<?php echo get_year_link($year)."?post_type=".$post_type; ?>"><?php echo $year; ?></a> (<?php echo $years_count; ?> Posts)
<ul>
<? $months = $wpdb->get_col("SELECT DISTINCT MONTH(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = '".$post_type."' AND YEAR(post_date) = '".$year."' ORDER BY post_date DESC");
foreach($months as $month) :
$months_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = '".$post_type."' AND YEAR(post_date) = ".$year." and MONTH(post_date) = ".$month.";" ) );
?>
<li class="month">>
<a href="<?php echo get_month_link($year, $month)."?post_type=".$post_type; ?>"><?php echo date( 'F', mktime(0, 0, 0, $month) );?></a> (<?php echo $months_count; ?> Posts)
</li>
<?php endforeach;?>
</ul>
</li>
<?php endforeach; ?>
</ul>
<?php echo $after_widget; ?>
<?php
}
}
register_widget('custom_archive');
?>

 
Leave a comment

Posted by on April 17, 2012 in Wordpress

 

Tags: , ,

“You do not have sufficient permissions to access this page” after database prefix change

After several times moving WordPress websites from one host to another, I get this painfully permission denied for superadmin user “You do not have sufficient permissions to access this page”. The frontend page was all fine. But I can’t access the admin page. Then I found these people who have the same problem and found the solution (http://wordpress.org/support/topic/sudden-you-do-not-have-sufficient-permissions-to-access-this-page-error).

The main cause is the database prefix changes. It cause the wordpress doesn’t recognize the admininstrator privilege. if you look into the wp_options table, the option_name from roles is wp_user_roles. The wp_ should match the table prefix. So if you change the wp_options table to en_options, then you must change the options_name to en_user_roles. That’s how the wordpress recognize the roles.

Besides that, user to role mapping also use the table prefix. You can see it in wp_usermeta tables. There is a meta_key called wp_capabilities. The wp_ is the table prefix of the wordpress tables. So if you change the table prefix e.q. wp_usermeta to en_usermeta, then you should change the wp_capabilities to en_capabilities.

Thats how you fix the permission problem to wp_admin page.

Have a good day

 
Leave a comment

Posted by on April 13, 2012 in Wordpress

 

Tags: , ,

Get Taxonomy List without links

Use <?php wp_get_object_terms( $object_ids, $taxonomies, $args ) ?>

http://codex.wordpress.org/Function_Reference/wp_get_object_terms

 
Leave a comment

Posted by on April 11, 2012 in Wordpress

 

Tags: ,

Woocommerce: Change number of products displayed per page

add_filter('loop_shop_per_page', create_function('$cols', 'return 6;'));

 
Leave a comment

Posted by on March 9, 2012 in Wordpress

 

Tags: ,

Change breadcrumb separator on woocommerce page

Good afternoon everyone.

I just change my woocommerce breadcrumb separator. It only need simple steps.

  • Copy the breadcrumb.php template from woocommerce plugin directory (/wp-content\themes/bestdeal/woocommerce/shop/breadcrumb.php) to your woocommerce theme template directory (/wp-content/themes/foreverlove/woocommerce/shop/breadcrumb.php)
  • Edit the breadcrumb.php, add this line after $prepend = '';
    $delimiter = '<span class="sep">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>';
  • You can put your delimiter in $delimiter variable. For me, I just add the style for .sep class.

Home this helps.

 
Leave a comment

Posted by on March 1, 2012 in Wordpress

 

WordPress site stuck in maintenance mode

If you are updating you plugins and your site is stuck in maintenance mode, you can just delete the .maintenance file in you site’s root directory and you are back online

 
Leave a comment

Posted by on February 22, 2012 in Wordpress

 

Create custom page template for blog posts

If you want to create a custom page template for your blog posts, you can use this query so the pagination still works:

<?php query_posts( array( 'paged' => get_query_var('paged') ) ); ?>

In the bottom of the page, reset the query:

<?php wp_reset_query(); ?>

 
Leave a comment

Posted by on February 22, 2012 in Wordpress

 

Change Breadcrumb Separator in Hybrid

Add this code to your function.php file

add_filter( 'breadcrumb_trail_args', 'my_breadcrumb_trail_args' );
function my_breadcrumb_trail_args( $args ) {
$args['separator'] = ' &rarr; ';
return $args;
}

Replace &rarr; with your own separator

 
Leave a comment

Posted by on February 20, 2012 in Wordpress

 

Tags:

Add WordPress Custom Header Image & Custom Background

In function.php files, use this code:

/* Add Custom Background */
add_custom_background();

/**
* Add support for WordPress custom header image.  On that note, this is horrible and messy.  Expect a
* rewrite of this entire code into something more beautiful in future versions.
*/
add_custom_image_header( '__return_false', '__return_false' );
define( 'NO_HEADER_TEXT', true );
define( 'HEADER_IMAGE', '' ); // By leaving empty, we allow for random image rotation.
define( 'HEADER_IMAGE_WIDTH', 960 );
define( 'HEADER_IMAGE_HEIGHT', 400 );

// Turn on random header image rotation by default.
add_theme_support( 'custom-header', array( 'random-default' => true ) );

register_default_headers( array(
'banner1' => array(
'url' => '%s/images/headers/banner1.jpg',
'thumbnail_url' => '%s/images/headers/banner1-thumb.jpg',
/* translators: header image description */
'description' => __( 'banner1', 'simplejoss' )
),
'banner2' => array(
'url' => '%s/images/headers/banner2.jpg',
'thumbnail_url' => '%s/images/headers/banner2-thumb.jpg',
/* translators: header image description */
'description' => __( 'banner2', 'simplejoss' )
)
) );

 
Leave a comment

Posted by on February 17, 2012 in Wordpress

 
 
Follow

Get every new post delivered to your Inbox.

Join 106 other followers