Support » Fixing WordPress » content before the more tag and functions.php

  • Cedric

    (@cooperanet)


    Hi,

    I try to retrieve the content before the <!–more–> tag of a page.

    I use a custom query and I created a specific function in my functions.php file.

    Here is my custom query in my index.php page

    <?php
    		$arg = array('post_type'=>'page','post_parent'=>5, 'showposts'=>1, 'orderby'=>'rand', 'post__not_in'=>array(36));
    		$randomService = new WP_Query($arg);
    			while($randomService->have_posts()) : $randomService->the_post();
    		?>
    <!-- this is the function supposed to display the stuff -->
    <?php the_page_excerpt(150); ?>
    
    <?php endwhile; ?>

    and this is the function in my functions.php file

    function the_page_excerpt($length) {
    	global $more;
    	if ($pos=strpos($post->post_content, '<!--more-->')) { $more = 0; the_content(''); }
    	else { $page_excerpt = $post->post_content; echo substr(strip_tags($page_excerpt),0,$length).'&nbsp;...'; }
    }

    But nothing displays… and if I add these lines in my index.php:

    global $more;
    	if ($pos=strpos($post->post_content, '<!--more-->')) { $more = 0; the_content(''); }
    	else { $page_excerpt = $post->post_content; echo substr(strip_tags($page_excerpt),0,200).'&nbsp;...'; }

    It works…

    So, what is wrong with the function in my functions.php file?

    Thanks a lot for your help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Samuel B

    (@samboll)

    did you put the functions.php code at the very top?

    Cedric

    (@cooperanet)

    Thanks for your response.

    I tried to put my code at the very top of the functions.php file but it changes nothing.

    Any idea is welcome!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘content before the more tag and functions.php’ is closed to new replies.