Recent posts with featured image or fallback image with permalink

Here’s the relevant part of your code that should work: // This will make a URL like http://yoursite.com/path/to/fallback.png $fallback_image = site_url( ‘/path/to/fallback.png’ ); $fallback_image = “<img src=”https://wordpress.stackexchange.com/questions/224740/{$fallback_image}” />”; foreach( $recent_posts as $recent ){ echo ‘<div class=”sidebar-entries”>’; $featured_image = get_the_post_thumbnail( $recent[‘ID’], ‘sidebar-thumb’, array( ‘class’ => ‘sidebar-image’ ) ); if ( ! strlen( $featured_image ) ) { … Read more

Output array into one table cell

Alternatively, make an array of the titles and then use implode… $prerequisites = get_post_meta($post->ID, ‘opl_prerequisites’, TRUE); $titles = array(); foreach( $prerequisites as $prerequisite ){ $titles[] = get_the_title( $prerequisite ); } $output .= ‘<td>’.implode(“,”, $titles).'</td>’;

WordPress Search Results for Multiple Post Types

The wp_get_attachment_image_src() function expects you to also pass some kind of attachment ID plus it doesn’t grab the image HTML that we need so instead we should use wp_get_attachment_image(). IF a post has a post thumbnail, grab it.ELSE IF the post has any attached images, grab the first one.ELSE maybe show a placeholder? I’ve defined … Read more

Load a page into a div with Ajax

My philosophy is that if you use a system like WP then you embrace it and do things the WP way. WP has plenty of hooks that let you override functionality and the flexible theme structure gives you almost total control over the output. So, I’d advise using a WP theme and WP built in … Read more

How to show phpinfo() only in a new tab?

If you are displaying the info in the front-end, hook into wp or init, otherwise init or admin_init will work on admin: add_action(‘wp’, function() { if( current_user_can(“manage_options”) && ! is_feed() && isset( $_GET[“my_plugin_show_phpinfo”] ) ) { ?> <!– Output things –> <?php phpinfo(); ?> <?php exit; } }); Now if you go to http://example.com/?my_plugin_show_phpinfo=1 it … Read more