I recieve the viewport size the browser having a JS function:

<script>
var winAlto = getWindowHeight();
var winAncho = getWindowWidth();
if ( (winAncho <= 1024) && (winAlto <= 768) ) {
   var jnumHome = 6;
   alert(jnumHome); 
}
else if ( (winAncho <= 1280) && (winAlto <= 800) ) {
   var jnumHome = 10;
   alert(jnumHome);
} else {
   var jnumHome = 16;
   alert(jnumHome);
}
</script>

This works perfect, however i must send the worthiness variable to PHP with Wordpress to show the amounts of publish.

<?php 
$finalVar = "<script> document.write(jnumHome) </script>";    
query_posts(array(
     'post_type' => 'portafolio',
     'orderby' => 'rand',
     'posts_per_page' => $finalVar
));   
<?php

The issues is PHP don't wait the need for the variable $finalVar and print the variable how undefined.

How do i wait to load the variable of js?

Thanks a lot