0

皆さんこんにちは、これを解決しようとして大きな問題が発生しています。JavaScript を使用する必要があることはわかっていますが、その方法がわかりません。これは私のスクリプトです:

<?php 
$posts = query_posts('order=DESC&cat=-2');
$cols = 4;
$filas = array_chunk($posts, $cols);
$columnas = array();
foreach( $filas as $row => $articulos ) {
foreach( $articulos as $ix => $articulo ) {
  $columnas[$ix] = isset($columnas[$ix]) ? $columnas[$ix] : array();
  $columnas[$ix][] = $articulo;
}
}
?>
<?php foreach($columnas as $posts):?> etc, etc ... <?php endforeach; ?>

$cols の値は、ユーザーのウィンドウ画面に応じて変化します。IE = ウィンドウ画面が (何らかの値) の場合、$cols = (何らかの値)

これについて何か助けていただければ幸いです。

乾杯!

4

1 に答える 1

0

ページのロード時に ajax スクリプトを使用するようなことができます。これによりサイトが遅くなりますが、適切な効果が得られるはずです。

HTML

<div class="container">
    <!-- Place columns here -->
</div>

jQuery

$(document).load(function(){
    var winWidth = $(window).width();
    $.post('phpscript', {width: winWidth}, function(data) {
        $('.container').html(data);
    });
});

PHP

<?PHP
    //Your PHP script to format your page in however many columns
    //Have your script here take the width of your page
    //Do do math to find how many columns
    //Query whatever you need to get those columns
    //Return the HTML
?>

これにより、必要な列レイアウトを返すことができます。ただし、必要な数の列を作成するための優れた CSS を作成する方が簡単だと確信しています。

于 2013-04-25T18:57:38.590 に答える