0

below is a query where it supposed to get a contents from a page by a specified page title

<?php
    $page = get_page_by_title( 'About Us' );
    $content = apply_filters('the_content', $page->post_content); 

    the_content_rss('', TRUE, '', 100);
?>

    <a href="<?php the_permalink() ?>" title="Read the whole post" class="rm">Read More</a>

and yes its successfully display a content and trim the content by 100, but the problem is the content and permalink is not the content and the permalink of the specified page that I pulled from the query, i mean, the content and permalink is different from the page Im pulling up. Any ideas whats going on? Im trying to play around with the code but seems nothing works at all and also im currently looking on the web for the possible solution but unfortunately, I find nothing.

PS: I just want to display the content and get the permalink of the specified page that im pulling up through the query above.

2 Answers 2

0

To display content and permalink of About Us page you should use get_permalink() function by passing page id to it and instead of the_content_rss() function, you should directly echo $page->post_content by trimming content using wp_trim_words() function.

The changed code is as following.

<?php
    $page = get_page_by_title( 'About Us' );
    $content = apply_filters('the_content', $page->post_content); 

     echo wp_trim_words( $content, 100, '');
?>

<a href="<?php  echo get_permalink( $page->ID ); ?>" title="Read the whole post" class="rm">Read More</a>
0
0

For the permalink, do:

echo get_permalink($page->ID);

instead of the_permalink().

The reason is because the_permalink() assumes you want the current post/page ID. Not the special one. It's not a mind reader! :)

6
  • and I got this error Fatal error: Call to undefined function get_the_permalink()
    – Jacky lou
    Aug 19, 2013 at 17:14
  • Whoops. Updated. Stupid inconsistent WP naming conventions... it's get_permalink()
    – GhostToast
    Aug 19, 2013 at 17:17
  • same error in this one echo get_the_permalink($page->ID);
    – Jacky lou
    Aug 19, 2013 at 17:19
  • anything about displaying the content? I know it could be done using echo $content; but what I want to do for the content is to trim it to 100 thats why im using the_content_rss('', TRUE, '', 100); to trim the content if possible but nothing works.
    – Jacky lou
    Aug 19, 2013 at 17:23
  • @Jackylou I have answered you about it. Aug 19, 2013 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.