http://www.dev4press.com/2011/tutorials/wordpress/practical/how-to-optimize-plugin-loading/
Category Archives: Wordpress
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');
?>
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
Woocommerce: Change number of products displayed per page
add_filter('loop_shop_per_page', create_function('$cols', 'return 6;'));
Change breadcrumb separator on woocommerce page
Good afternoon everyone.
I just change my woocommerce breadcrumb separator. It only need simple steps.
- Copy the
breadcrumb.phptemplate 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"> </span>'; - You can put your delimiter in $delimiter variable. For me, I just add the style for
.sepclass.
Home this helps.
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
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(); ?>
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' )
)
) );

