Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this code on my header:

$rPosts->query('showposts=3&cat=2174');

But I want to show 4 posts on desktop and 2-3 on mobile. In CSS I could use @mediaqueries, could I use something like that on PHP?

Thanks,

share|improve this question
add comment

1 Answer 1

WordPress has a function called wp_is_mobile. It does very simple User Agent checking, which isn't very reliable. There are a lot of user agents out there and they can easily be falsified. There is no guarantee that a browser representing itself as some user agent actually is that user agent. You can do more complicated user agent checking but it is still user agent checking.

But you also don't have a lot of choice with a server side script. I would use wp_is_mobile, or some more complicated version, to hedge my bets. It may save some load time in some, maybe many, cases. But make sure that media queries deal with the important stuff.

share|improve this answer
    
While this is technical options I want to stress that this is not reliable server side. Won't work at all (or will work faulty) with static page caching, etc. –  Rarst May 1 '13 at 17:34
    
I tried to make an smaller div with overflow hidden, but didn't work because some elements still show after that. –  euDennis May 2 '13 at 11:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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