Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9149903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:32:25+00:00 2026-06-17T11:32:25+00:00

Ok so I am going to try and explain this the best I can.

  • 0

Ok so I am going to try and explain this the best I can. I created a widget that will pull in a featured image from the post on the home page based on the category. Right now it pulls in 4 posts. I would like to have the option to pull in 2, 3, 4, or 6 posts. I would also like to change the layout based on how many posts are coming in. Is it possible to only display 2, 3,4, or 6 posts and how would I go about changing the layout based on the number of posts coming in. I was thinking it would refer to a container class in the css for each number of posts or something along the lines of that. Any links, tutorials, or advice would be greatly appreciated!
Thanks,
– Michael

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:32:26+00:00Added an answer on June 17, 2026 at 11:32 am

    Pure CSS

    This provides a CSS3 method to achieve what you want, with a fall back in place for CSS2. Basically, you have a wrapper to target your post items, which will be the only children directly in that wrapper (or, at least the only children of a particular “tag” type, here a div). So something like the following, only the number of children can be 2, 3, 4, or 6 (as you requested).

    Simple HTML (this does not have to be div elements; just illustrating)

    <div class="postWrapper">
      <div>This is a post</div>
      <div>This is the second post</div>
    </div>
    

    Set Default CSS2

    For IE7/8, this will be the default display no matter how many posts are being shown in those two browsers, using this selector:

    .postWrapper > div { ... }
    

    Set Fancy CSS3

    This is doen based on number of posts and will be displayed in all CSS3 browsers. It uses this series of selectors, in this order: (we are using the cascade to our advantage here):

    .postWrapper > div:nth-last-of-type(2),
    .postWrapper > div:nth-last-of-type(2) ~ div {
       ... your two display css ...
    }
    
    .postWrapper > div:nth-last-of-type(3),
    .postWrapper > div:nth-last-of-type(3) ~ div {
       ... your three display css ...
    }
    
    .postWrapper > div:nth-last-of-type(4),
    .postWrapper > div:nth-last-of-type(4) ~ div {
       ... your four display css ...
    }
    
    .postWrapper > div:nth-last-of-type(6),
    .postWrapper > div:nth-last-of-type(6) ~ div {
       ... your six display css ...
    }
    

    What this is doing is utilizing the :nth-last-of-type() selector to “count backwards” through the number of child div’s of the wrapper, apply a style to that div, and then use the general sibling combinator ~ to style all the other div’s in .postWrapper that follow that (theoretical) first div. It does this for the first two using the :nth-last-of-type(2), but then if the wrapper contains three, the next set of selectors that uses :nth-last-of-type(3) overrides the previous (2) selector, and so forth. In this way, through a series of overriding css in the cascade, we change our settings for the number of post elements.

    You can see a sample of this technique for illustration purposes in in this fiddle.

    NOTE: Because we are using the cascade to override, it is imperative that you make sure to handle any previously set css. In my fiddle example, note how I put a margin on a group of four, but then I removed it on a group of six. If I had mentioned nothing of margin in group six (that is, no overriding), then elements 3-6 (but not 1-2) of the group of six would have had margin still applied based off the previous settings for the group of four.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm going to try to explain this best I can I will provide more
I will try to explain this as best as I can and hope someone
I'm going to try and explain this the best I can... I have one
I'm going to try and explain this the best I can. I used this
I'm going to try to explain this as best I can. I'm returning an
I am going to try and explain this as best as I can, so
I will try my best to explain what's going on. The app that I'm
I'm going to try and explain this as simply as I can, it's most
OK, I'm going to try my best to explain my problem. I have this
This is going to be hard to explain but I'll try my best. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.