• Resolved Imagefasihsajid

    (@fasihsajid)


    hello I am turning a PHP into a function to be executed on a page template, the code when itself is run through directly from the template file works but when I create a function in code snippets and call it on the page template it breaks
    this is the code

    function getPrevNext(){
    $pagelist = get_pages("child_of=".$post->post_parent."&parent=".$post->post_parent."&sort_column=menu_order&sort_order=asc");
    	$pages = array();
    	foreach ($pagelist as $page) {
    	   $pages[] += $page->ID;
    	}
    
    $current = array_search($post->ID, $pages);
    	$prevID = $pages[$current-1];
    	$nextID = $pages[$current+1];
    	
    	echo '<div class="navigation">';
    	
    	if (!empty($prevID)) {
    		echo '<div class="alignleft">';
    		echo '<a href="';
    		echo get_permalink($prevID);
    		echo '"';
    		echo 'title="';
    		echo get_the_title($prevID); 
    		echo'">Previous</a>';
    		echo "</div>";
    	}
    	if (!empty($nextID)) {
    		echo '<div class="alignright">';
    		echo '<a href="';
    		echo get_permalink($nextID);
    		echo '"';
    		echo 'title="';
    		echo get_the_title($nextID); 
    		echo'">Next</a>';
    		echo "</div>";		
    	}
    }
Viewing 1 replies (of 1 total)
  • Plugin Author ImageShea Bunge

    (@bungeshea)

    I’d recommend making this into a shortcode:

    add_shortcode( 'prev_next', function () {
    	ob_start();
    
    	getPrevNext();
    
    	return ob_get_clean();
    } );

    Then use [prev_next] in your post or page content, or call do_shortcode( '[prev_next]' ); in your template files.

Viewing 1 replies (of 1 total)

The topic ‘function not executing’ is closed to new replies.