Skip to content
This repository has been archived by the owner. It is now read-only.

Post template filters #89

Merged
merged 1 commit into from
Jan 8, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions page-blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,51 @@
<div class="col-sm-<?php echo (is_active_sidebar( $sidebar )?9:12); ?>">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php the_content();?>
<?php query_posts('post_type=post&post_status=publish&paged='. get_query_var('paged')); ?>
<?php if( have_posts() ): ?>
<?php while( have_posts() ): the_post(); ?>

<?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;
}
$args = array(
'post_type' => 'post',
'category_name' => $cat,
'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(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
Expand Down