• Resolved otis1991

    (@otis1991)


    I needed a permanent slider above the posts on a home page. So I created the slider and inserted the following short code near the top of content.php, right after opening PHP statement and just above the post code. Here’s the first few lines (condensed):
    <?php …
    ?>
    <?php if (is_front_page()) {echo do_shortcode(“[metaslider id=40]”);}?>
    <article id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>
    <?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
    <div class=”featured-post”> …etc.

    Weirdly, the slider’s CSS styles show up underneath each post on the page. Somehow the slider code is getting caught up in the post loop, although the slider itself only shows up once. Its just the CSS styles (border and margin) that repeat.

    I also replaced the slider code with <?php echo (“HELLO!”); ?> And sure enough, HELLO appears after each post.

    PHP isn’t my thing, but I would have thought that any code inserted above the post code would only run once. Obviously I’m missing something. Advice would be greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • content.php will get called for each post in the loop;

    consider to add the code into index.php (?) before the start of the loop.

    PS:

    make sure to create a child theme for the customisations.

    Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    The reason it is repeating is because you have in inside the WordPress loop.

    Thread Starter otis1991

    (@otis1991)

    Well duh. Sometimes the hardest things to see are the things in front of your own nose. Thank you gentlemen.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Twentytwelve: Slider code repeats under posts’ is closed to new replies.