Skip to content

Commit

Permalink
Merge branch 'master' into develop, resolve conflicts, add doc for la…
Browse files Browse the repository at this point in the history
…rgo_loop_after_post_x action
  • Loading branch information
benlk committed Aug 25, 2016
2 parents bfda8b6 + e1c30f5 commit ffab1cc
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 67 deletions.
6 changes: 4 additions & 2 deletions archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@
<?php
// and finally wind the posts back so we can go through the loop as usual
rewind_posts();

$counter = 1;
while ( have_posts() ) : the_post();
$post_type = get_post_type();
$partial = largo_get_partial_by_post_type('archive', $post_type, 'archive');
$partial = largo_get_partial_by_post_type( 'archive', $post_type, 'archive' );
get_template_part( 'partials/content', $partial );
do_action( 'largo_loop_after_post_x', $counter, $context = 'archive' );
$counter++;
endwhile;

largo_content_nav( 'nav-below' );
Expand Down
9 changes: 8 additions & 1 deletion category.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,20 @@
<?php
do_action( 'largo_before_category_river' );
if ( have_posts() ) {
$counter = 1;
while ( have_posts() ) {
the_post();
$post_type = get_post_type();
$partial = largo_get_partial_by_post_type('archive', $post_type, 'archive');
$partial = largo_get_partial_by_post_type( 'archive', $post_type, 'archive' );
get_template_part( 'partials/content', $partial );
do_action( 'largo_loop_after_post_x', $counter, $context = 'archive' );
$counter++;
}
largo_content_nav( 'nav-below' );
} elseif ( count($featured_posts) > 0 ) {
// do nothing
// We have n > 1 posts in the featured header
// It's not appropriate to display partials/content-not-found here.
} else {
get_template_part( 'partials/content', 'not-found' );
}
Expand Down
24 changes: 24 additions & 0 deletions docs/developers/hooksfilters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,29 @@ Here is the current list of hooks available in Largo (available as of v.0.4):

- **largo_header_before_largo_header** - immediately before ``largo_header()`` is output
- **largo_header_after_largo_header** - immediately after ``largo_header()`` is output. By default, ``largo_header_widget_sidebar`` is hooked here.

**for all lists of posts**

- **largo_loop_after_post_x** - fires after every post in a river of posts on the homepage or archive pages. This is helpful if you want to insert interstitial content in a river of posts (typically things like newsletter subscription widgets, donation messages, etc.).

This action takes a couple of arguments that may come in handy:

do_action( 'largo_loop_after_post_x', $counter, $context );

- **$counter** tracks the number of posts in any given loop
- **$context** is presently either 'archive' or 'home' to give you flexibility to insert different interstitials for different page types.

an example of this in use might look like:

function mytheme_interstitial( $counter, $context ) {
if ( $counter === 2 && $context === 'home' ) {
// do homepage stuff
} elseif ( $counter === 2 && $context === 'archive' ) {
// do something different in the same spot on archive pages
}
}
add_action( 'largo_loop_after_post_x', 'mytheme_interstitial', 10, 2 );


**home.php**

Expand Down Expand Up @@ -322,6 +345,7 @@ These actions are run on all homepage templates, including the Legacy Three Colu

- **largo_category_after_description_in_header** - between the ``div.archive-description`` and before ``get_template_part('partials/archive', 'category-related');``.
- **largo_before_category_river** - just before the river of stories at the bottom of the category archive page (for adding a header to this column, for example)
- **largo_loop_after_post_x** - runs after every post, with arguments ``$counter`` and ``context`` describing which post it's running after and what the context is. (In categories, the context is ``archive``.)
- **largo_after_category_river** - immediately after the river of stories at the bottom of the category archive page, after the Load More Posts button (for adding a footer to this column, for example.)

**search.php**
Expand Down
3 changes: 3 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ function largo_setup() {

// Add support for localization (this is a work in progress)
load_theme_textdomain('largo', get_template_directory() . '/lang');

//Add support for <title> tags
add_theme_support( 'title-tag' );

}
}
Expand Down
12 changes: 1 addition & 11 deletions inc/post-metaboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,21 +330,11 @@ function largo_top_terms_js() {
*
*/
function largo_prominence_meta_box($post, $args) {
$largoProminenceTerms = $args['args'];

$terms = get_terms('prominence', array(
$termList = get_terms('prominence', array(
'hide_empty' => false,
'fields' => 'all'
));

$slugs = array_map(function($arg) { return $arg['slug']; }, $largoProminenceTerms);

$termList = array();
foreach ($terms as $k => $v) {
if (in_array($v->slug, $slugs))
$termList[] = $v;
}

$tax = get_taxonomy('prominence');
$args = array(
'taxonomy' => 'prominence',
Expand Down
8 changes: 4 additions & 4 deletions inc/related-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ protected function get_series_posts() {
protected function get_term_posts() {

//we've gone back and forth through all the post's series, now let's try traditional taxonomies
$taxonomies = get_the_terms( $this->post_id, array('category', 'post_tag') );
$taxonomies = get_the_terms( $this->post_id, array( 'category', 'post_tag' ) );

//loop thru taxonomies, much like series, and get posts
if ( is_array($taxonomies) ) {
Expand All @@ -629,7 +629,7 @@ protected function get_term_posts() {
'taxonomy' => $term->taxonomy,
'term' => $term->slug,
'orderby' => 'date',
'order' => 'ASC',
'order' => 'DESC',
'ignore_sticky_posts' => 1,
'date_query' => array(
'after' => $this->post->post_date,
Expand All @@ -640,7 +640,7 @@ protected function get_term_posts() {
$term_query = new WP_Query( $args );

// If not enough posts were added from after this post, look before this post
if ( count($term_query->posts) < $this->number ) {
if ( count( $term_query->posts ) < $this->number ) {

// Store the returned posts from the after query
$this->add_from_query( $term_query );
Expand Down Expand Up @@ -681,7 +681,7 @@ protected function get_recent_posts() {
$posts_query = new WP_Query( $args );

if ( $posts_query->have_posts() ) {
$this->add_from_query($posts_query);
$this->add_from_query( $posts_query );
}
}

Expand Down
9 changes: 7 additions & 2 deletions inc/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,13 @@ function largo_edit_permission_check() {
global $current_user, $profileuser;

$screen = get_current_screen();

get_currentuserinfo();

global $wp_version;
if ( $wp_version < 4.5 ) {
get_currentuserinfo();
} else {
wp_get_current_user();
}

if( ! is_super_admin( $current_user->ID ) && in_array( $screen->base, array( 'user-edit', 'user-edit-network' ) ) ) { // editing a user profile
if ( is_super_admin( $profileuser->ID ) ) { // trying to edit a superadmin while less than a superadmin
Expand Down
66 changes: 30 additions & 36 deletions inc/widgets/largo-related-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,42 @@ function widget( $args, $instance ) {

if ( $title ) echo $before_title . $title . $after_title;

$related = new Largo_Related( $instance['qty'] );
$related = new Largo_Related( $instance['qty'] );

//get the related posts
$rel_posts = new WP_Query( array(
'post__in' => $related->ids(),
'nopaging' => 1,
'posts_per_page' => $instance['qty'],
'ignore_sticky_posts' => 1
) );
//get the related posts
$rel_posts = new WP_Query( array(
'post__in' => $related->ids(),
'nopaging' => 1,
'posts_per_page' => $instance['qty'],
'ignore_sticky_posts' => 1
) );

if ( $rel_posts->have_posts() ) {
if ( $rel_posts->have_posts() ) {

echo '<ul class="related">';
echo '<ul class="related">';

while ( $rel_posts->have_posts() ) {
$rel_posts->the_post();
echo '<li>';
echo '<a href="' . get_permalink() . '"/>' . get_the_post_thumbnail( get_the_ID(), 'thumbnail', array('class'=>'alignleft') ) . '</a>';
while ( $rel_posts->have_posts() ) {
$rel_posts->the_post();
echo '<li>';

echo '<a href="' . get_permalink() . '"/>' . get_the_post_thumbnail( get_the_ID(), 'thumbnail', array( 'class' => '' ) ) . '</a>';
?>
<h4><a href="<?php the_permalink(); ?>" title="Read: <?php esc_attr( the_title('','', FALSE) ); ?>"><?php the_title(); ?></a></h4>
<h5 class="byline">
<span class="by-author"><?php largo_byline( true, false ); ?></span>
</h5>

<h4><a href="<?php the_permalink(); ?>" title="Read: <?php esc_attr( the_title( '','', FALSE ) ); ?>"><?php the_title(); ?></a></h4>

<?php if ( $instance['show_byline'] ) { ?>
<h5 class="byline">
<span class="by-author"><?php largo_byline( true, false ); ?></span>
</h5>
<?php } ?>

<?php // post excerpt/summary
largo_excerpt(get_the_ID(), 2, null, null, true);
echo '</li>';
}
largo_excerpt(get_the_ID(), 2, false, '', true);
echo '</li>';
}

echo "</ul>";
}
echo "</ul>";
}
echo $after_widget;
// Restore global $post
wp_reset_postdata();
Expand All @@ -68,7 +74,6 @@ function update( $new_instance, $old_instance ) {
$instance['title'] = sanitize_text_field($new_instance['title']);
$instance['qty'] = (int) $new_instance['qty'];
$instance['show_byline'] = (int) $new_instance['show_byline'];
$instance['thumbnail_location'] = sanitize_key( $new_instance['thumbnail_location'] );
return $instance;
}

Expand All @@ -93,18 +98,7 @@ function form( $instance ) {
</p>

<p><input id="<?php echo $this->get_field_id('show_byline'); ?>" name="<?php echo $this->get_field_name('show_byline'); ?>" type="checkbox" value="1" <?php checked( $instance['show_byline'], 1);?> />
<label for="<?php echo $this->get_field_id('show_byline'); ?>"><?php _e( 'Show date with each post', 'largo' ); ?></label>
</p>

<p>
<label for="<?php echo $this->get_field_id('thumbnail_location'); ?>"><?php _e('Thumbnail position', 'largo'); ?>:</label>
<select name="<?php echo $this->get_field_name('thumbnail_location'); ?>" id="<?php echo $this->get_field_id('thumbnail_location'); ?>">
<?php
$choices = array( 'before' => __( 'Before Headline', 'largo' ), 'after' => __( 'After Headline', 'largo' ) );
foreach( $choices as $i => $display ) {
echo '<option value="', $i, '"', selected($instance['thumbnail_location'], $i, false), '>', $display, '</option>';
} ?>
</select>
<label for="<?php echo $this->get_field_id('show_byline'); ?>"><?php _e( 'Show byline on each post', 'largo' ); ?></label>
</p>

<?php
Expand Down
5 changes: 4 additions & 1 deletion partials/content-not-found.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
wp_kses($_SERVER['REQUEST_URI'], array()) // The url, sanitized
);
}

$title = '<h1 class="entry-title">' . __( 'Page Not Found', 'largo' ) . '</h1>';
} else if ( is_search() ) {
$apologies = __( 'Apologies, but no results were found. Perhaps searching for something else will help.', 'largo' );
$title = '';
}

?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Page Not Found', 'largo' ); ?></h1>
<?php echo $title ?>
</header><!-- .entry-header -->

<div class="entry-content">
Expand Down
26 changes: 16 additions & 10 deletions partials/home-post-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,31 @@
'ignore_sticky_posts' => true
);

if (of_get_option('num_posts_home'))
$args['posts_per_page'] = of_get_option('num_posts_home');
if (of_get_option('cats_home'))
$args['cat'] = of_get_option('cats_home');
if ( of_get_option( 'num_posts_home' ) ) {
$args['posts_per_page'] = of_get_option( 'num_posts_home', 10 );
}
if ( of_get_option( 'cats_home' ) ) {
$args['cat'] = of_get_option( 'cats_home', '' );
}

$query = new WP_Query($args);
if ($query->have_posts()) {

if ( $query->have_posts() ) {
$counter = 1;
while ($query->have_posts()) : $query->the_post();
//if the post is in the array of post IDs already on this page, skip it. Just a double-check
if (in_array(get_the_ID(), $shown_ids))
if ( in_array( get_the_ID(), $shown_ids))
continue;
else {
$shown_ids[] = get_the_ID();
do_action('largo_before_home_list_post', $post, $query);
do_action( 'largo_before_home_list_post', $post, $query );
get_template_part('partials/content', 'home');
do_action('largo_after_home_list_post', $post, $query);
do_action( 'largo_after_home_list_post', $post, $query );
do_action( 'largo_loop_after_post_x', $counter, $context = 'home' );
$counter++;
}
endwhile;
largo_content_nav('nav-below');
largo_content_nav( 'nav-below' );
} else {
get_template_part('partials/content', 'not-found');
get_template_part( 'partials/content', 'not-found' );
}
3 changes: 3 additions & 0 deletions series-landing.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@
}

$series_query = new WP_Query($args);
$counter = 1;
while ( $series_query->have_posts() ) : $series_query->the_post();
get_template_part( 'partials/content', 'series' );
do_action( 'largo_loop_after_post_x', $counter, $context = 'archive' );
$counter++;
endwhile;
wp_reset_postdata();

Expand Down

0 comments on commit ffab1cc

Please sign in to comment.