0

伙计们...我在这里遇到问题...

我想在中间的分类存档页面中插入广告,好的,是这样的情况:

在我的主题(Fastheme)的类别存档页面中,如果您选择类别列表之一,我有 1 个视图:例如“精选”

Total output Category 选定的(10 个帖子)显示列表类别存档页面。

显示类别“精选”(1 个帖子)

显示类别“精选”(2 个帖子)

显示类别“精选”(3 个帖子)

显示类别“精选”(4 个帖子)

<-- 定位广告-->

显示类别“精选”(5 个帖子)

显示类别“精选”(6 个帖子)

显示类别“精选”(7 个帖子)

显示类别“精选”(8 个帖子)

显示类别“精选”(9 个帖子)

显示类别“精选”(10 个帖子)

以下是我的类别存档页面上的代码:

<div class="posta">
    <h1><?php if(is_category()) { ?> <?php single_cat_title(''); ?> News and Pictures
        <?php } elseif (is_day()) { ?><?php the_time('F jS, Y'); ?>
        <?php } elseif (is_month()) { ?> <?php the_time('F, Y'); ?>
        <?php } elseif (is_tag()) { ?> <?php single_tag_title(''); ?>
        <?php } elseif (is_year()) { ?> <?php the_time('Y'); ?>
        <?php } elseif (is_author()) { ?> Author
        <?php } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?> Blog Archives
        <?PHP } ?><?php  if ( get_query_var('paged') ) { echo ' ('; echo __('page') . ' ' . get_query_var('paged');   echo ')';  } ?>
    </h1>
</div>

        <?php $postcounter = 1; if (have_posts()) : ?>
            <?php while (have_posts()) : $postcounter = $postcounter + 1; the_post(); $do_not_duplicate = $post->ID; $the_post_ids = get_the_ID(); ?>

                <div class="post post-<?php echo $postCount ;?>" style="width:755px;float:right"><?php include (TEMPLATEPATH . '/thumb.php'); ?>
                    <div class="posttitle">
                        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
                    </div>
                    <div class="tags"><?php the_time('M jS Y') ?> | <?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></div>
                    <?php echo excerpt(50); ?><?php if ( is_home() || is_category() || is_tag()) : ?>&nbsp;<?php endif; ?>
                    <p class="readmore"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">...learn more</a></p>
                    <div style="clear: both"></div>
                </div>
            <?php endwhile; ?>
            <?php else : ?>
            <div class="notfound"></div>
            <div class="post"><center><h2>404 Not Found</h2></center></div>
            <?php endif; ?>

请帮我。!

4

3 回答 3

0

如果您想让广告显示在中间,您可以执行以下操作:

<div class="posta">
    <h1><?php if(is_category()) { ?> <?php single_cat_title(''); ?> News and Pictures
        <?php } elseif (is_day()) { ?><?php the_time('F jS, Y'); ?>
        <?php } elseif (is_month()) { ?> <?php the_time('F, Y'); ?>
        <?php } elseif (is_tag()) { ?> <?php single_tag_title(''); ?>
        <?php } elseif (is_year()) { ?> <?php the_time('Y'); ?>
        <?php } elseif (is_author()) { ?> Author
        <?php } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?> Blog Archives
        <?PHP } ?><?php  if ( get_query_var('paged') ) { echo ' ('; echo __('page') . ' ' . get_query_var('paged');   echo ')';  } ?>
    </h1>
</div>

<?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); $the_post_ids = get_the_ID(); ?>

        <?php if (floor($post_count/2) == $current_post) : ?>

            // Your add code here

        <?php endif; ?>

        <div class="post post-<?php echo $postCount ;?>" style="width:755px;float:right"><?php include (TEMPLATEPATH . '/thumb.php'); ?>
            <div class="posttitle">
                <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
            </div>
            <div class="tags"><?php the_time('M jS Y') ?> | <?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></div>
            <?php echo excerpt(50); ?><?php if ( is_home() || is_category() || is_tag()) : ?>&nbsp;<?php endif; ?>
            <p class="readmore"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">...learn more</a></p>
            <div style="clear: both"></div>
        </div>
    <?php endwhile; ?>
<?php else : ?>
        <div class="notfound"></div>
        <div class="post"><center><h2>404 Not Found</h2></center></div>
<?php endif; ?>

$current_postis 在循环中保存当前帖子的索引

$post_count是当前页面中显示的帖子总数

阅读https://codex.wordpress.org/Class_Reference/WP_Query了解更多信息。

于 2013-04-16T06:35:04.963 回答
0

维维克·曼格拉尼。在我使用您提供的代码后,这里发生的是......

Display Category "featured" (1 Posts)
// Your code here add
Display Category "featured" (2 Posts)
// Your code here add
Display Category "featured" (3 Posts)
// Your code here add
Display Category "featured" (4 Posts)
/ / Your code here add
Display Category "featured" (5 Posts)
/ / Your code here add

等等。如果想让它变成这样怎么办?

Display Category "featured" (1 Posts)
Display Category "featured" (2 Posts)
Display Category "featured" (3 Posts)
Display Category "featured" (4 Posts)

<- Position Ads ->

Display Category "featured" (5 Posts)
Display Category "featured" (6 Posts)
Display Category "featured" (7 Posts)
Display Category "featured" (8 Posts)
Display Category "featured" (9 Posts)
Display Category "featured" (10 Posts)

请告诉我。

于 2013-04-16T12:39:21.077 回答
0

你可以试试,

<?php while (have_posts()) : the_post(); $the_post_ids = get_the_ID(); $i ++?>
<?php if ($i == 5) : ?>
            // Your Ad Code Here
<?php endif; ?>
于 2017-03-25T20:19:57.240 回答