• Phillip

    (@phillustration)


    Hi,

    Sorry about the long title, but i am unsure how else to describe this.

    The problem that I am having is that I have a page that has a small paragraph with a <!–more–> tag after the first sentence.

    I am trying to get only the first sentence to display before the more tag on the home page. with possibly a click through so that the user can view the page that the sentence is from.

    I have got to the point with the code that it will display the title and the post on the home page but this read more problem has stumped me for about a month.

    <h2 class="entry-title">
    
    	<a href="https://www.phillipvale.com/?page_id=2">
    
    		<?php
    		$page_id = 2;
    		$page_data = get_page( $page_id );
    		$title = $page_data->post_title;
    		echo $page_data->post_title;
    		?>
    
    	</a>
    
    	</h2>
    
    		<?php
    		$page_id = 2;
    		$page_data = get_page( $page_id );
    		$the_content = $page_data->post_content;
    		echo $page_data->post_content;
    		?>

    Any help is much appreciated!

    Thank you!

Viewing 6 replies - 1 through 6 (of 6 total)
  • vtxyzzy

    (@vtxyzzy)

    You need to apply the content filters:

    $the_content = apply_filters('the_content',$page_data->post_content);

    Thread Starter Phillip

    (@phillustration)

    Thanks for you help vtxyzzy.

    However, it still doesn’t seem to be working.

    I have pasted the code as it looks now below, i’m not sure if i’m doing something wrong?

    <h2 class="entry-title">
    
    	<a href="https://www.phillipvale.com/?page_id=2">
    
    		<?php
    		$page_id = 2;
    		$page_data = get_page( $page_id );
    		$title = $page_data->post_title;
    		echo $page_data->post_title;
    		?>
    
    	</a>
    
    	</h2>
    
        	<?php global $more; $more = 0; ?>
    		<?php
    		$page_id = 2;
    		$page_data = get_page( $page_id );
    		$the_content = apply_filters('the_content',$page_data->post_content);
    		echo $page_data->post_content;
    		?>

    Is there anywhere else on the site that i need to clarify $the_content ?

    Thanks for you help again.

    Reuben

    (@greuben)

    change this
    echo $page_data->post_content;
    to
    echo $the_content;

    Thread Starter Phillip

    (@phillustration)

    Hi Reuben,

    Thanks for that. Unfortunately all that this has done is format the text properly.

    Before it was all a continuous line of text, now it is using paragraphs.

    I am really stuck on this one!

    This is what my code looks like now:

    <h2 class="entry-title">
    
    	<a href="https://www.phillipvale.com/?page_id=4">
    
    		<?php
    		$page_id = 4;
    		$page_data = get_page( $page_id );
    		$title = $page_data->post_title;
    		echo $page_data->post_title;
    		?>
    
    	</a>
    
    	</h2>
    
    		<?php
    		$page_id = 4;
    		$page_data = get_page( $page_id );
    		$the_content = apply_filters('the_content',$page_data->post_content);
    		echo $the_content;
    		?>

    Thanks again.

    Thread Starter Phillip

    (@phillustration)

    Reuben,

    My apologies. This has worked perfectly.

    I placed the correction in the wrong section.

    Is there a way to produce a read more link under the content without having to code in a link using ?

    Thanks.

    Read more not working on inner pages
    pls help
    i put this code it’ look in innerpage but when we click on it it’s not going to read more content

    <?php $more = 0;
    get_template_part( ‘content’, ‘page’ );
    ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Read more not working on pages displayed on home page’ is closed to new replies.