0

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,

2

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.

  • 1
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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