How to get first category name or id from wordpress post

Many people want to know about post category and know more information current category. Some time we need to use the first category of wordpress post. As we know we can define the multiple category to single article. So if we want retrive the wordpress category then we will get the result in simple php array format. Using that array we can easily extract the first category of post.

if we want first category than, we will get result in php array format. Using that array we can easily get first category name or id from wordpress post.

How to get first category name or id from wordpress post

In this post I will show how we can achieve that. Using following code we can get the first category ID.

< ?php
$category = get_the_category();
$currentcat = $category[0]->cat_ID;
?>

Using following code we can extract the first category name from the wordpress post.

< ?php
$category = get_the_category();
$currentcat = $category[0]->cat_name;
?>

Above code we can use only in the loop but using the following code we can extract the category
outside the loop also

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
global $post;
$categories = get_the_category($post->ID);

$currentcat = $category[0]->cat_ID;
?></pre>
<pre>

same like that.. cat name

 <!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
 global $post;
 $categories = get_the_category($post->ID);

$currentcat = $category[0]->cat_name;
 ?>

</pre>
<pre>
How to get first category name or id from post
How to get first category name or id from post

Fetch the wordpress post paragraph number wise

In this article we given code for Fetch the wordpress post paragraph number wise. created One function for fetching the wordpress post as per p tag number.

Fetch the wordpress post paragraph number wise

# You can Use this function for showing

function paragraph_show($paragraph_number, $post_content){
$show_after_paragraph_tag = 1;
$paragraph_number= $paragraph_number - 1;
//echo $paragraph_number;
$content = apply_filters('the_content', $post_content);

if(substr_count($content, '

') > $show_after_paragraph_tag)
//echo substr_count($content, '

');

{
$contents = explode("

", $content);
$p_count = 0;
foreach($contents as $content)
{
//echo $p_count;
if($paragraph_number == $p_count){
echo $content;
}

$p_count++;
}
}
}

We can use this function like this.

In while loop you can use or paste following code

#This will show the first paragraph of post.
post_content);

Image upload issue in wordpress with nginx

Nginx server is used by wordpress itself. We solved Image upload issue in wordpress with nginx. you can use following code.

Image upload issue in wordpress with nginx

Please Use the following code:


location ~ ^.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
root /usr/share/nginx/html/wordpressmu;
rewrite ^/.*(/wp-admin/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last;
rewrite ^/.*(/wp-includes/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last;
rewrite ^/.*(/wp-content/themes/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last;
rewrite ^/.*(/wp-content/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last;
rewrite ^.*/files/(.*(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ /wordpress/wp-content/blogs.php?file=$1 last;

expires 10d;
break;
}