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>";
$column=$column+1;
Then if the number of columns are reached desired value, close the <tr> tag:
if ($column == 2) {
echo "</tr>";
$column=0;
}
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.
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>";
$column=$column+1;
Then if the number of columns are reached desired value, close the <tr> tag:
if ($column == 2) {
echo "</tr>";
$column=0;
}
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.
Comments
Post a Comment