0

guys ... I get a problem here ...

I want to insert ads in the middle category archive page, Ok, this is the situation:

In the category archive page of my theme (Fastheme) I have 1 view's, if you select one of the list of categories: example "featured"

Total output Category the selected (10 Posts) Display List Category Archive page.

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)

The following is the code that is on my Category Archive Page:

<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; ?>

please help me.!

3 Answers3

0

If you want to have the ad displayed in the middle you can do something like this:

<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_post is holds the index of the current post in the loop

$post_count is the total displayed post in the current page

Read https://codex.wordpress.org/Class_Reference/WP_Query for more information.

0

Vivek Manglani. After I used the code you provided, that happens here is ...

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

and so on. what if want to make it like this?

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)

please let me know.

0

You can try,

<?php while (have_posts()) : the_post(); $the_post_ids = get_the_ID(); $i ++?>
<?php if ($i == 5) : ?>
            // Your Ad Code Here
<?php endif; ?>
Saksham
  • 13
  • 4