can't add blog posts to custom widget
-
Hi,
Ive used this code to add a widget on my static home page and I want it to display a preview of my recent posts.
My problem is that when I have the widget display my blog page, it doesn’t show the post content as the page has no content on it, it is only displaying posts (hope this makes sense). Is it possible to have the post content displayed on the widget from the blog page?
https://www.energyforlife.net.au/blog/
/* add widget area before the blog, after the featured pages, only in home */ add_filter( 'tc_default_widgets' , 'add_featured_page_widget' ); function add_featured_page_widget( $defaults ) { $defaults['fp_widgets'] = array( 'name' => __( 'Featured Pages Widget' , 'customizr' ), 'description' => __( 'After the featured pages area on home' , 'customizr' ) ); return $defaults; } add_action('__before_main_container' , 'display_my_fp_widget', 15 ); function display_my_fp_widget() { if ( ! tc__f('__is_home') ) return; dynamic_sidebar('fp_widgets'); } add_filter('widget_text', 'do_shortcode'); /* shortcode to display a page/post content + title */ add_shortcode('tc_post', 'do_tc_post'); function do_tc_post( $atts ){ $default = array( 'id' => '', ); $atts = shortcode_atts($default, $atts); if ( ! isset($atts['id']) ) return; $_post = get_post($atts['id']); if ( ! isset($_post) ) return; ob_start(); printf(' <article id="%1$s" class="post-%1$ page type-page status-publish hentry row-fluid"> <header class="entry-header"> <h2 class="entry-title">%2$s</h2> </header> <section class="entry-content"> %3$s </section> </article>', $_post -> ID, $_post -> post_title, apply_filters('the_content', $_post -> post_content) ); $html = ob_get_contents(); if ( $html ) ob_end_clean(); return $html; }
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘can't add blog posts to custom widget’ is closed to new replies.