WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Conditionally including a php file in the template (6 posts)

  1. xrun
    Member
    Posted 2 years ago #

    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?

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    [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") ; }  ?>
  3. xrun
    Member
    Posted 2 years ago #

    That works excellent. Thank you very much! :)

  4. xrun
    Member
    Posted 2 years ago #

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

  5. keesiemeijer
    moderator
    Posted 2 years ago #

    Yes to both questions. Glad you got it resolved.

  6. xrun
    Member
    Posted 2 years ago #

    Thank you, and seasons greetings from Norway. :)

Topic Closed

This topic has been closed to new replies.

About this Topic