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,
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI 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,
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.