if ( ! defined( 'ABSPATH' ) ) { exit( 'Direct script access denied.' ); } get_header(); ?>
get_results( "SELECT YEAR(post_date) AS year FROM wp_posts WHERE post_type = 'news' AND post_status = 'publish' GROUP BY year DESC LIMIT 1" ); $count = $wpdb->get_var('SELECT FOUND_ROWS()'); foreach ( $years as $year ) { // get posts for each year $posts_this_year = $wpdb->get_results( "SELECT post_title, ID as ID FROM wp_posts WHERE post_type = 'news' AND post_status = 'publish' AND YEAR (post_date) = '" . $year->year . "'" ); echo '

' . $year->year . '

'; foreach ( $posts_this_year as $post ) { echo '
'; echo '
'; echo '
    '; echo '
  • '; echo '
    '; echo ''; echo '
    '; echo '
  • '; echo '
'; echo '
'; echo'
'; $terms = get_the_terms( $post->ID, 'newstype' ); if ($terms) { foreach($terms as $term) { echo '

' . $term->name . '

'; } } echo '

' . wp_trim_words( get_the_title( $post->ID ), 9, '...' ) . '

'; echo '
'; // start publisher code $termsx = get_the_terms( $post->ID, 'publisher' ); if ($termsx) { foreach($termsx as $term) { echo '' . $term->name . ''; } } // end publisher code // start published date $whatDate = get_field('published_on_date'); if ( $whatDate ) { // check if published date was entered into custom field echo '' . get_field('published_on_date'). ''; } else { // if not - then use wordpress post publised date echo '' . get_the_date("F n, Y" , $post->ID ) . ''; } // end published date // added admin edit link for easier accessibility while editing news post type edit_post_link('Edit Item', '
', '
'); echo '
'; echo '
'; } } } else { // no posts found }; // next set of posts global $wpdb; if($page == 1){ $per_page = 1; }else{ $per_page = 2; } $page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1; if ($page > 1) { $offset = $page * $per_page - $per_page; } else { $offset = $page; } $years = $wpdb->get_results( "SELECT YEAR(post_date) AS year FROM wp_posts WHERE post_type = 'news' AND post_status = 'publish' GROUP BY year DESC limit $per_page offset $offset" ); $total = $wpdb->get_var('SELECT FOUND_ROWS()'); foreach ( $years as $year ) { // get posts for each year $posts_this_year = $wpdb->get_results( "SELECT post_title, ID as ID FROM wp_posts WHERE post_type = 'news' AND post_status = 'publish' AND YEAR (post_date) = '" . $year->year . "'" ); echo '

' . $year->year . '

'; foreach ( $posts_this_year as $post ) { echo '
'; echo '
'; echo '
    '; echo '
  • '; echo '
    '; echo ''; echo '
    '; echo '
  • '; echo '
'; echo '
'; echo'
'; $terms = get_the_terms( $post->ID, 'newstype' ); if ($terms) { foreach($terms as $term) { echo '

' . $term->name . '

'; } } echo '

' . wp_trim_words( get_the_title( $post->ID ), 9, '...' ) . '

'; echo '
'; // start publisher code $termsx = get_the_terms( $post->ID, 'publisher' ); if ($termsx) { foreach($termsx as $term) { echo '' . $term->name . ''; } } // end publisher code // start published date if ( get_field('published_on_date') ) { // check if published date was entered into custom field echo '' . the_field('published_on_date'). ''; } else { // if not - then use wordpress post publised date echo '' . get_the_date("F n, Y" , $post->ID ) . ''; } // end published date // added admin edit link for easier accessibility while editing news post type edit_post_link('Edit Item', '
', '
'); echo '
'; echo '
'; } echo ''; } ?>