Suporte » Temas e templates » mostrar posts através do LOOP e adicionar 1 class por post Par ou Impar

  • Resolvido morpheuz2006

    (@morpheuz2006)


    Alguém me consegue ajudar a converter este código para mostrar posts da seguinte forma:

    p1 || p2
    p3 || p4
    p5 || p6

    <div class=”experiencias”>
    <div class=”container”>
    <div class=”exp-top”>
    <h3 class=”top-title”>Sobre</h3>
    <span class=”line”></span>
    </div>
    <div class=”exp-devide”>
    <h4>Experience</h4>
    <span class=”devide-line”>
    </span>
    <label class=”bag”></label>
    <div class=”exp-devide-grid-right”>
    <h5>DESIGNER</h5>
    <small>data</small>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s</p>
    </div>

    <div class=”exp-devide-grid-rightb”>
    <h5><?php the_title(); ?></h5>
    <small>data</small>
    <p><?php the_content(); ?></p>
    </div>

    <div class=”exp-devide-grid-left”>
    <h5>JUNIOR UI DESIGNER</h5>
    <small>Microsoft – 2014 . 2015</small>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s</p>
    </div>
    <div class=”exp-devide-grid-rightb”>
    <h5>web-designer</h5>
    <small>- 2006 . 2010</small>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s</p>
    </div>
    </div>

A visualizar 5 respostas - de 1 a 5 (de um total de 5)
  • Olá,
    Você pode usar essa função no seu arquivo function

    function impar_par() {
    global $post_num;
    if ( ++$post_num % 2 )
    $class = ‘par’;
    else
    $class = ‘impar’;
    echo $class;
    }

    E no html do seu loop você chama ela assim por exemplo:
    <div class=”exp-devide-grid-rightb <?php impar_par(); ?>”>

    Espero que tenha ajudado.
    Abraço

    Thread Starter morpheuz2006

    (@morpheuz2006)

    ola Digo Ribeiro

    antes de mais nada muito obrigado pela dica… simplificaste bastante o meu problema, mas mesmo assim ainda não consegui resolver..

    deixo o fidler para veres se me consegues ajudar mais um pouco…

    https://jsfiddle.net/morpheuz2000/wptbwpr2/

    Olá,
    Eu meio que “refiz” o seu código, mas de maneira bem superficial.
    Ela esta disponível aqui http://jsfiddle.net/digoribeiro/yzx60uzx/
    Espero que tenha ajudado.
    Qualquer coisa estou a disposição.
    Até mais.

    Thread Starter morpheuz2006

    (@morpheuz2006)

    obrigado 😀 muito bom… você é impecável… deixo o codigo completo para quem precisar…

    Muito obrigado :Digo Ribeiro

    no function.php

    function impar_par() {
    global $post_num;
    if ( ++$post_num % 2 )
    $class = 'exp-devide-grid-left';
    else
    $class = 'exp-devide-grid-right';
    echo $class;
    }

    no index.php

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    div class="exp-devide-grid <?php impar_par(); ?>">
    	<h2><?php the_title() ;?></h2>
    	<?php the_post_thumbnail(); ?>
    	<?php the_excerpt(); ?>
                    </div>
    <?php endwhile; else: ?>
    	<p>Não existem Posts</p>
    
    <?php endif; ?>

    Fico feliz em ter ajudado!
    Até mais.

A visualizar 5 respostas - de 1 a 5 (de um total de 5)
  • O tópico ‘mostrar posts através do LOOP e adicionar 1 class por post Par ou Impar’ está fechado a novas respostas.