Support » Themes and Templates » [Custom Theme] Need help to check my PHP code.

  • Resolved yekxmerr

    (@yekxmerr)


    Yesterday i’ve found myself stuck on my wordpress template because it’s working badly due the my PHP code (i think). The big issue i’m having it’s my adsense is not showing all the ads i put on, it only shows one at a time and i think this issue is related to my PHP code. Can you guys check if this is correct ?

    Main loop on index:

    <?php $pagedNum = get_query_var('paged'); $main_loop = new WP_Query( array( posts_per_page => 16, 'paged' => $pagedNum ) );?>
    <?php if( $main_loop->have_posts() ): while( $main_loop->have_posts() ): $main_loop->the_post();?>
    <li><a href="<?php the_permalink() ?>" target="_blank"><?php the_post_thumbnail(); ?></a>
    <h3><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" target="_blank"><?php the_title(); ?></a></h3>
    <?php the_excerpt(); ?></li>
    <?php endwhile; endif; wp_reset_query(); ?>

    Side bar popular posts:

    <?php if ( is_single() ) { ?>
    <ul><?php global $post; $args = array( 'order' => 'DESC','orderby' => 'meta_value','meta_key' => 'views','posts_per_page' => 8 );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :  setup_postdata($post); ?>
    <li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" target="_blank"><?php echo substr(get_the_title(), 0, 20); if(strlen(get_the_title()) > 20) echo '...'; ?></a></li>
    <?php endforeach; wp_reset_postdata(); ?></ul>
    <?php } else { ?>
    <ul><?php global $post; $args = array( 'order' => 'DESC','orderby' => 'meta_value','meta_key' => 'views','posts_per_page' => 5 );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :  setup_postdata($post); ?>
    <li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" target="_blank"><?php echo substr(get_the_title(), 0, 20); if(strlen(get_the_title()) > 20) echo '...'; ?></a></li>
    <?php endforeach; wp_reset_postdata(); ?></ul>
    <?php } ?>

    Thanks in advance

    [ Please do not bump, that’s not permitted here. ]

Viewing 1 replies (of 1 total)
  • Thread Starter yekxmerr

    (@yekxmerr)

    Ok i’ve discovered that it isn’t a template issue and i tweaked my code using the codex.
    Thanks anyway.

Viewing 1 replies (of 1 total)
  • The topic ‘[Custom Theme] Need help to check my PHP code.’ is closed to new replies.