Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter ctinetworks

    (@ctinetworks)

    I was able to fix the problem by adding “the_post()” method within the main loop in the inserPages_handleShortcode_insert” method after while(have_posts()). The loop was not iterating thus causing it to be an infinite loop.

    Thread Starter ctinetworks

    (@ctinetworks)

    Actually my previous solution broke when using non custom page templates. Below is a better solution I came up with. I basically just set a boolean called $continue to true, add it as a condition for the while loop and then set it to false when using custom page templates. Thus ending the loop. Not sure how this solution will affect custom posts though.

    $continue = true;
    // Start our new Loop
    while (have_posts() && $continue) {
    
    	ob_start(); // Start output buffering so we can save the output to string
    
    	// Show either the title, link, content, everything, or everything via a custom template
    	switch ($display) {
    		case "title":
    			the_post();
    			echo "<h1>"; the_title(); echo "</h1>";
    			break;
    		case "link":
    			the_post();
    			echo "<a href='"; the_permalink(); echo "'>"; echo the_title(); echo "</a>";
    			break;
    		case "content":
    			the_post();
    			echo the_content();
    			break;
    		case "all":
    			the_post();
    			echo "<h1>"; the_title(); echo "</h1>";
    			echo the_content();
    			echo the_meta();
    			break;
    		default: // display is either invalid, or contains a template file to use
    			$template = locate_template($display);
    			if (strlen($template) > 0) {
    				include($template); // execute the template code
    			}
    			$continue = false; // Stop the loop
    			break;
    	}
    
    	$content = ob_get_contents(); // Save off output buffer
    	ob_end_clean(); // End output buffering
    }

    I have the same issue and the last fix provided seems to correct the situation. Is there something wrong with my custom template?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Issue with custom page templates.’ is closed to new replies.