• Resolved papaworx

    (@papaworx)


    I have a two level menu: chapter>pages. I set up the page template to give a nice page navigation within the chapter level. But my editor would like to also have previous and next chapter in the selection. So I generated a WP_Post with the chapter pages. But now I need to find the index of the current chapter page_ID, so I can determine the page_IDs for the next and previous chapter. I am stuck trying to search the ID ‘column’ of that WP_Post

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hey there,

    Can you perhaps share some code to demonstrate how you are currently displaying the posts?

    How are the various chapters connected to each other in the back end / the database? As long as that connection can be determined somehow, showing previous / next links should be possible.

    @papaworx,

    Without a lot of additional information related to the specifics on the issue, support forum volunteers, in my experience (see link here also), can and will find it quite difficult to support this topic unless you Include as much Information as Possible.

    That said, to output the $post use echo is a page template.

    Thread Starter papaworx

    (@papaworx)

    All the pages are stored as regular pages in the database with the first page of each chapter as parents and the rest as children, one level down. I can extract the top pages by making parent->0.
    The code looks as follows:

    			// Styled Page Selector
    			$par = $post->post_parent;
    			$this_ID = get_the_ID();
    			if($par==0)
    				$par = $this_ID;
    			$page_number = $commentpress_core->nav->get_page_number( $par );
    			$cPages = get_pages(  array( 'parent' => 0, 'sort_column' => 'menu_order', 'sort_order' => 'asc' ) );
    			$rank = array_search ($par, array_column($cPages, 'ID'));
    			
    			//echo "Rank is: ".$cPages[1][0]."<br/>";
    			echo get_the_title($par)."<br/>";
    			echo "<a href='". get_page_link( $par ) ."'>";
    			if ($par == $this_ID)
    				echo "<span class='page_nav' style='font-weight:bold;'> Page ".$page_number." </span></a>";
    			else
    				echo "<span class='page_nav'>".$page_number." </span></a>";
    			$zpages = get_pages(  array( 'child_of' => $par, 'sort_column' => 'post_order', 'sort_order' => 'asc' ) );
    			foreach ( $zpages as $page ) {
    				$page_ID = $page->ID;
    				$page_number = $commentpress_core->nav->get_page_number( $page_ID );
    				echo "<a href='". get_page_link( $page_ID ) ."'>";
    				if ($page_ID == $this_ID)
    					echo "<span class='page_nav' style='font-weight:bold;'>| Page ".$page_number." </span></a>";
    				else 
    					echo "<span class='page_nav'>| ".$page_number." </span></a>";
    			}
    

    If there were a way of uploading a small screenshot, I could show you what it looks like.

    • This reply was modified 8 years, 3 months ago by papaworx.

    Thanks for the info>

    It may help to review all of the functions using echo.

    Thread Starter papaworx

    (@papaworx)

    SOLVED!
    I simply stepped through the WP_Post and tested for ID component, until I had the right one. There won’t be to many items.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘howto find index of item in WP_Post’ is closed to new replies.