• good evening,

    i’m trying to make my coding as modular as possible. my site uses three different LOOPs, each to accomplish a different task with my posts/pages, and i’ve got each loop on its own file, injected into the site via php_include, such as :
    <?php include(locate_template('loop_blog_entry.php')); ?>

    this works great, and lets me modify loop behavoir or appearance in one place, and have the changes affect all instances of that LOOP.

    now i’m getting greedy and want to reuse my loop_blog_entry LOOP on single.php

    the problem is that my standard loop_blog_entry LOOP uses variables to achieve the pagination i need everywhere else on the site… and obviously that same pagination breaks single.php‘s navigation ??

    i’ve tried all sorts of IF/THEN statements to try and modify the variables used by the loop, and none of them work successfully. i might be using the is_singular() function incorrectly?

    here’s some examples :

    variables set on pages that use the loop_blog_entry LOOP :

    $paged3 = isset( $_GET['paged3'] ) ? (int) $_GET['paged3'] : 1;
    $args3 = array(                        // blog section
    	'paged'          => $paged3,
    	'post_type'      => 'post',
    	'posts_per_page' => 3,
    	);

    and the reference LOOP itself :

    $query3 = new WP_Query( $args3 );
    while ( $query3->have_posts() ) : $query3->the_post();

    i tried the following variations of IF just before the LOOP :

    if ( is_singular('post')) { $args3 = ""; }
    if ( is_singular('post')) { $args3 = NULL; }

    trying to negate the variables that initiate pagination if single.php is loading the loop. but it just breaks my single.php :/

    tried a proper IF/THEN statement to use an entirely different LOOP if is_singular was true

    if ( is_singular('post') )
    	{
    	$query3 = new WP_Query();
    	while ( $query3->have_posts() ) : $query3->the_post();
    	}
    else
    	{
    	$query3 = new WP_Query( $args3 );
    	while ( $query3->have_posts() ) : $query3->the_post();
    	}

    that broke everything ??

    any advice is greatly appreciated

  • The topic ‘modifying variables passed to the loop, with IF/THEN ??’ is closed to new replies.