AMP Related Posts



AMP Related Posts Settings

NB. If you are NOT using the Automattic AMP plugin please implement the related posts by adding this code to your plugins templates:

<?php echo do_shortcode( "[amp-recent-posts append='amp' heading='Recent Posts' max='5']" ); ?>

Use AMP plugin (Automattic) hook? />

This will implement the related posts without the use of shortcode.

Priority of hook

We suggest you set this to 3, to play nice with our other plugins, if you wish to move the related posts up of down change this number.

Set endpoint*

Unless you have changed this the AMP plugin uses 'amp', enter just letters no apostrophes. The endpoint is the last part of the URL to indicate AMP content.

Heading

Add an <H3> heading here.

Set number of posts*

The maximum of related posts rendered, for example 5.

Return posts? " />

Check this to show related posts, as opposed to entries of a different post type, for example portfolio items. Only prerequisite is a shared category.

Other post types

If you wish to return a different post type set it here. (ex.: post, page, product, portfolio), only prerequisite is a shared category

Display featured image? " />

Check this to show featured images.

Show date? " />

Check this to show the dates.

Exclude posts by ID

Some posts are more equal than others, you can find their ID in the admin URL of the post, page etc.




★★★★★ If you like this plugin please consider rating it, thank you!


 
AMP Related Posts

Our other plugins

Articles

Keep in touch

ID); $category = $category[0]->cat_ID; // WP_Query arguments $args = array ( 'post_type' => array( $type1, $type2 ), 'order' => 'DESC', 'orderby' => 'rand', 'showposts' => $maxamp, 'post__not_in' => array (get_the_ID(), $numm1, $numm2, $numm3, $numm4, $numm5 ), 'post_status' => 'publish', 'category__in' => array($category), ); $attappendamp = get_option( 'append_amp_rel' ); $attheadingamp = get_option( 'heading_amp_rel' ); $ampthumb = get_the_post_thumbnail( 'thumbnail' ); echo '
'; echo '
'; echo '
'; echo '

'.$attheadingamp.'

'; echo '
    '; // The Query $query = new WP_Query( $args ); // The Loop if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); // do something $ampthumb = get_the_post_thumbnail_url(); $ampthumbalt = get_the_title(); $ampdefimg = plugin_dir_url( __FILE__ ) . 'images/default-thumb.jpg'; $ampdate = get_the_date(); // Featured image + has thumb + date if ( get_option( 'sel_thumb_amp_rel' ) == '1' && has_post_thumbnail() && get_option( 'sel_date_amp_rel' ) == '1') { echo '
  • '.get_the_title().'

    '. $ampdate .'

  • '; } // Featured image + has thumb else if ( get_option( 'sel_thumb_amp_rel' ) == '1' && has_post_thumbnail() && !get_option( 'sel_date_amp_rel' ) == '1') { echo '
  • '; } // Featured image + NO thumb + date else if ( get_option( 'sel_thumb_amp_rel' ) == '1' && !has_post_thumbnail() && get_option( 'sel_date_amp_rel' ) == '1') { echo '
  • '.get_the_title().'

    '. $ampdate .'

  • '; } // Featured image + NO thumb + NO date else if ( get_option( 'sel_thumb_amp_rel' ) == '1' && !has_post_thumbnail() && !get_option( 'sel_date_amp_rel' ) == '1') { echo '
  • '; } // NO featured image + date else if ( !get_option( 'sel_thumb_amp_rel' ) == '1' && get_option( 'sel_date_amp_rel' ) == '1' ) { echo '
  • '.get_the_title().'

    '. $ampdate .'

  • '; } // NO featured image + NO date else if ( !get_option( 'sel_thumb_amp_rel' ) == '1' && !get_option( 'sel_date_amp_rel' ) == '1' ) { echo '
  • '; } } } else { echo '

    No related posts found

    '; } echo '
'; echo '
'; echo '
'; echo '
'; // Restore original Post Data wp_reset_postdata(); } } // Shortcode function amp_related_posts_function($atts, $append, $heading, $max) { extract(shortcode_atts(array( 'append' => 'amp', 'heading' => null, 'max' => 10, 'cpt1' => null, 'cpt2' => null, 'cpt3' => null, ), $atts)); $return_string = '