Доброго времени суток! Нужно вывести рекламу между постами, информация в и-нете не помогла, перерыл 100500 страниц Яндекса и гугла, везде одно решение:
1. Зарегистрировать область под виджет (с этим проблем нет!)
register_sidebar( array(
'name' => 'Реклама между постами №1',
'id' => 'reklama-post1',
'before_widget' => '<div id="%1$s" style="margin:5px auto;" class="%2$s widget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );
2. Здесь начинаются проблемы! Надо создать счетчик отсчета постов и соответственно сам вывод рекламы.Вот, что предлогает интернет:
В index.php найти строчку
<?php while (have_posts()) : the_post(); ?>
вставить в нее $postcounter++;
чтобы получилось так
<?php while (have_posts()) : the_post(); $postcounter++; ?>
далее перед <?php endwhile; ?>
вставить
<?php if ($postcounter % 2 == 0) : ?><?php dynamic_sidebar('reklama-post1') ?><?php endif; ?>
Так вот мне этот способ не подходит у меня index.php немного другой.
Тема root сайт ladyby.ruПомогите пожалуйста!
Заранее спасибо!
1. Зарегистрировать область под виджет (с этим проблем нет!)
register_sidebar( array(
'name' => 'Реклама между постами №1',
'id' => 'reklama-post1',
'before_widget' => '<div id="%1$s" style="margin:5px auto;" class="%2$s widget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );
2. Здесь начинаются проблемы! Надо создать счетчик отсчета постов и соответственно сам вывод рекламы.Вот, что предлогает интернет:
В index.php найти строчку
<?php while (have_posts()) : the_post(); ?>
вставить в нее $postcounter++;
чтобы получилось так
<?php while (have_posts()) : the_post(); $postcounter++; ?>
далее перед <?php endwhile; ?>
вставить
<?php if ($postcounter % 2 == 0) : ?><?php dynamic_sidebar('reklama-post1') ?><?php endif; ?>
Так вот мне этот способ не подходит у меня index.php немного другой.
| Код |
|---|
<?php
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<?php if ( have_posts() ) : ?>
<?php //if ( is_customize_preview() ) { echo '<div class="customizer-add-block">Добавить блок</div>'; } ?>
<?php if ( is_home() && ! is_front_page() ) : ?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
</header>
<?php endif; ?>
<?php if ( 'top' == root_get_option( 'structure_home_position' ) ) get_template_part( 'template-parts/home', 'content' ); ?>
<?php
if ( is_home() ) {
$is_show_on_paged = root_get_option( 'structure_slider_show_on_paged' );
if ( ! is_paged() || ( $is_show_on_paged && is_paged() ) ) {
get_template_part( 'template-parts/slider', 'posts' );
}
}
?>
<?php get_template_part( 'template-parts/layout/archive', root_get_option( 'structure_home_posts' ) ); ?>
<?php the_posts_pagination(); ?>
<?php if ( 'bottom' == root_get_option( 'structure_home_position' ) ) get_template_part( 'template-parts/home', 'content' ); ?>
<?php else : ?>
<?php get_template_part( 'template-parts/content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
if ( root_get_option( 'structure_home_sidebar' ) != 'none' ) get_sidebar();
get_footer();
|
Тема root сайт ladyby.ruПомогите пожалуйста!
Заранее спасибо!
