function widget($args, $instance) { global $post; // Preserve global $post $preserve = $post; extract($args); // only useful on post pages if (!is_single()) { return; } $title = apply_filters('widget_title', empty($instance['title']) ? __('Read Next', 'largo') : $instance['title'], $instance, $this->id_base); echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } $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)); if ($rel_posts->have_posts()) { 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>'; ?> <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, true); ?> </span> <time class="entry-date updated dtstamp pubdate" datetime="<?php echo esc_attr(get_the_date('c')); ?> "><?php largo_time(); ?> </time> </h5> <?php // post excerpt/summary largo_excerpt(get_the_ID(), 2, false, '', true); echo '</li>'; } echo "</ul>"; } echo $after_widget; // Restore global $post wp_reset_postdata(); $post = $preserve; }
/** * Returns markup for the headline of the top story **/ function homepage_big_story_headline($moreLink = false) { $bigStoryPost = largo_home_single_top(); ob_start(); ?> <article> <h5 class="top-tag"><?php largo_top_term(array('post' => $bigStoryPost->ID)); ?> </h5> <h2><a href="<?php echo get_permalink($bigStoryPost->ID); ?> "><?php echo $bigStoryPost->post_title; ?> </a></h2> <h5 class="byline"><?php largo_byline(true, true, $bigStoryPost); ?> </h5> <section> <?php if (empty($moreLink)) { largo_excerpt($bigStoryPost, 2, false); } else { largo_excerpt($bigStoryPost, 2, true, __('Continue Reading →', 'largo'), true, false); } ?> </section> </article> <?php wp_reset_postdata(); $ret = ob_get_contents(); ob_end_clean(); return $ret; }
} ?> <h2><a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a></h2> <h5 class="byline"><?php largo_byline(); ?> </h5> <?php largo_excerpt($post, 4, false); ?> <?php if (largo_post_in_series()) { $feature = largo_get_the_main_feature(); $feature_posts = largo_get_recent_posts_for_term($feature, 1, 1); if ($feature_posts) { foreach ($feature_posts as $feature_post) { ?> <h4 class="related-story"> <?php _e('RELATED:', 'largo'); ?> <a href="<?php echo esc_url(get_permalink($feature_post->ID)); ?>
<a href="<?php the_permalink(); ?> "> <?php the_post_thumbnail(); ?> </a> </div> <?php } ?> <?php if (isset($opt['show']['excerpt']) && $opt['show']['excerpt']) { largo_excerpt($post, 5, true, __('Continue Reading →', 'largo'), true, false); } ?> <?php if (isset($opt['show']['tags']) && $opt['show']['tags'] && largo_has_categories_or_tags() && $tags === 'btm') { ?> <h5 class="tag-list"><strong><?php _e('Filed under:', 'largo'); ?> </strong> <?php largo_categories_and_tags(8); ?> </h5> <?php }
</managingEditor> <?php foreach ($posts as $post) { ?> <item> <title><?php the_title_rss(); ?> </title> <link><?php the_permalink(); ?> </link> <description><?php echo '<![CDATA[' . largo_excerpt($post, 5, false, '', false) . ']]>'; ?> </description> <pubDate><?php rss_date(strtotime($post->post_date_gmt)); ?> </pubDate> <guid><?php the_permalink(); ?> </guid> <dc:creator><?php $curuser = get_user_by('id', $post->post_author); echo $curuser->first_name . ' ' . $curuser->last_name; ?> </dc:creator>
/** * @expectedDeprecated largo_excerpt */ function test_largo_excerpt() { $this->expectDeprecated(); $id = $this->factory->post->create(array('post_content' => '<span class="first-letter"><b>S</span>entence</b> <i>one<i>. Sentence two. Sentence three. Sentence four. Sentence five. Sentence six. Sentence seven. Sentence eight. Sentence nine. Sentence ten. <!--more--> This should never display.', 'post_excerpt' => false)); /** * Test that the echo variable is respected */ ob_start(); $ret = largo_excerpt($id, 5, true, '', true); $echo = ob_get_clean(); $this->assertTrue(!empty($ret)); // The $output is always returned $this->assertTrue(!empty($echo)); // We want to make sure that it all works ob_start(); $ret = largo_excerpt($id, 5, true, '', false); $echo = ob_get_clean(); $this->assertTrue(!empty($ret)); $this->assertTrue(empty($echo)); // With echo to false, this should not have anything in it /** * Test the sentence count output. */ $ret = largo_excerpt($id, 1, null, null, false); $this->assertEquals("<p>Sentence one. </p>\n", $ret, "Only one sentence should be output when the count of sentences is 1."); $ret = largo_excerpt($id, 5, null, null, false); $this->assertEquals("<p>Sentence one. Sentence two. Sentence three. Sentence four. Sentence five. </p>\n", $ret, "Only five sentences should be output when the count of sentences is 5."); $ret = largo_excerpt($id, 11, null, null, false); $this->assertEquals("<p>Sentence one. Sentence two. Sentence three. Sentence four. Sentence five. Sentence six. Sentence seven. Sentence eight. Sentence nine. Sentence ten. This should never display. </p>\n", $ret, "11 sentences should be output when the count of sentences is 11."); /** * Test that if we're on the homepage and the post has a more tag, that gets used if there is no post excerpt */ $this->go_to('/'); // Go home $ret = largo_excerpt($id, 1, null, null, false); $this->assertEquals("<p>Sentence one. Sentence two. Sentence three. Sentence four. Sentence five. Sentence six. Sentence seven. Sentence eight. Sentence nine. Sentence ten. </p>\n", $ret, "Always obey the <!-- more --> tag for excerpts on the home page."); // And now with an excerpt wp_update_post(array('ID' => $id, 'post_content' => '<span class="first-letter"><b>S</span>entence</b> <i>one<i>. Sentence two. Sentence three. Sentence four. Sentence five. Sentence six. Sentence seven. Sentence eight. Sentence nine. Sentence ten. <!--more--> This should never display.', 'post_excerpt' => 'Custom post excerpt!')); $this->go_to('/'); // Go home $ret = largo_excerpt($id, 1, null, null, false); $this->assertEquals("<p>Custom post excerpt!</p>\n", $ret, "Custom post excerpt did not output."); }
function largo_post_metadata($post_id, $echo = TRUE) { $out = '<meta itemprop="description" content="' . strip_tags(largo_excerpt(get_post($post_id), 5, false, '', false)) . '" />' . "\n"; $out .= '<meta itemprop="datePublished" content="' . get_the_date('c', $post_id) . '" />' . "\n"; $out .= '<meta itemprop="dateModified" content="' . get_the_modified_date('c', $post_id) . '" />' . "\n"; if (has_post_thumbnail($post_id)) { $image = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), 'thumbnail'); $out .= '<meta itemprop="image" content="' . $image[0] . '" />'; } if ($echo) { echo $out; } else { return $out; } }
?> <header> <h2 class="entry-title"> <a href="<?php echo post_permalink($featured_post->ID); ?> " title="<?php echo __('Permalink to', 'largo') . esc_attr(strip_tags($featured_post->post_title)); ?> " rel="bookmark"><?php echo $featured_post->post_title; ?> </a> </h2> <h5 class="byline"><?php largo_byline(true, false, $featured_post); ?> </h5> </header> <div class="entry-content"> <?php largo_excerpt($featured_post, 5, true, '', true, false); ?> </div> </div> </article>