I need code to get one category - including its sticky post and a custom featured post box on my front page. I am using twenty twelve. I have created a child theme. I have wordpress 3.6 on a wordpress.org site.

I selected "your latest posts" under Static Page in the theme customize tab for my front page. I want posts from only one category (vacation) to appear on my front page. I want them to include the sticky post in that category along with my custom featured post box. Getting the featured post box is important.

I changed the style.css - in my child theme - to modify the appearance of the featured post box:

/*  change Featured Post box appearance */
article.sticky .featured-post {
    border-top: 4px double #4275b1;
    border-bottom: 4px double #4275b1;
    color: #08b8c3;
    font-size: 13px;
    font-size: 1.25rem;
    line-height: 3.692307692;
    margin-bottom: 24px;
    margin-bottom: 1.714285714rem;
    text-align: center;

Then I changed the wording that appears in the featured post box in my (child theme) content.php.

The combination of these two files with my "latest posts" selection and the standard index.php makes the front page look the way I want design wise...but I only want one category of posts (vacation) to appear on the front page and I want the sticky post in that category to display the featured post box. I get the sticky post (with the box) plus all other posts (from every category) when I use the standard index.php file.

So I tested (changing the index.php) and was able to show both posts from the vacation category. And none from other categories. However, although the sticky post (from the "vacation" category) shows, I lost the "featured post box" part. (The "vacation" category is the only category where I have a sticky post.)

So I think that instead of using just a category, I need to somehow incorporate the "is sticky" part to get the featured post box to show.

Can anyone help me with 1. what code to modify and 2. in what template I can do this? I have been searching and testing for 3 days. So I stopped and I just put the original index code which populates the front page with the right sticky and featured post box but multiple categories.

Thank you for any assistance or suggestions- hopefully at a level for someone who is just technical enough to be dangerous :)

I think that this post may have part of the answer I need, but I just want one category of post(s)on the front page - including the one I set as sticky which should show up with the featured post box.

  • Please don't use pastebin or other outside sources for your code. Just add it to the question.
    – kaiser
    Aug 16, 2013 at 18:46

2 Answers 2


This may only be part of the problem. That is quite a bit of code to read (and you should post relevant code inline so that the question is not dependent on an external site) and your description is a bit hard to follow, but...

You should not be using a secondary query at all (I am pretty sure) and you certainly should not be using query_posts to do it.

It should be noted that using this to replace the main query on a page can increase page loading times, in worst case scenarios more than doubling the amount of work needed or more. While easy to use, the function is also prone to confusion and problems later on. See the note further below on caveats for details.

http://codex.wordpress.org/Function_Reference/query_posts (emphasis mine)

I think that you need a filter on pre_get_posts. Something like this:

function one_cat_front_wpse_110327($qry) {
  if (is_front_page() && $qry->is_main_query()) {
  return $qry;

That should restrict the results to category 123. Obviously, change that to the correct category.


If you asks me I would do that by custom snippet witch you simply have to add to functions.php

        function my_category_queries( $query ) {
          if ($query->is_home() && $query->is_main_query()){
             $query->set('category_name', 'wperror');
        add_action( 'pre_get_posts', 'my_category_queries' );

If you check it better first part of the function applying it only to homepage and the main query while the other part is related to the category slug on this example 'wperror'

If you want more advanced snippet on this theme please check topic Display only one category on home page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.