* Author: Nick van de Veerdonk
* Author URI: https://jaaadesign.nl/
*/
// create custom plugin settings menu
add_action('admin_menu', 'amp_recent_posts_menu');
function amp_recent_posts_menu() {
//create new top-level menu
add_menu_page('AMP Recent Posts Settings', 'AMP Recent Posts', 'administrator', __FILE__, 'amp_recent_posts_options_page' , plugins_url('/images/icon.png', __FILE__), 102 );
//call register settings function
add_action( 'admin_init', 'register_amp_recent_posts_settings' );
}
function register_amp_recent_posts_settings() {
//register our settings
register_setting( 'amp_recent_posts_group', 'use_hook' );
register_setting( 'amp_recent_posts_group', 'set_prio_hook_amp' );
register_setting( 'amp_recent_posts_group', 'append_amp' );
register_setting( 'amp_recent_posts_group', 'heading_amp' );
register_setting( 'amp_recent_posts_group', 'max_amp' );
register_setting( 'amp_recent_posts_group', 'type_check_post_amp' );
register_setting( 'amp_recent_posts_group', 'cust_post_supp_amp' );
register_setting( 'amp_recent_posts_group', 'exclude_any_id_amp_1' );
register_setting( 'amp_recent_posts_group', 'exclude_any_id_amp_2' );
register_setting( 'amp_recent_posts_group', 'exclude_any_id_amp_3' );
register_setting( 'amp_recent_posts_group', 'exclude_any_id_amp_4' );
register_setting( 'amp_recent_posts_group', 'exclude_any_id_amp_5' );
register_setting( 'amp_recent_posts_group', 'sel_thumb_amp' );
register_setting( 'amp_recent_posts_group', 'sel_date_amp' );
}
function amp_recent_posts_options_page() {
?>
AMP Recent Posts
| AMP Recent Posts Settings |
★★★★★ If you like this plugin please consider rating it, thank you!
|
|
|
|
array( $type1, $type2 ),
'order' => 'DESC',
'orderby' => 'date',
'showposts' => $maxamp,
'post__not_in' => array (get_the_ID(), $numm1, $numm2, $numm3, $numm4, $numm5 ),
'post_status' => 'publish',
);
$attappendamp = get_option( 'append_amp' );
$attheadingamp = get_option( 'heading_amp' );
$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' ) == '1' && has_post_thumbnail() && get_option( 'sel_date_amp' ) == '1') {
echo ''.get_the_title().'
'. $ampdate .'
';
}
// Featured image + has thumb
else if ( get_option( 'sel_thumb_amp' ) == '1' && has_post_thumbnail() && !get_option( 'sel_date_amp' ) == '1') {
echo ''.get_the_title().'
';
}
// Featured image + NO thumb + date
else if ( get_option( 'sel_thumb_amp' ) == '1' && !has_post_thumbnail() && get_option( 'sel_date_amp' ) == '1') {
echo ''.get_the_title().'
'. $ampdate .'
';
}
// Featured image + NO thumb + NO date
else if ( get_option( 'sel_thumb_amp' ) == '1' && !has_post_thumbnail() && !get_option( 'sel_date_amp' ) == '1') {
echo ''.get_the_title().'
';
}
// NO featured image + date
else if ( !get_option( 'sel_thumb_amp' ) == '1' && get_option( 'sel_date_amp' ) == '1' ) {
echo ''.get_the_title().'
'. $ampdate .'
';
}
// NO featured image + NO date
else if ( !get_option( 'sel_thumb_amp' ) == '1' && !get_option( 'sel_date_amp' ) == '1' ) {
echo ''.get_the_title().'
';
}
}
} else {
echo 'No recent posts found
';
}
echo '
';
echo '
';
echo '
';
echo '
';
// Restore original Post Data
wp_reset_postdata();
}
}
// Shortcode
function amp_recent_function($atts, $append, $heading) {
extract(shortcode_atts(array(
'append' => 'amp',
'heading' => null,
'max' => 10,
'cpt1' => null,
'cpt2' => null,
'cpt3' => null,
), $atts));
$return_string = '';
$args = array (
'post_type' => array( 'post' ),
'post_status' => 'publish',
'order' => 'DESC',
'orderby' => 'date',
'showposts' => $max,
'post__not_in' => array (get_the_ID()),
'heading' => $heading,
'append' => $append,
);
echo ''.$heading.'
';
echo '';
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
// do something
echo '- '.get_the_title().'
';
}
} else {
// no posts found
}
echo '';
// Restore original Post Data
wp_reset_postdata();
}
function register_shortcode_amp_rec(){
add_shortcode('amp-recent-posts', 'amp_recent_function');
}
add_action( 'init', 'register_shortcode_amp_rec');
//* AMP Plugin extra styles
add_action( 'amp_post_template_css', 'jd_css_plugins_arp' );
function jd_css_plugins_arp( $amp_template ) {
if ( function_exists('is_amp_endpoint') )
// only CSS here please...
?>
div.jd-css-plugins-cont {
max-width: 600px;
width: 100%;
margin: auto;
}
div.jd-css-plugins-inner{
padding: 35px 16px 35px 16px;
}
div.jd-css-plugins-arp li {
margin-bottom: initial;
margin-left: 20px;
}
div.amplinkcont {
line-height: 1.6;
}
div.amplinkcont {
padding-right: 16px;
}
div.amplinkcont p {
font-size: 87%;
opacity: .7;
line-height: 1.4;
}
div.jd-css-plugins-arp li {
margin-bottom: initial;
margin-left: 0px;
list-style-type: none;
}
div.amplinkcont {
margin-left: 2px;
position: absolute;
display: inline-block;
}
div.ampimgcont {
height: 70px;
width: 70px;
padding: 2px;
border: 1px solid #ddd;
margin: 0px 10px 16px 0px;
display: inline-block;
}