I wanted to just show my ‘website news’ category in the root of my WordPress installation. But by default index.php shows the latest posts from all categories, this was not what I wanted. So how could I get what I want?

Step 1

I take a look in index.php. It displays:

/* Short and sweet */
define("WP_USE_THEMES", true);

Step 2

After looking at this code I could see, clearly, there was no statement to restrict what category to show, which was what I wanted. So I checked in the Administration>Categories section in the Administration part of my site to find out the category ID of the category I wanted to just show on my index.php in my WordPress installation root, the category ID was ‘2?. I changed index.php to the following and uploaded it to my webserver:

$blog = 1;
if (!isset($cat)) {
$cat = "2";
/* Don't remove this line. */
define("WP_USE_THEMES", true);

30 Comments Add Your Own Comment

(March 28th, 2009 at 6:02 pm )

Very Interesting post! Thank you for such interesting resource!
PS: Sorry for my bad english, I’v just started to learn this language 😉
See you!
Your, Raiul Baztepo

(August 21st, 2010 at 5:14 pm )

Use this code <?php query_posts('category_name=YourCategoryName&showposts=4'); ?> before

if (have_posts()) :
while (have_posts()) : the_post(); …………………

Change to your category name[you wish to have] instead of “YourCategoryName”
It works 🙂

(August 21st, 2010 at 5:16 pm )

also > “4” is the amount of post u wish to do so

(December 18th, 2011 at 12:38 pm )

Best Tips to Secure WordPress Blog/Site here http://how-what.blogspot.com/2

(April 12th, 2012 at 3:26 pm )

I am trying to use this code on a page. It shows the list of posts as expected, but also the posts content at the bottom of the page which I do not want. I am not sure why this is happening. any Ideas?

Thank you for a great tip and your site is awesome.

(April 16th, 2012 at 4:16 pm )

Hi JW, I use this script but I have a problem. When I select the categories it only shows the title and the name of the category, but the text of the lastest news of every one of the category do not correspond to this category.

(April 16th, 2012 at 4:17 pm )

i want photo & clip

(April 16th, 2012 at 4:18 pm )

Hello, dear Author!
If I include your code into my index.php I get an error due to some errors in your function. I am not really good in php, but could you take a look please?

(April 16th, 2012 at 4:19 pm )

thank you for the supplied  index.php, it is showing only one post of each selected category!!

(April 16th, 2012 at 4:20 pm )

Thanks for one’s marvelous posting! I seriously enjoyed reading it, you can be a great author.I will be sure to bookmark your blog and definitely will come back very soon. I want to encourage that you continue your great work, have a nice morning!

(April 20th, 2012 at 9:13 am )

Thanks for the tips I will followed them now. recently created my new technical blog. Thanks for explaining step by step process.

(April 22nd, 2012 at 12:39 pm )


its quite tricky. A easy way to fool someone. Awesome Man….. I liked it. Will do it on my blog.

If you have any such customizations, please share.




(April 24th, 2012 at 11:07 am )


I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I’m quite sure I’ll learn a lot of new stuff right here! Good luck for the next! 

(April 25th, 2012 at 3:09 am )

Appreciate it intended for one’s great placing! When i severely relished examining the item, you could end up an incredible article author. I will be guaranteed to help search for your site in addition to will definitely go back fastly. I have to really encourage you go on ones good do the job, employ a pleasant a . m .!

(May 28th, 2012 at 7:14 pm )


(July 16th, 2012 at 10:08 am )

i want to say one important thing about the programming, many peoples rae understand that programming is very tough and  they scared to learn it but no these is wrong as coding is very interesting we can get instantly result on it.

(October 11th, 2012 at 3:40 am )

Premium WordPress Theme for Attorneys, Law Firms and Legal Offices That
Want to Build Instant Credibility Launched by ThemeFuse

(October 11th, 2012 at 3:41 am )

 eMazzanti Technologies CEO Speaks at Microsoft World Wide Partner Conference

(October 11th, 2012 at 3:42 am )

MECASOLARs projects in Greece go up by 52% in six months

(October 11th, 2012 at 3:43 am )

Extensis Releases Free WebINK Plug-in for WordPress

(October 11th, 2012 at 3:43 am )

Implement WordPress in an educational setting using Packts New Book and eBook on WordPress

(October 11th, 2012 at 3:43 am )

Luxury Insiders Guide To The 2012 MTV VMAs (Video Music Awards 2012)

(October 11th, 2012 at 3:44 am )

WordPress Theme Marketplace MOJO Themes Achieves Milestone of 40,000 Users

(October 11th, 2012 at 3:44 am )

Raven Releases Google Chrome Toolbar for SEO and Social Media


(October 11th, 2012 at 3:44 am )

RosettaBooks Joins Worldreader in African Literacy Program

(November 16th, 2012 at 5:50 am )

There are certainly a lot of details like that to take into consideration. That is a great point to bring up.

(December 20th, 2012 at 1:31 pm )

I’m also use code on my pages and it’s works well.

(January 13th, 2013 at 4:02 pm )

Thank you for sharing this nice post.I find it very interesting to read and want to read more and more.

(January 16th, 2013 at 11:30 am )

I’m not be good in WordPress  but  here is really helpful post . This is very good tip for WordPress programmer .

Add Your Own Comment Fields marked * are required.