• Resolved markyeoj

    (@markyeoj)


    hello guys, I really have this serious problem.

    here is my code for my archive page

    https://pastebin.com/r6BtEUuX
    and I have three widgets for advertisement.

    What I want is an advertisement after every three posts. I am displaying twelve posts per page, so 3 ads every page.. and those 3 ads must came from the 3 widgets for ads. Please help regarding this. thanks.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Firstly, can you elaborate more on the ‘Should com from the 3 widgets for ads.’ What are the widgets, how do you connect to them to retrieve the ads?

    Secondly, I’m no maths wiz, but 12/3 = 4, not 3. Or do you not want one at the bottom of the list of posts?

    My first thought though is that as you are using the The Loop, just add a counter to it and include an ad if the number is devisable by 3.

    Befor The Loop –

    $i=0;

    After post display in The Loop –

    $i++;
    if($i%3 === 0 && $i <= 9) : // Set $i <= 9 to prevent ad showing at the end of The Loop
        /** Display your add here */
    endif;
    Thread Starter markyeoj

    (@markyeoj)

    well, what I want is between the three posts,I dont want to display ads after the 12th posts. I already accomplished that by using this code..

    https://pastebin.com/gMHLjBvw

    the only problem is, It only displays an ads form a single widget. I want every ad must came from the 3 widgets.

    Ok, so it’s this that is displaying the add? – dynamic_sidebar('Header Ad');

    If so, and if you have the names for the other 2 widgets, you could put the names in to an array before The Loop and call one of them randomly –

    $widget_names = array(
        'Header Ad',
        'Header Ad 2',
        'Header Ad 3'
    );

    and then –

    'dynamic_sidebar($widget_names[rand(0, 2)]);

    Or if you wan’t the widgets used in order, add a second counter that increases after every 3rd post and use that counter to get the corred widget name.

    Thread Starter markyeoj

    (@markyeoj)

    <?php
    				$Archive_Ads = array(
        				'Archive Ad1',
        				'Archive Ad2',
        				'Archive Ad3'
    				);
    				if ($i % 3 === 0):
    				if (function_exists('dynamic_sidebar'($Archive_Ads[rand(0, 2)]);) ) :
                    endif;
    				endif;
    				?>

    whats wrong with my code? it’s not working..

    Try this –

    $Archive_Ads = array(
        'Archive Ad1',
        'Archive Ad2',
        'Archive Ad3'
    );
    if ($i % 3 === 0):
        if (function_exists('dynamic_sidebar') :
            dynamic_sidebar($Archive_Ads[rand(0, 2)]));
        endif;
    endif;

    Obviously your widgets (whihc I assume are custom?) would have to be called ‘Archive Ad1’, ‘Archive Ad2’ and ‘Archive Ad3’

    Thread Starter markyeoj

    (@markyeoj)

    sorry bro, I tried to figure it out but still, not yet working

    Parse error: syntax error, unexpected ‘:’ in /home/pinoytop/public_html/livelong/wp-content/themes/livelong/archive.php on line 69

    $Archive_Ads = array(
        'Archive Ad1',
        'Archive Ad2',
        'Archive Ad3'
    );
    if ($i % 3 === 0):
        if (function_exists('dynamic_sidebar') :/*this is the line 69*/
            dynamic_sidebar($Archive_Ads[rand(0, 2)]));
        endif;
    endif;

    I missed a close bracket ‘)’ before the colon ‘:’ – add that and the syntax should be ok.

    Thread Starter markyeoj

    (@markyeoj)

    Thank you so much!, It works.. ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘archive looping’ is closed to new replies.