WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Custom Theme] Need help to check my PHP code. (2 posts)

  1. yekxmerr
    Member
    Posted 2 years ago #

    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. ]

  2. yekxmerr
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags