Forums

How to display a specific post with formating and the "more" tag ? (13 posts)

  1. blendesign
    Member
    Posted 1 year ago #

    Hi,

    i'm a beginner at PHP, and i try to display a specific post on the footer.
    i use this PHP code :

    <?php
    $post_id = 67;
    $specific_post = get_post($post_id);
    echo $specific_post -> post_content;

    it work good, but i want the "more" tag... i was unable to find a solution... but i think it's very easy... i try this one, but don't work :

    <?php
    $post_id = 67;
    $specific_post = get_post($post_id);
    echo $specific_post -> the_content('more');
  2. keesiemeijer
    moderator
    Posted 1 year ago #

    try it with this:

    <?php
    $post_id = 67;
    $specific_post = get_posts('include='.$post_id);
    setup_postdata($specific_post[0]);
    the_content('Read the rest of this entry &raquo;');
    ?>
  3. blendesign
    Member
    Posted 1 year ago #

    i try, but seems not work....
    ( nothing displayed on the page)

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    It works on my testserver. Are you sure you have the right ID (67)?

  5. blendesign
    Member
    Posted 1 year ago #

    be careful, because i'm talking about the content of a PAGE, not a post...
    it seems different ( i don't know why..)

  6. keesiemeijer
    moderator
    Posted 1 year ago #

    try it with (works for me with a Page):

    <?php
    $post_id = 67;
    $specific_post = get_pages('include='.$post_id);
    setup_postdata($specific_post[0]);
    the_content('Read the rest of this entry &raquo;');
    ?>
  7. blendesign
    Member
    Posted 1 year ago #

    it work now ! thanks a lot keesiemeijer ^_^

    could u explain little bit ? i would like to understand your code !

  8. blendesign
    Member
    Posted 1 year ago #

    ah, and just a question : if i click on "read the rest of this entry", the rest of the post appears..but if i want to go on this page to read more ?

  9. keesiemeijer
    moderator
    Posted 1 year ago #

    I'm not sure what you mean. Did you split a single post up into different web pages by typing <!--nextpage--> in your post?

  10. blendesign
    Member
    Posted 1 year ago #

    in fact, this is the background of my problem :

    i make a website with wordpress.
    on the footer, i have a little "ABOUT" section (i create an "ABOUT" page), but i want just the beginning (around 3 lines) + a "read more" link.

    when people click on the "read more" link, i want to go to the main "ABOUT" page...

    hope u understand !!
    thanks in advance,

  11. keesiemeijer
    moderator
    Posted 1 year ago #

    Ok, I changed the code a little bit:

    <?php
      $post_id = 67;
      $specific_post = get_pages('include='.$post_id);
      $content_more =false;
      $html = '';
      $excerpt_length = 40;
      $content = $specific_post[0]->post_content;
      $content = strip_shortcodes($content);
      $content = str_replace(']]>', ']]>', $content);
      $content = strip_tags($content);
      $excerpt = explode(' ', $content);
      if (count($excerpt) > $excerpt_length) {
    	 $excerpt = implode(' ', array_slice($excerpt, 0, $excerpt_length)) . '...';
    	 $content_more = true;
    	} else { $excerpt = $content; }
      if($content_more){
      	$html .= $excerpt;
        $html .= ' <a href="' . get_permalink($post_id) . '" title="Read more about: '.$specific_post[0]->post_title .'">Read more</a>';
    	} else {
    		$html .= $excerpt;
    	}
    	$excerpt = apply_filters('the_content', $html);
    	echo $excerpt;
    ?>

    Change $excerpt_length = 40; to make the excerpt longer or shorter

  12. blendesign
    Member
    Posted 1 year ago #

    thanks a lot, it work great ! ^^

    but, omg : lot of code for something seems not so difficult to do !

  13. blendesign
    Member
    Posted 1 year ago #

    can u give some good book to buy, to learn coding WP like this ? ^^

Topic Closed

This topic has been closed to new replies.

About this Topic