本文整理汇总了PHP中in_the_loop函数的典型用法代码示例。如果您正苦于以下问题:PHP in_the_loop函数的具体用法?PHP in_the_loop怎么用?PHP in_the_loop使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了in_the_loop函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insert_layout
/**
* Renders a layout with the provided post ID and enqueues the
* necessary styles and scripts.
*
* @since 1.7
* @param array $attrs The shortcode attributes.
* @return string
*/
public static function insert_layout($attrs)
{
$builder_active = in_the_loop() && FLBuilderModel::is_builder_active();
$post_type = isset($attrs['type']) ? $attrs['type'] : get_post_types();
$args = array('post_type' => $post_type, 'posts_per_page' => -1);
// Build the args array.
if (isset($attrs['id'])) {
$args['orderby'] = 'post__in';
if (is_numeric($attrs['id'])) {
$args['post__in'] = array($attrs['id']);
} else {
$args['post__in'] = explode(',', $attrs['id']);
}
} else {
if (isset($attrs['slug'])) {
$args['orderby'] = 'name';
$args['name'] = $attrs['slug'];
} else {
return;
}
}
// Render and return the layout.
ob_start();
if ($builder_active) {
echo '<div class="fl-builder-shortcode-mask-wrap"><div class="fl-builder-shortcode-mask"></div>';
}
FLBuilder::render_query($args);
if ($builder_active) {
echo '</div>';
}
return ob_get_clean();
}
示例2: tc_fp_block_display
/**
* The template displaying the front page featured page block.
*
*
* @package FPC
* @since FPC 1.3
*/
function tc_fp_block_display()
{
$hook = esc_attr(tc__f('__get_fpc_option', 'tc_fp_position'));
//if the hook is loop start, we don't want to display fp in all queries.
if ('loop_start' == $hook && (!is_main_query() || !in_the_loop())) {
return;
}
//gets display options
$tc_show_featured_pages = esc_attr(tc__f('__get_fpc_option', 'tc_show_fp'));
if (!apply_filters('tc_show_fp', 0 != $tc_show_featured_pages && tc__f('__is_home'))) {
return;
}
//gets the featured pages array and sets the fp layout
$fp_ids = apply_filters('fpc_featured_pages_ids', TC_fpc::$instance->fpc_ids);
$fp_nb = count($fp_ids);
list($span_value, $fp_per_row) = $this->tc_get_layout();
//save $args for filter
$args = array($fp_ids, $fp_nb, $fp_per_row, $span_value);
?>
<?php
ob_start();
?>
<div class="fpc-container fpc-marketing">
<?php
do_action('__before_fp');
$j = 1;
for ($i = 1; $i <= $fp_nb; $i++) {
printf('%1$s<div class="fpc-span%2$s fp-%3$s">%4$s</div>%5$s', 1 == $j ? '<div class="fpc-row-fluid fpc-widget-area" role="complementary">' : '', $span_value, $fp_ids[$i - 1], $this->tc_fp_single_display($fp_ids[$i - 1]), $j == $fp_per_row || $i == $fp_nb ? '</div>' : '');
//set $j back to start value if reach $fp_per_row
$j++;
$j = $j == $fp_per_row + 1 ? 1 : $j;
}
do_action('__after_fp');
//display edit link for logged in users with edit posts capabilities
if (apply_filters('tc_show_fp_edit_link', is_user_logged_in()) && !TC_utils_fpc::$instance->is_customizing) {
printf('<a class="fpc-edit-link fpc-btn fpc-btn-inverse" href="%1$s" title="%2$s" target="_blank">%2$s</a>', admin_url() . 'customize.php', __('Edit Featured Pages', $this->plug_lang));
}
//end edit attachment condition
?>
</div><!-- .fpc-container -->
<?php
echo !tc__f('__is_home_empty') ? apply_filters('fpc_after_fp_separator', '<hr class="featurette-divider ' . current_filter() . '">') : '';
?>
<?php
$html = ob_get_contents();
if ($html) {
ob_end_clean();
}
//Return or echo
$hook = esc_attr(tc__f('__get_fpc_option', 'tc_fp_position'));
if ('wp_nav_menu' != $hook) {
echo apply_filters('fpc_block_display', $html, $args);
} else {
return apply_filters('fpc_block_display', $html, $args);
}
}
示例3: spine_section_meta
function spine_section_meta($attribute = 'slug', $sectional = 'subsection')
{
if (!is_singular() && !in_the_loop()) {
return '';
}
if (empty($sectional)) {
$sectional = 'subsection';
}
if (empty($attribute) || 'slug' == $attribute) {
$attribute = 'post_name';
}
if ('title' == $attribute) {
$attribute = 'post_title';
}
$subsections = get_post_ancestors(get_the_ID());
if (!empty($subsections)) {
$subsection = get_post($subsections[0]);
$sections = array_reverse($subsections);
$section = get_post($sections[0]);
if (isset($sectional) && in_array($sectional, array('section', 'top'))) {
return $section->{$attribute};
} else {
return $subsection->{$attribute};
}
}
return null;
}
示例4: mm_in_the_loop_contact_button
function mm_in_the_loop_contact_button($class = '', $text = '', $subject = '', $ouput = true)
{
if (!in_the_loop()) {
return;
}
//this is in the loop, we can get author
$username = get_the_author();
$user = null;
if (!empty($username)) {
$user = get_user_by('login', $username);
}
if (!$user instanceof WP_User) {
return;
}
$shortcode = "[pm_user ";
$shortcode .= sprintf('user_id="%s" ', $user->ID);
if (!empty($class)) {
$shortcode .= sprintf('class="%s" ', $class);
}
if (!empty($text)) {
$shortcode .= sprintf('text="%s" ', $text);
}
if (!empty($subject)) {
$shortcode .= sprintf('subject="%s" ', $subject);
}
$shortcode .= "]";
if ($ouput) {
echo do_shortcode($shortcode);
} else {
return do_shortcode($shortcode);
}
}
示例5: image
/**
* image()
*
* @param array $anchor
* @return anchor $anchor
**/
function image($anchor)
{
if (!preg_match("/^\\s*<\\s*img\\s.+?>\\s*\$/is", $anchor['body'])) {
return $anchor;
}
if (!$anchor['attr']['class']) {
$anchor['attr']['class'][] = 'thickbox';
$anchor['attr']['class'][] = 'no_icon';
} else {
if (!in_array('thickbox', $anchor['attr']['class']) && !in_array('nothickbox', $anchor['attr']['class']) && !in_array('no_thickbox', $anchor['attr']['class'])) {
$anchor['attr']['class'][] = 'thickbox';
}
if (!in_array('no_icon', $anchor['attr']['class']) && !in_array('noicon', $anchor['attr']['class'])) {
$anchor['attr']['class'][] = 'no_icon';
}
}
if (in_the_loop() && !$anchor['attr']['rel']) {
$anchor['attr']['rel'][] = 'gallery-' . get_the_ID();
}
if (empty($anchor['attr']['title'])) {
if (preg_match("/\\b(?:alt|title)\\s*=\\s*('|\")(.*?)\\1/i", $anchor['body'], $title)) {
$anchor['attr']['title'] = end($title);
}
}
return $anchor;
}
示例6: tc_maybe_display_img_smartload_help
/**
* Displays a help block about images smartload for single posts prepended to the content
* hook : the_content
* @since Customizr 3.4+
*/
function tc_maybe_display_img_smartload_help($the_content)
{
if (!($this->tc_page_display_controller() && in_the_loop() && TC_placeholders::tc_is_img_smartload_help_on($the_content))) {
return $the_content;
}
return TC_placeholders::tc_print_smartload_help_block() . $the_content;
}
示例7: get_author_avatar
function get_author_avatar()
{
global $default;
$avatar = '';
if (class_exists('author_image')) {
$avatar = author_image::get();
}
if ($avatar == '') {
if (in_the_loop()) {
$author_id = get_the_author_ID();
} elseif (is_singular()) {
global $wp_the_query;
$author_id = $wp_the_query->posts[0]->post_author;
} elseif (is_author()) {
global $wp_the_query;
$author_id = $wp_the_query->get_queried_object_id();
}
$author = get_userdata($author_id);
if (!empty($author)) {
$avatar = get_avatar($author->user_email, 64, $default, $author->display_name);
} else {
$avatar = '<img src="' . esc_url($default) . '" alt="' . $author->display_name . '" />';
}
}
return $avatar;
}
示例8: inject_singular_content
/**
* Inject vehicle singular content into singular page
*
* @param string $content
*
* @return string
*/
public function inject_singular_content($content)
{
global $post;
// check if we need to inject
if (!is_singular(Vehicle\PostType::VEHICLE) || !in_the_loop()) {
return $content;
}
// remove filter to prevent crazy loops
remove_filter('the_content', array($this, 'inject_singular_content'));
// check if vehicle actually the post type that's being looped
if (Vehicle\PostType::VEHICLE === $post->post_type) {
// create vehicle object
$vehicle = wp_car_manager()->service('vehicle_factory')->make($post->ID);
ob_start();
/**
* wpcm_before_main_content hook
*/
do_action('wpcm_before_single_content', $vehicle);
// load content-single-vehicle
$this->get_template_part('content', 'single-vehicle', array('vehicle' => $vehicle));
/**
* wpcm_after_main_content hook
*/
do_action('wpcm_after_single_content', $vehicle);
// set new content
$content = ob_get_clean();
}
// add filter back in place
add_filter('the_content', array($this, 'inject_singular_content'));
// return content
return apply_filters('wpcm_content_single_vehicle', $content, $post);
}
示例9: zippo_thumbnail_url
function zippo_thumbnail_url($post_id = null, $size = 'post-thumbnail', $attr = '')
{
$url = array();
$post_id = null === $post_id ? get_the_ID() : $post_id;
$post_thumbnail_id = get_post_thumbnail_id($post_id);
/**
* Filter the post thumbnail size.
*
* @since 2.9.0
*
* @param string $size The post thumbnail size.
*/
$size = apply_filters('post_thumbnail_size', $size);
if ($post_thumbnail_id) {
/**
* Fires before fetching the post thumbnail HTML.
*
* Provides "just in time" filtering of all filters in wp_get_attachment_image().
*
* @since 2.9.0
*
* @param string $post_id The post ID.
* @param string $post_thumbnail_id The post thumbnail ID.
* @param string $size The post thumbnail size.
*/
do_action('begin_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size);
if (in_the_loop()) {
update_post_thumbnail_cache();
}
$url = wp_get_attachment_image_src($post_thumbnail_id, $size, false, $attr);
}
return reset($url);
}
示例10: page_content
public function page_content($content)
{
global $wtd_plugin, $post, $wp_query;
if (!is_singular('page') || !in_the_loop()) {
return $content;
}
$res_id = get_post_meta($post->ID, 'res_id', true);
$wtd_pages = get_option('wtd_pages');
$page_type = get_post_meta($post->ID, 'wtd_page', true);
if (!empty($wtd_pages['activities_pages'][$res_id]) || $page_type == 'activity_page') {
if (in_array($post->ID, $wtd_pages['activities_pages'])) {
remove_filter('the_content', 'theme_formatter', 99);
remove_filter('the_content', 'wpautop');
ob_start();
if (empty($wp_query->query['wtdc']) && empty($_GET['wtdc'])) {
$this->matrix();
} elseif (!empty($wp_query->query['wtdc']) || !empty($_GET['wtdc'])) {
switch ($wtd_plugin['act_page_type']) {
case 2:
$this->results();
break;
case 3:
default:
$this->results();
break;
}
}
$content = ob_get_contents();
ob_end_clean();
}
}
return $content;
}
示例11: pm_user
function pm_user($atts)
{
$this->button_id = uniqid();
$a = shortcode_atts(array('user_id' => '', 'user_name' => '', 'text' => __('Message me', mmg()->domain), 'class' => 'btn btn-sm btn-primary', 'subject' => __('You have new message!', mmg()->domain), 'in_the_loop' => false), $atts);
if (!empty($a['user_id'])) {
$user = get_user_by('id', $a['user_id']);
} elseif (!empty($a['user_name'])) {
$user = get_user_by('login', $a['user_name']);
} elseif ($a['in_the_loop'] == true && in_the_loop()) {
//this is in the loop, we can get author
$username = get_the_author_meta('user_login');
if (!empty($username)) {
$user = get_user_by('login', $username);
}
}
if (!isset($user) || !is_object($user)) {
return '';
}
if (!is_user_logged_in()) {
mmg()->load_script('login');
}
//add modal in footer,only if user logged in
add_action('wp_footer', array(&$this, 'message_me_modal'));
return $this->render('message_me/buttons', array('a' => $a, 'user' => $user), false);
}
示例12: replace_page_content
public static function replace_page_content($content)
{
if (in_the_loop()) {
$content = self::get_content();
}
return $content;
}
开发者ID:amankatoch,项目名称:wp-plugin,代码行数:7,代码来源:class-displet-rets-idx-search-results-page-controller.php
示例13: relMe
/**
* Link to a site's Twitter profile using rel me
*
* Adds via attribution to Twitter widgets on the page
*
* @link http://microformats.org/wiki/rel-me XFN rel me
*
* @return void
*/
public static function relMe()
{
$site_username = \Twitter\WordPress\Site\Username::getViaAttribution(in_the_loop() ? get_the_ID() : null);
if ($site_username) {
echo '<link rel="me" href="' . esc_url(\Twitter\Helpers\TwitterURL::profile($site_username), array('https', 'http')) . '"' . \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement() . '>';
}
}
示例14: replace_page_title
public static function replace_page_title($title, $id)
{
if ($id == self::$_options['property_details_page_id'] && in_the_loop() && DispletRetsIdxUtilities::is_referral_function('the_title')) {
return self::get_page_title();
}
return $title;
}
开发者ID:amankatoch,项目名称:wp-plugin,代码行数:7,代码来源:class-displet-rets-idx-partial-address-page-controller.php
示例15: display_pagetitle_icon
function display_pagetitle_icon($title)
{
global $post;
/* get values from post meta*/
$value = get_post_meta($post->ID, '_wpptwi_icon', true);
$icon_color = get_post_meta($post->ID, '_wpptwi_icon_color', true);
$icon_size = get_post_meta($post->ID, '_wpptwi_icon_size', true);
/* escapes html entities*/
$icon = esc_attr($value);
$icon_color = esc_attr($icon_color);
$icon_size = esc_attr($icon_size);
/* checks if the icon is empty, title is in the loop*/
if (!empty($icon) && in_the_loop()) {
/* check if this is the current page */
if (is_page($post->ID) && $title == $post->post_title) {
return '<i class="fa ' . $icon . '" style="color:' . $icon_color . '; font-size:' . $icon_size . 'px"></i> ' . $title;
} else {
if (is_single($post->ID) && $title == $post->post_title) {
return '<i class="fa ' . $icon . '" style="color:' . $icon_color . '; font-size:' . $icon_size . 'px"></i> ' . $title;
} else {
return $title;
}
}
} else {
return $title;
}
}