Bring Your Business to Life › Support › Popular Widget › Inserting Custom Field Contents into Tab Post Content
Tagged: customization, Tab Post Content
- AuthorPosts
- November 12, 2013 at 9:11 pm #55282buegelfreiParticipant
First, thanks for the great plugin. It seems to be working great on WP 3.7.1 and does 99% of what I want it to do.
I’m working on a site for a client in which we have a custom text field (“department”) which produces a pre-headline which we show just above post titles on the blog. I’m trying to customize Popular Widget to show these pre-headlines in its tab post content.
The following code works for me within theme files (e.g., loop.php, single.php):
<?php $departments = get_post_meta( $post->ID, 'departments', true ); foreach( $departments as $department){ echo $department['department'];} ?>
I have been trying to translate the above into something that works when spliced into display_post_tab_content in Popular Widget’s functions.php file, but without success.
I would be grateful for any assistance.
Mighty thanks!
November 12, 2013 at 9:20 pm #55290Xpark MediaKeymasterif you want to add content or replace the title on a particular tab using the “pop_{$this->current_tab}_title” filter.
this is how you use it
function add_replace_title_on_post_tab( $title ){ $title . "add something after the title"; return $title; }add_filter( 'pop_recent_title', 'add_replace_title_on_post_tab' );
or you can replace the entire content using the “pop_recent_posts_content” filter.
November 13, 2013 at 8:30 pm #55301buegelfreiParticipantI must be doing something wrong: just working with your starter code, I would expect to see each title get “add something after the title” added to it. Instead, the titles are gone altogether under the “Recent” tab. (The titles are still there under Popular and Commented, the other two tabs that I’m using).
I’ve got this at line 382 in functions.php:
function add_replace_title_on_post_tab( $title ){ $title . "add something after the title"; return $title; }
And this at the last line of the file:
add_filter( 'pop_recent_title', 'add_replace_title_on_post_tab' );
Thanks!
November 15, 2013 at 12:25 pm #55311buegelfreiParticipantI think I just figured out how to do it. I’ll post my solution here, if it works…
November 19, 2013 at 12:51 am #55325Xpark MediaKeymasterHere are other filters
- pop_recent_title
- pop_commented_title
- pop_viewed_title
Try this code
function add_replace_title_on_post_tab( $title ){ return $title . "add something after the title"; } add_filter( 'pop_recent_title', 'add_replace_title_on_post_tab' );
November 19, 2013 at 8:53 pm #55339buegelfreiParticipantSolved!
It seems that the plugin I was using to create my custom field was the culprit. Once I realized that WP had custom field functionality already built in, I found that adding the following to display_post_tab_content was all I needed to display a WP-generated custom field in tab post content:
$output .= '<span class="myClass">'. get_post_meta($post->ID, 'myCustomField', true) . '</span> ';
(My solution did not work for the custom field created via the plugin which shall remain nameless. Disabled and deleted!)
Thanks again for Popular Widget!
- AuthorPosts
- You must be logged in to reply to this topic.