Hello,
I’m not an expert, so it seems I can’t see to figure this out.
I got the wpp hook working, but when try to add the alternative title function it doesn’t work.
This is technically what I need:
If post has alternative title,
then show the alternative title,
if not, then show the original title.
This is the function I’m been trying to create
function get_my_custom_title($post_id){
// Get post data
$the_post = get_post( $post_id );
// Get post_content
$the_title_custom = $the_post->the_title;
if ($the_title_custom = get_post_meta($post->id, 'field_alt_title', true)) {
echo $the_title_custom;
} else {
get_the_title();
}
$the_title_custom = $the_title_custom;
return $the_title_custom;
}
Inside the function my_custom_popular_posts_html_list, this is what I’ve got:
function my_custom_popular_posts_html_list( $mostpopular, $instance ){
$output = '<ol class="wpp-list new">';
// loop the array of popular posts objects
foreach( $mostpopular as $popular ) {
$excerpt = ''; // Excerpt placeholder
// Excerpt option checked, build excerpt tag
if ( $instance['post-excerpt']['active'] ) {
$excerpt = get_excerpt_by_id( $popular->id );
if ( !empty( $excerpt ) ) {
$excerpt = '<div class="wpp-excerpt">' . $excerpt . '</div>';
}
}
$the_title_custom = get_my_custom_title($popular->id);
if ( !empty( $the_title_custom ) ) {
$the_title_custom = $the_title_custom;
}
$output .= "<li>";
$output .= "<a href=\"" . get_the_permalink( $popular->id ) . "\" title=\"" . esc_attr( $popular->title ) . "\"><h2 class=\"entry-title\">" . esc_attr( $the_title_custom ) . "</h2>";
$output .="<div>" . get_the_post_thumbnail( $popular->id ) . "</div>";
$output .= $excerpt;
$output .= "</a></li>" . "\n";
}
$output .= '</ol>';
return $output;
}
add_filter( 'wpp_custom_html', 'my_custom_popular_posts_html_list', 10, 2 );
Any help will be much appreciated!
Thanks,