• Resolved xrun

    (@xrun)


    Hi.
    I need to load an ad at certain intervals on index pages, and I’m trying this code:

    <?php /* Start the Loop */ ?>
    <?php $count = 0 ; /* Setting count to zero for ads interval */ ?>
    <?php while ( have_posts() ) : the_post(); ?>
    	<?php get_template_part( 'content', get_post_format() ); ?>
    	<?php /* Getting the minibanner ad at certain intervals along the list of entries down the page */
    	$count= $count+1;
    	if($count(array('1', '5', '10', '15', true))) { include("ads/minibanner.php") ; } ; ?>
    <?php endwhile; ?>

    This gives me a “Fatal error: Function name must be a string in /mounted-storage/…” and so on, indicating line 33 which is this line:

    if($count(array('1', '5', '10', '15', true))) { include("ads/minibanner.php") ; } ; ?>

    This is in the twentyeleven theme, slightly modified but have left the functions.php file alone so far.

    Any pointers?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    [untested] Try changing this:

    $count= $count+1;
    if($count(array('1', '5', '10', '15', true))) { include("ads/minibanner.php") ; } ; ?>

    to this:

    $count++;
    if($count == 1 || ($count % 5 == 0 )) { include("ads/minibanner.php") ; }  ?>

    Thread Starter xrun

    (@xrun)

    That works excellent. Thank you very much! 🙂

    Thread Starter xrun

    (@xrun)

    Btw: your code sets an interval of 5 right? So if the number 5 is changed to 4 then that’s the interval?

    Moderator keesiemeijer

    (@keesiemeijer)

    Yes to both questions. Glad you got it resolved.

    Thread Starter xrun

    (@xrun)

    Thank you, and seasons greetings from Norway. 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Conditionally including a php file in the template’ is closed to new replies.