PHP检测屏幕宽度然后改变变量?

I'm attempting to build a WordPress theme from semi-scratch (using Understraps), and I'm using an Instagram plugin that allows placement using PHP. Basically, I'd like to detect screen width then display the number of posts accordingly.

I feel like jQuery will be helpful for this, but I don't really get how to use that and PHP together in a .php doc

This:

    $instagram->serve_user_media( 'foo', x )

Grabs x amount of photos from foo's Instagram and displays them. I've extended this to grab 16 then randomly pick 4 from those.

For example:

if screenWidth < 990 {
   $user_photos = $instagram->serve_user_media( 'foo', 9 );
}

I understand there's probably a world of errors in my code, but please try not to tear it apart too much