• I’m having problems with the_content() function after modifying my theme to add previous and next links on pages. I am sure that it is called within the loop as the_ID() works fine and so is the_title().
    $post->post_content also works fine.
    The output of the_content() function is a number and usually it is the id of the previous page.
    Anybody have any ideea what could be the source of this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Have you tried:

    – deactivating all plugins to see if this resolves the problem? If this works, re-activate the plugins one by one until you find the problematic plugin(s).

    – switching to the default theme to rule out any theme-related problems?

    Thread Starter overdeath

    (@overdeath)

    There is no plugin activated.
    The problem is surely theme related, and it is related to the modifications i made but i find the fact that the_title() works and the_content() doesn’t very odd. There is no php code between them.

    You can see the code from page.php here https://pastebin.com/d3Qa8Z7w

    Can you describe the goal of that Page Template?

    Thread Starter overdeath

    (@overdeath)

    I’m trying to get the page’s next and previous “brother”.
    Here i am trying to make an array with all the page’s brothers (their IDs)

    $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;
    }


    Then i search for the current page id in that array and i remember the position. That means that the previous array element is the id of the previous page, and the next element is the id of the next page.

    $current = array_search($post->ID, $pages);
    $prevID = $pages[$current-1];
    $nextID = $pages[$current+1];


    Based on those IDs i show the post title and permalink using get_the_title() and get_permalink(). This works fine. But when i try to display that page info using this:

    <div class="post" id="post-<?php the_ID(); ?>">
    		<h2><?php the_title(); ?></h2>
    			<div class="entry">
    				<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
            <?php echo $post->post_content; ?>
    
    				<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    			</div>
    		</div>


    Everything shows ok except the_content() which returns a number.

    Thread Starter overdeath

    (@overdeath)

    I’ve found the problem.
    Changing the array from $pages to something else and the variable in the foreach statement from $page to something else fixed the problem.
    Are they reserved names? I wouldn’t have expected that since i started from an example that was on the wordpress codex. (link).
    Hope somebody will shed some light

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘the_content outputs a number’ is closed to new replies.