Archive for the ‘ Wordpress ’ Category

Create Custome post type

As usually creating custom post type in wordpress is very simple. Just get into the follow post
1. for the first step just open function.php in your theme(U can find this one in your theme directory)
2. Add the following code to that file(function.php)

add_action( 'init', 'create_post_type' );
function create_post_type() {
	register_post_type( 'acme_product',
		array(
			'labels' => array(
				'name' => __( 'Products' ),
				'singular_name' => __( 'Product' )
			),
		'public' => true,
		'has_archive' => true,
		)
	);
}

That’s it u can find new custom post type in wp dashboard..
U have another option like plugin
With the following plugin also u can create custom post
http://wordpress.org/extend/plugins/custom-post-type-ui/

Find WordPress Category ID

In Simple Way you can find Category ID in WordPress
1. Login into wordpress admin Panel
2. Goto Manage Categories Page
3. Simply Edit category which you want to find the ID
4. Find URL : https://urdomain/wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=647&post_type=post
5. tag_ID=647 is the category ID

Disable Categories from WP RSS

To continue this process you must know the ID of category(find Category ID)
once you find the category Id which you want to exclude from your RSS follow steps
1. Open Function.php which you can find in your theme directory. If your theme doesn’t have , create one
2. Create filter like the follwing Way

function myFilter($query) {
if ($query->is_feed) {
$query->set(‘cat’,’-5′);
//Don’t forget to change the category ID =^o^=(in this 5 is the ID.) Keep ‘-‘ before the cat ID
}
return $query;
}

This filter excludes category from feed
3. Apply this filter to your Theme using ‘add_filter’ function

add_filter(‘pre_get_posts’,’myFilter’);

Create custom wordpress page navi

Try this one
Paste the following code in function.php

<?php
#Page Navi

function page_navi($before = ”, $after = ”) {
global $wpdb, $wp_query;

$request = $wp_query->request;
$posts_per_page = intval(get_query_var(‘posts_per_page’));
$paged = intval(get_query_var(‘paged’));
$numposts = $wp_query->found_posts;
$max_page = $wp_query->max_num_pages;

if(empty($paged) || $paged == 0) {
$paged = 1;
}
$pages_to_show = 5;
$pages_to_show_minus_1 = $pages_to_show-1;
$half_page_start = floor($pages_to_show_minus_1/2);
$half_page_end = ceil($pages_to_show_minus_1/2);
$start_page = $paged – $half_page_start;
if($start_page <= 0) {
$start_page = 1;
}
$end_page = $paged + $half_page_end;
if(($end_page – $start_page) != $pages_to_show_minus_1) {
$end_page = $start_page + $pages_to_show_minus_1;
}
if($end_page > $max_page) {
$start_page = $max_page – $pages_to_show_minus_1;
$end_page = $max_page;
}
if($start_page <= 0) {
$start_page = 1;
}

echo $before.'<center><div class=”page_navi”>’.”\n”;
if ($start_page >= 2 && $pages_to_show < $max_page) {
$first_page_text = “First”;
echo ‘<a href=”‘.get_pagenum_link().'” title=”‘.$first_page_text.'”>’.$first_page_text.'</a>’;
}
previous_posts_link(‘&laquo;’);
for($i = $start_page; $i  <= $end_page; $i++) {
if($i == $paged) {
echo ‘<span class=”current”>’.$i.'</span>’;
} else {
echo ‘<a href=”‘.get_pagenum_link($i).'”>’.$i.'</a>’;
}
}
next_posts_link(‘&raquo;’);
if ($end_page < $max_page) {
$last_page_text = “Last”;
echo ‘<a href=”‘.get_pagenum_link($max_page).'” title=”‘.$last_page_text.'”>’.$last_page_text.'</a>’;
}
echo ‘</div></center>’.$after.”\n”;
}
?>

cal the following function where ever you want

 <?php page_navi(); ?>

use the following css for styling

.page_navi{padding:10px 0 10px 10px;}
.page_navi a,.page_navi a:link,.page_navi a:visited{text-decoration:none;border:1px solid #ccc;color:#2b74b4;background-color:#fff;font-weight:700;margin:2px;padding:2px 4px;}
.page_navi a:active,.page_navi a:hover{text-decoration:none;border:1px solid #2b74b4;color:#fff;background-color:#0F0;margin:2px;padding:2px 4px;}
.page_navi span.current{font-weight:700;border:1px solid #2b74b4;color:#fff;background-color:#03C;margin:2px;padding:2px 4px;}

WP-PageNavi not working

I also faced same issue. I found solution for this follow these steps

1. After activating the plugin
2. <?php $page = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;?> add this code before the query_posts
3. Add the paged=$page argument query_posts like <?php query_posts(“paged=$page&showposts=10”); ?>
4.after while loop add the following code
<?php wp_pagenavi(); ?>                        
//Reset Query
            wp_reset_query();
     ?>

Get Post Comments count

Try this one

<?php
$num_comments = get_comments_number(); // for some reason get_comments_number only returns a numeric value displaying the number of comments
if ( comments_open() ){
if($num_comments == 0){
$comments = __(‘No Comments’);
}
elseif($num_comments > 1){
$comments = $num_comments. __(‘Comments’);
}
else{
$comments =”1 Comment”;
}
$write_comments = ‘<a href=”‘ . get_comments_link() .'”>’. $comments.'</a>’;
}
else{$write_comments =  __(‘Comments are off for this post’);}

?>

now use $num_comments just like

<?php echo $num_comments; ?>

 

Checkout fields have BR tags? Ecommerce Plugin

This is a small issue but I have taken great time to rectify this. Follow the below steps
1. Go to “wp-content\plugins\wp-e-commerce\wpsc-theme\ ” directory
2. Open wpsc-shopping_cart_page.php with the text editor
3. find the  <label  ” tag and remove the line breaks in the label tags