Три столбца на главной
-
Подскажите, как сделать, чтобы на главной отображались анонсы постов в 3 столбца. Например:
1 2 3
4 5 6
7 8 9
10 11 12
-
Приведу пример на Теме оформления TwentyTwelve, WP 3.5
Открываете файл index.php этой Темы, находите этот участок:<?php if ( have_posts() ) : ?> <?php /* Start the Loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', get_post_format() ); ?> <?php endwhile; ?>
И дополняете такими строками:
<?php if ( have_posts() ) : $count = 0; //активировали счетчик ?> <?php /* Start the Loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <div class="column<?php if( $count%3 == 0 ) { echo '-1'; }; $count++; ?>"> <?php get_template_part( 'content', get_post_format() ); ?> </div> <?php endwhile; ?>
В файл
style.css
добавляем такие строки (внизу):.column-1 { float:left; clear:left; width: 30%; margin-left: 0; } .column { float:left; width: 30%; margin-left: 3%; }
На выходе получаем это скрин.
Кратко — до основного цикла создаете счетчик$count = 0;
В цикле, вывод контента (заголовков, поста, мета информации) обрамляете своим блоком, (у меня в примере это класс.column
, который обрамляет блок<article>
и применяете своё стилевое оформление.UPD Typo fix 🙂
<?php if ( have_posts() ) : $count = 2; //активировали счетчик = 2 ?>
у меня в Index.php нету такого..тема стандартная, twentyten
вот из чего состоит мой index.php
<?php include_once("analyticstracking.php") ?> <?php /** * The main template file. * * This is the most generic template file in a WordPress theme * and one of the two required files for a theme (the other being style.css). * It is used to display a page when nothing more specific matches a query. * E.g., it puts together the home page when no home.php file exists. * Learn more: http://codex.wordpress.org/Template_Hierarchy * * @package WordPress * @subpackage Twenty_Ten * @since Twenty Ten 1.0 */ get_header(); ?> <div id="container"> <div id="content" role="main"> <?php /* Run the loop to output the posts. * If you want to overload this in a child theme then include a file * called loop-index.php and that will be used instead. */ get_template_part( 'loop', 'index' ); ?> </div><!-- #content --> </div><!-- #container --> <?php get_sidebar(); ?> <?php get_footer(); ?>
вот из чего состоит мой index.php
И? Что не получается-то? Готовый скрипт под руками (точнее под мышкой), копируйте, пробуйте.
копировал, пробовал, при открытии сайта, ошибка в линии такойто
в loop только три строчки что ли добавить?
[offtop]
О, новый мегасервис пошел в ход… Здорово!
- Тема «Три столбца на главной» закрыта для новых ответов.