2016-06-13 13 views
-2

Ich versuche herauszufinden, die Wordpress-Beiträge in meiner Blog-Seite in verschiedenen Spalten anzuzeigen. Beispiel: Die ersten zwei Beiträge in zwei Zeilen, die restlichen Beiträge in zwei Spalten nacheinander.Wordpress-Beiträge in verschiedenen Spalten anzeigen

Wie kann ich Beiträge anzeigen, die als angehängt sind?

Vielen Dank im Voraus!

enter image description here

Und hier ist mein Code.

<div class="container"> 
<div class="row"> 
    <div class="col-xs-12 col-sm-6"> 
       <?php 
       $news_args = array(
        'cat' => 3, 
        'paged' => get_query_var('paged'), 
        'posts_per_page' => 4, 
        'orderby' => 'post_date', 
        'order' => 'DESC', 
       ); 
       $news_query = new WP_Query($news_args); 
       if ($news_query->have_posts()) : 
       while ($news_query->have_posts()) : $news_query->the_post(); 
       ?> 

           <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> 
            <p><span><?php the_time('F j, Y'); ?> 
            </span> 
            <span><?php echo "By: ".get_the_author(); ?> 
            </span> 
            <span> 
            <?php 
            $commentcount = comments_number('0', '1', '%'); 
            $fulltitle = $title . ' (' . $commentcount . ' comments)'; 
            ?>Comments<?php wp_count_comments($post_id); ?> 
            </span></p> 

           <figure class="fig_rel1"> 
           <?php the_post_thumbnail(); ?> 
           </figure> 
           <p> 
           <?php 
           $content = get_the_content('',FALSE,''); 
           $content = apply_filters('the_content', $content); 
           $content = str_replace(']]>', ']]>', $content); 
           echo substr($content,0,300).'<a href="'. get_permalink($post->ID) .'">Read More &raquo; </a>'; 
           ?> 
           </p> 

       <?php 
       endwhile; 
       previous_posts_link('prev', $news_query->max_num_pages); 
       echo ' &mdash; '; 
       next_posts_link('next', $news_query->max_num_pages); 
       endif; 
       ?> 

       </div> 
       </div> 
       </div> 
+0

Also, was ist die Frage? – Epodax

+0

Wie kann ich das selbe wie angebracht anzeigen? –

+0

Also, was hast du probiert, um das obige Design zu bekommen? – Epodax

Antwort

1

Es kann Ihnen helfen.

+0

Es werden 2 Beiträge pro Seite angezeigt –

+0

@ Mahbubur Rahman. Ich möchte das gleiche machen wie http://www.rugsusa.com/blog/ –

+0

Nichts ist passiert. Ich habe Bootstrap verwendet, um Spaltenraster zu erstellen. Ich kann Ihren Code nicht mit HTML-Tags versehen. Hast du meinen gesamten Code gesehen? Bitte helfen Sie mit .. –

0

Versuchen Sie, die folgende Methode zu implementieren.

$count = 0; 

while (have_posts()) : the_post(); 

    if ($count < 2) { 
     //code to populate first two post 
     $count++; 
    }else 
     //code to populate remaining posts 
     $count++; 
    } 

endwhile; 
+0

Wohin mit meinem Code? –

0

Und schließlich habe ich die Lösung, wenn Bedingung in Spalten geteilt "div" Tag gesetzt.

Hier ist die endgültige Lösung.

<div class="container"> 
<div class="row"> 
    <div class="col-xs-12 col-sm-8"> 
     <div class="container-fluid"> 
      <div class="row"> 
       <div class="col-xs-12 col-sm-12"> 
       <div class="row"> 
       <div class="ka-justcontent"> 
       <?php 
       $news_args = array(
        'cat' => 3, 
        'paged' => get_query_var('paged'), 
        'posts_per_page' => 4, 
        'orderby' => 'post_date', 
        'order' => 'DESC', 
       ); 
       $news_query = new WP_Query($news_args); 
       $i = 0; 
       if ($news_query->have_posts()) : 
       while ($news_query->have_posts()) : $news_query->the_post(); 
       ?> 
          <div <?php if($i<2){?> class="col-md-12" <?php } else {?> class="col-xs-12 col-sm-6 col-md-6" <?php }?> > 
          <!-- Previous Next --> 
           <div class="survey"> 
           <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> 
            <p><span><?php the_time('F j, Y'); ?> 
            </span> 
            <span><?php echo "By: ".get_the_author(); ?> 
            </span> 
            <span> 
            <?php 
            $commentcount = comments_number('0', '1', '%'); 
            $fulltitle = $title . ' (' . $commentcount . ' comments)'; 
            ?>Comments<?php wp_count_comments($post_id); ?> 
            </span></p> 
           </div> 
           <figure class="fig_rel1"> 
           <?php the_post_thumbnail(); ?> 
           </figure> 
           <p> 
           <?php 
           $content = get_the_content('',FALSE,''); 
           $content = apply_filters('the_content', $content); 
           $content = str_replace(']]>', ']]>', $content); 
           echo substr($content,0,300).'<a href="'. get_permalink($post->ID) .'">Read More &raquo; </a>'; 
           ?> 
           </p> 
          </div> 
       <?php 
       $i++; 
       endwhile; 
       previous_posts_link('prev', $news_query->max_num_pages); 
       echo ' &mdash; '; 
       next_posts_link('next', $news_query->max_num_pages); 
       endif; 
       ?> 
       </div> 
       </div> 
       </div>    
      </div> 
     </div> 
    </div> 
</div> 

Verwandte Themen