Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
cornerstone/page-blog.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
95 lines (94 sloc)
3.09 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Template Name: Blog | |
* Displays all published posts, in reverse chronological order. | |
*/ | |
get_header(); ?> | |
<div id="page-blog"> | |
<?php include('inc/sidebar-check.php')?> | |
<?php while ( have_posts() ) : the_post(); ?> | |
<?php include('inc/submenu-check.php')?> | |
<div class="row"> | |
<div class="col-sm-<?php echo (is_active_sidebar( $sidebar )?9:12); ?>"> | |
<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; | |
} | |
$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> | |
<p class="text-muted"><?php the_date(); ?></p> | |
</header> | |
<div class="entry-content"> | |
<?php the_content(); ?> | |
</div> | |
<footer class="entry-footer"> | |
<?php the_tags(); ?> | |
</footer> | |
</article> | |
<?php endwhile; ?> | |
<nav class="navigation"> <span class="older"> | |
<?php next_posts_link(__('« Older','example')) ?> | |
</span> <span class="newer"> | |
<?php previous_posts_link(__('Newer »','example')) ?> | |
</span> | |
</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 include('inc/sidebar-if-active.php')?> | |
</div> | |
<?php include('inc/submenu-closing-tags.php')?> | |
<?php endwhile; // end of the loop. ?> | |
</div> | |
<?php get_footer(); ?> |