Skip to main content

Displaying wordpress post contents in multiple columns

There are some template files for displaying post contents in excerpt or full-length form in wordpress like index.php, category.php, archive.php etc. If it is wanted to be displayed post contents in the form of multiple columns, following changes may give the desired result.

put these lines of code after <?php if ( have_posts() ) : ?> and just before <?php while ( have_posts() ) : the_post(); ?> loop:

echo "<table>";
$column = 0

inside the while loop, put <tr> and <td> just after <?php while ( have_posts() ) : the_post(); ?>

if ($column == 0) echo "<tr>";
echo "<td width='50%'>";

Now it comes to close <td> tag after the post content. Post content generally appears similar to <?php get_template_part( 'content', get_post_format() ); ?>

echo "</td>";

Then if the number of columns are reached desired value, close the <tr> tag:

if ($column == 2) {
echo "</tr>";

close the <table> after the <?php endwhile; ?> loop:

echo "</table>";
These changes produce two columns. For more colums just change <td width='50%'> and if ($column == 2) with appropriate values accordingly.


Popular posts from this blog