Bonjour à tous
Je suis un Papy de 57 ans et j'ai quelques lacunes en code. J'ai terminé un site de petites annonces et j'ai juste un problème d'affichage que je n'arrive pas à régler.
En effet le code ci-dessous affiche la totalité des annonces sur une seule ligne et le mieux serait qu'elle s'affiche sur plusieurs lignes de 5 ou 6 annonces. J'ai beau essayer, je n'y arrive pas, quelqu'un aurait il une idée ?
D'avance merci
Bertrabd

<table width="100%">
<?php if ($this->_tpl_vars'records']): ?>
    <div class="subhead1"><?php echo @INDEX_FEATURED; ?></div>

    <?php $_from = $this->_tpl_vars'records']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars'image']):
?>

<?php if ($this->_tpl_vars'use_fancy_urls']): ?>
<td><a href="listings/view/<?php echo ((is_array($_tmp=$this->_tpl_vars'image']'departement'])) ? $this->_run_mod_handler('strip', true, $_tmp, "-") : smarty_modifier_strip($_tmp, "-")); ?>/<?php echo ((is_array($_tmp=$this->_tpl_vars'image']'model'])) ? $this->_run_mod_handler('strip', true, $_tmp, "-") : smarty_modifier_strip($_tmp, "-")); ?>
/<?php echo $this->_tpl_vars'image']'listingid']; ?>/"><img src="<?php echo $this->_tpl_vars'image']'imagethumbpath']; ?>" title="<?php echo $this->_tpl_vars'image']'ad_title']; ?>" alt="<?php echo $this->_tpl_vars'image']'ad_title']; ?>" /></a></td>
<?php else: ?>
<td><a href="listings.php?departement=<?php echo ((is_array($_tmp=$this->_tpl_vars'image']'departement'])) ? $this->_run_mod_handler('strip', true, $_tmp, "-") : smarty_modifier_strip($_tmp, "-")); ?>&model=<?php echo ((is_array($_tmp=$this->_tpl_vars'image']'model'])) ? $this->_run_mod_handler('strip', true, $_tmp, "-") : smarty_modifier_strip($_tmp, "-")); ?>
&id=<?php echo $this->_tpl_vars'image']'listingid']; ?>"><img src="<?php echo $this->_tpl_vars'image']'imagethumbpath']; ?>
" title="<?php echo $this->_tpl_vars'image']'ad_title']; ?><?php echo $this->_tpl_vars'image']'villes']; ?> dans le département <?php echo $this->_tpl_vars'image']'departement']; ?>
" alt="<?php echo $this->_tpl_vars'image']'ad_title']; ?><?php echo $this->_tpl_vars'image']'villes']; ?> dans le département <?php echo $this->_tpl_vars'image']'departement']; ?>
" />
        <?php endif; ?>
        <br /><div class="subhead0" align="center"><?php echo $this->_tpl_vars'image']'ad_title']; ?></div><br /></a></td>
<?php endforeach; endif; unset($_from); ?>
</table>

7 réponses


Carouge10
Réponse acceptée
<table width="100%">
    <tr>
    <?php if ($this->_tpl_vars'records']): ?>
        <div class="subhead1"><?php echo @INDEX_FEATURED; ?></div>
        <?php
        $_from = $this->_tpl_vars'records'];
        if (!is_array($_from) && !is_object($_from)) { 
           settype($_from, 'array');
        }
        $i = 0;
        ?>
        <?php if (count($_from)): ?>
            <?php foreach ($_from as $this->_tpl_vars'image']): ?>
                <?php
                    if(($i % 4) == 0)
                        echo "</tr><tr>";
                ?>
                <?php if ($this->_tpl_vars'use_fancy_urls']): ?>
                    <td><a href="listings/view/<?php echo (is_array($_tmp = $this->_tpl_vars'image']'departement']) ? $this->_run_mod_handler('strip', true, $_tmp, "-") : smarty_modifier_strip($_tmp, "-")); ?>/<?php echo ((is_array($_tmp = $this->_tpl_vars'image']'model'])) ? $this->_run_mod_handler('strip', true, $_tmp, "-") : smarty_modifier_strip($_tmp, "-")); ?>
                    /<?php echo $this->_tpl_vars'image']'listingid']; ?>/"><img src="<?php echo $this->_tpl_vars'image']'imagethumbpath']; ?>" title="<?php echo $this->_tpl_vars'image']'ad_title']; ?>" alt="<?php echo $this->_tpl_vars'image']'ad_title']; ?>" /></a>
                <?php else: ?>
                    <td><a href="listings.php?departement=<?php echo ((is_array($_tmp=$this->_tpl_vars'image']'departement'])) ? $this->_run_mod_handler('strip', true, $_tmp, "-") : smarty_modifier_strip($_tmp, "-")); ?>&model=<?php echo ((is_array($_tmp=$this->_tpl_vars'image']'model'])) ? $this->_run_mod_handler('strip', true, $_tmp, "-") : smarty_modifier_strip($_tmp, "-")); ?>
                    &id=<?php echo $this->_tpl_vars'image']'listingid']; ?>"><img src="<?php echo $this->_tpl_vars'image']'imagethumbpath']; ?>
                    " title="<?php echo $this->_tpl_vars'image']'ad_title']; ?><?php echo $this->_tpl_vars'image']'villes']; ?> dans le département <?php echo $this->_tpl_vars'image']'departement']; ?>
                    " alt="<?php echo $this->_tpl_vars'image']'ad_title']; ?><?php echo $this->_tpl_vars'image']'villes']; ?> dans le département <?php echo $this->_tpl_vars'image']'departement']; ?>
                    " />
                <?php endif; ?>
                <br /><div class="subhead0" align="center"><?php echo $this->_tpl_vars'image']'ad_title']; ?></div><br /></a></td>
                <?php 
                    $i++; 
                ?>
            <?php endforeach; ?>
        <?php endif; ?>
    <?php endif; ?>
    </tr>
</table>
<?php
unset($_from);
bertrandg17
Auteur
Réponse acceptée

En grand MERCI Carouge10, ça fonctionne parfaitement et c'est tout à fait la mise en page que je voulais.
Bravo et encore MERCI
Cordialement
Bertrand

Bonjour bertrandg17,

Il n'y a pas de <tr> dans votre tableau.
Il serait judicieux de l'ajouter à chaque passage de boucle

<?php foreach(...) ?>
<tr>    
    <?php if(..): ?> <td>...</td>
    <?php else: ?> <td>...</td>
</tr>
<?php endforeach; ?>

Cordialement
M. (#mLF)

Merci à vous deux pour vos conseils, je viens de regarder la vidéo, mais elle ne semble pas correspondre tout à fait à mon problème, en me relisant il est vrai que je n'ai pas été très clair. Mieux vos des images pour mieux m'exprimer.
Evidement à mon âge je travaille plus facilement sur Papyrus :)

La réalité

Ce que j'aimerai avoir

Bonjour

Ceci devrait vous aider:

<table width="100%">
    <tr>
<?php if ($this->_tpl_vars'records']): 
    $i = 0; ?>

    <div class="subhead1"><?= @INDEX_FEATURED; ?></div>

    <?php $_from = $this->_tpl_vars'records']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars'image']): ?>

    <?php if ($this->_tpl_vars'use_fancy_urls']): ?>
        <td><a href="listings/view/<?= ((is_array($_tmp=$this->_tpl_vars'image']'departement'])) ? $this->_run_mod_handler('strip', true, $_tmp, "-") : smarty_modifier_strip($_tmp, "-")); ?>/<?= ((is_array($_tmp=$this->_tpl_vars'image']'model'])) ? $this->_run_mod_handler('strip', true, $_tmp, "-") : smarty_modifier_strip($_tmp, "-")); ?>
        /<?= $this->_tpl_vars'image']'listingid']; ?>/"><img src="<?= $this->_tpl_vars'image']'imagethumbpath']; ?>" title="<?= $this->_tpl_vars'image']'ad_title']; ?>" alt="<?= $this->_tpl_vars'image']'ad_title']; ?>" /></a>
    <?php else: ?>

        <td><a href="listings.php?departement=<?= ((is_array($_tmp=$this->_tpl_vars'image']'departement'])) ? $this->_run_mod_handler('strip', true, $_tmp, "-") : smarty_modifier_strip($_tmp, "-")); ?>&model=<?= ((is_array($_tmp=$this->_tpl_vars'image']'model'])) ? $this->_run_mod_handler('strip', true, $_tmp, "-") : smarty_modifier_strip($_tmp, "-")); ?>
        &id=<?= $this->_tpl_vars'image']'listingid']; ?>"><img src="<?= $this->_tpl_vars'image']'imagethumbpath']; ?>
        " title="<?= $this->_tpl_vars'image']'ad_title']; ?><?= $this->_tpl_vars'image']'villes']; ?> dans le département <?= $this->_tpl_vars'image']'departement']; ?>
        " alt="<?= $this->_tpl_vars'image']'ad_title']; ?><?= $this->_tpl_vars'image']'villes']; ?> dans le département <?= $this->_tpl_vars'image']'departement']; ?>
        " />
    <?php endif; ?>
        <br /><div class="subhead0" align="center"><?= $this->_tpl_vars'image']'ad_title']; ?></div><br /></a></td>
        $i++;
    <?php 
        if(($i % 4) == 0)
            echo "</tr><tr>";
    ?>
<?php endforeach; endif; unset($_from); ?>
        </tr>
</table>

J'ai appliquer ce que vous a dit maximeshr en ajoutant des ligne à votre tableau "<tr></tr>"
De plus à la ligne 27, je fais un test pour savoir si nous avons 4 annonces, si oui, je termine ma ligne et en commence une autre, sinon je continue.

Bonjour Carouge10,
Merci pour votre aide, mais voici le résultat à l'affichage.
Comme je suis une bille, je ne veux pas mobiliser tout votre temps sur ce problème.

Cordialement
Bertrand

Je vous en prie.