Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm not quite sure how it works, if you're on a post (single.php), does it count page.php as the page it's on?

What i need to do, is get a custom field assigned to a page, from a blog post. I need it because i want the user to be able to change the "Read more" text in the post excerpt.

I could get the custom field by just using a static page id, but if the user decides to change things up the id might change, i need it to be dynamic.

What would be the best way to go about this?

share|improve this question
    
Please take a look at this, this and this answer. –  kaiser Oct 16 '12 at 13:58

2 Answers 2

up vote 1 down vote accepted

I would suggest a different approach. The option for manually adding post excerpt should go in a theme option as opposed to a custom field. Also you should use this hook for modifying the excerpt's more text

http://codex.wordpress.org/Plugin_API/Filter_Reference/excerpt_more

If the user is supposed to enter custom excerpt on a per-post basis, they can do it from the admin panel anyway.

share|improve this answer
    
The excerpt isn't manually added, it's just a cropped version of the entire text (default). The custom_excerpt_more() function only works from the functions.php right? I need to have the user be able to set their own Read more text on the blog page (not the post page), and then display it after each excerpt. –  qwerty Oct 16 '12 at 12:16
    
I meant that you should give the user a theme option where they may enter the text they want. Then in the custom_excerpt_more() function in functions.php, you'll read the text that user entered, sanitize it, & add it. –  Mridul Aggarwal Oct 16 '12 at 12:25
    
Please note that excerpt_more hook is not called if the excerpt is not actually trimmed from the content. If you want to guarantee that Read More text is always displayed use the_excerpt hook instead or you can just display it directly inside template files (single.php, page.php etc.) –  Mridul Aggarwal Oct 16 '12 at 12:28
    
That would work, but i'm afraid it's too complex for the end user. It has to bee as simple as possible. The user shouldn't have to ever go to the themes settings to change something. (Not my rules) Is it possible to get the custom field of the blog page from the single (blog post) page? –  qwerty Oct 16 '12 at 12:30
1  
get_option('page_for_posts') would return the blog page's id. Then you can do something like get_post_meta( get_option('page_for_posts'), 'customfield', true ); –  Mridul Aggarwal Oct 16 '12 at 12:39

This will work.Add this lines in functions.php file

 function custom_excerpt_more( $more ) {
       global $post;
       $key_1_values = get_post_meta($post_id, $key, $single);
       $more=$key_1_values;
        return $more;
    }
    add_filter( 'excerpt_more', 'custom_excerpt_more' );
share|improve this answer
    
No, this won't work. $post_id and $single are set nowhere. –  kaiser Oct 16 '12 at 13:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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