Skip to content
Permalink
master
Go to file
 
 
Cannot retrieve contributors at this time
117 lines (113 sloc) 4.67 KB
<?php
/*
* Template Name: Blog
* Displays all published posts, in reverse chronological order.
*
* This template displays the Blog Pages when you click on news archive from the news page
*/
get_header(); ?>
<div id="page-blog">
<?php include get_template_directory().'/inc/sidebar-check.php';?>
<?php while ( have_posts() ) : the_post(); ?>
<?php include get_template_directory().'/inc/submenu-check.php'; ?>
<div class="row">
<div class="col-md-8">
<div id="primary" class="content-area subpage">
<main id="main" class="site-main" role="main">
<?php
the_content();
$cat = get_post_meta( get_the_ID(), 'categories', true );
$tag = get_post_meta( get_the_ID(), 'tags', true );
$authornames = get_post_meta( get_the_ID(), 'authors', true );
$authorsArr = explode(",", $authornames);
if( array_key_exists(1, $authorsArr) ){
$authorsStr = '';
foreach( $authorsArr as $a ){
$user = get_user_by('slug', $a);
$id = $user->ID;
$authorsStr .= $id.',';
}
$author = rtrim($authorsStr, ',');
} else {
$author = get_user_by('slug', $authornames)->ID;
}
$inTheMediaObj = get_category_by_slug('neag-in-the-media');
$args = array(
'post_type' => 'post',
'category_name' => $cat,
'cat'=> '-'.$inTheMediaObj->term_id,
'tag' => $tag,
'author' => $author,
'post_status' => 'publish',
'paged' => get_query_var('paged'),
);
if( isset($args) ){
$pattern = '#[a-zA-Z|~`!@\#$%^&*()_+=|\\}\][{\'/;\-":?>.<]#';
$arr = array('category_name'=>$cat, 'tag'=>$tag, 'author'=>$author);
foreach( $arr as $k=>$v ){
if( empty($v) ){
continue;
}
if( $k == 'author' ){
$pattern = '#[0-9|~`!@\#$%^&*()_+=|\\}\][{\'/;\-":?>.<]#';
}
if( preg_match($pattern, $v) ){
$args[$k] = $v;
} else {
echo '<p>Invalid input in field: "'.$k.'"</p>';
}
}
}
query_posts( $args );
if( have_posts() ):
while( have_posts() ): the_post();?>
<article id="post-<?php the_ID(); ?>" class="post type-post status-publish clearfix">
<div class="blog-thumbnail">
<?php the_post_thumbnail('thumbnail'); ?>
</div>
<header class="entry-header">
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<p class="text-muted"><?php the_time('F j, Y'); ?></p>
</header>
<div class="entry-content">
<?php the_excerpt(); ?>
</div>
<ul class="post-categories">
<?php
$categories = get_the_category();
$separator = ' ';
$output = '';
if($categories){
foreach($categories as $category) {
if($category->name !== 'Uncategorized')
if($category->name !== 'Home-Featured')
if($category->name !== 'News Featured')
{
$output .= '<li><a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a></li>'.$separator; }
}
echo trim($output, $separator);
}
?>
</ul>
</article>
<hr />
<?php endwhile; ?>
<nav class="navigation">
<?php echo paginate_links( $args ); ?>
</nav>
<?php else: ?>
<div id="post-404" class="noposts">
<p>
<?php _e('None found.','example'); ?>
</p>
</div>
<?php endif; wp_reset_query(); ?>
</main>
</div>
</div>
<?php get_sidebar(); ?>
</div>
<?php include get_template_directory().'/inc/submenu-closing-tags.php';?>
<?php endwhile; // end of the loop. ?>
</div>
<?php get_footer(); ?>
You can’t perform that action at this time.