function custom_dashboard_display_stats($widget) { ?> <p>Les principales valeurs statistiques de l'intégration BF QUOTES</p> <div class="inside"> <?php // global $wpdb; /* === JUST AS REMINDER post_type => product_for_sale taxonomy => product_for_sale_genre taxonomy => product_for_sale_author taxonomy => product_for_sale_kw */ $num_posts_bf_quotes_manager = wp_count_posts('bf_quotes_manager'); // Main figures for product_for_sale $num_product_for_sale = $num_posts_product_for_sale->publish; // nb for Author(s) $num_cats_bf_quotes_manager_author = wp_count_terms('bf_quotes_manager_author'); // nb for Flavor(s) $num_tags_bf_quotes_manager_flavor = wp_count_terms('bf_quotes_manager_flavor'); ?> <h4><strong>Les chiffres-clés</strong></h4> <ul> <li>Nombre d' Auteur(s) : <b><?php echo '' . $num_cats_bf_quotes_manager_author . ''; ?> </b></li> <li>Nombre de Saveur(s) : <b><?php echo '' . $num_tags_bf_quotes_manager_flavor . ''; ?> </b></li> </ul> <h4><strong>Les dernières citations enregistrées</strong></h4> <?php /* LAST POSTS */ $args = array('offset' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'numberposts' => '3', 'post_status' => 'publish', 'post_type' => 'bf_quotes_manager'); $recent_posts = wp_get_recent_posts($args); /* debug only */ // print_r($recent_posts); foreach ($recent_posts as $recent) { setup_postdata(get_post($recent['ID'])); // Output echo '<ul><li><a class="rsswidget" href="' . get_permalink($recent['ID']) . '" title="' . esc_attr(get_the_title($recent['ID'])) . '">' . get_the_title($recent['ID']) . '</a> <span class="rss-date">' . get_the_time('j F Y', $recent['ID']) . '</span><div class="rssSummary">' . $recent['post_excerpt'] . '</div></li>'; } // EOL wp_reset_postdata(); ?> </div> <?php }
/** * How to display the widget on the screen. */ function widget($args, $instance) { extract($args); global $wp_query, $post; /* Our variables from the widget settings. */ $title = apply_filters('widget_title', isset($instance['title']) ? $instance['title'] : ''); $post_type = isset($instance['post_type']) ? $instance['post_type'] : 'post'; $taxonomy = axiom_get_taxonomy_categories_by_post_type($post_type); $number = isset($instance['number']) ? (int) $instance['number'] : ''; $show_date = isset($instance['show_date']) ? (int) $instance['show_date'] : 0; $show_image = isset($instance['show_image']) ? (int) $instance['show_image'] : 0; $show_author = isset($instance['show_author']) ? (int) $instance['show_author'] : 0; $show_counters = isset($instance['show_counters']) && $instance['show_counters'] > 0 ? axiom_get_theme_option('blog_counters') : ''; $category = isset($instance['category']) ? (int) $instance['category'] : 0; $output = ''; $args = array('numberposts' => $number, 'offset' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => $post_type, 'post_status' => current_user_can('read_private_pages') && current_user_can('read_private_posts') ? array('publish', 'private') : 'publish', 'ignore_sticky_posts' => 1, 'suppress_filters' => true); if ($category > 0) { if ($taxonomy == 'category') { $args['category'] = $category; } else { $args['tax_query'] = array(array('taxonomy' => $taxonomy, 'field' => 'id', 'terms' => $category)); } } $ex = axiom_get_theme_option('exclude_cats'); if (!empty($ex)) { $args['category__not_in'] = explode(',', $ex); } $recent_posts = wp_get_recent_posts($args, OBJECT); $post_number = 0; foreach ($recent_posts as $post) { $post_number++; require axiom_get_file_dir('templates/parts/widgets-posts.php'); if ($post_number >= $number) { break; } } if (!empty($output)) { /* Before widget (defined by themes). */ echo $before_widget; /* Display the widget title if one was input (before and after defined by themes). */ echo $before_title . $title . $after_title; echo $output; /* After widget (defined by themes). */ echo $after_widget; } }
function Grafik_Shortcode_RecentPosts_Callback($atts, $content = null) { // Query Params... $a = shortcode_atts(array('numberposts' => 10, 'offset' => 0, 'category' => '', 'orderby' => 'post_date', 'order' => 'DESC', 'include' => null, 'exclude' => null, 'meta_key' => null, 'meta_value' => null, 'post_type' => 'post', 'post_status' => 'publish', 'suppress_filters' => true, 'heading' => 'Recent Posts', 'show_preview' => 'true', 'show_postdate' => 'true', 'show_title' => 'true', 'show_excerpt' => 'true', 'class' => '', 'id' => ''), $atts, "RecentPost"); // Convert Category Slugs to IDs... $category_list = explode(",", $a['category']); foreach ($category_list as $key => $val) { if (is_numeric($val)) { continue; } $is_negative = substr($val, 0, 1) == "-"; $trim_val = trim($val, "-"); $category = get_category_by_slug($trim_val); $category_list[$key] = ($is_negative ? "-" : null) . $category->term_id; } $a['category'] = implode(",", $category_list); // Filters... $grafik_filters = get_option("grafik-filters"); if (!is_array($grafik_filters)) { $grafik_filters = json_decode($grafik_filters, true); } // Query Recent Posts Using Params... $RecentPosts = wp_get_recent_posts($a, ARRAY_A); foreach ($RecentPosts as $RecentPost) { // Get Category Info... $info_categories = array(); $GRAFIK_CATEGORIES = wp_get_post_categories($RecentPost['ID']); foreach ($GRAFIK_CATEGORIES as $key => $val) { $cat = get_category($val); // Filter Uncategorized from display... if (is_array($grafik_filters['category-masking']) && in_array($cat->term_id, $grafik_filters['category-masking'])) { continue; } $info_categories[] = '<span class="theme-recentposts-postcategory ' . $cat->slug . '">' . $cat->name . '</span>'; } // Get Stored Meta Values... $PREFILL = array('grafik-meta-preview-desktop' => stripslashes(esc_textarea(base64_decode(get_post_meta($RecentPost['ID'], 'grafik-meta-preview-desktop', true)))), 'grafik-meta-preview-tablet' => stripslashes(esc_textarea(base64_decode(get_post_meta($RecentPost['ID'], 'grafik-meta-preview-tablet', true)))), 'grafik-meta-preview-phone' => stripslashes(esc_textarea(base64_decode(get_post_meta($RecentPost['ID'], 'grafik-meta-preview-phone', true)))), 'grafik-meta-excerpt' => apply_filters('the_excerpt', get_post_field('post_excerpt', $RecentPost['ID']))); // Construct Recent Post Anchor... $content .= '<a href="' . get_permalink($RecentPost['ID']) . '" class="theme-recentposts-post">' . ($a['show_preview'] == 'false' ? null : '<span class="theme-recentposts-postimage">' . (empty($PREFILL['grafik-meta-preview-desktop']) ? null : '<img src="' . $PREFILL['grafik-meta-preview-desktop'] . '" width="100%" height="100%" alt="' . $RecentPost['post_title'] . '" class="theme-recentposts-preview-desktop" />') . (empty($PREFILL['grafik-meta-preview-tablet']) ? null : '<img src="' . $PREFILL['grafik-meta-preview-tablet'] . '" width="100%" height="100%" alt="' . $RecentPost['post_title'] . '" class="theme-recentposts-preview-tablet" />') . (empty($PREFILL['grafik-meta-preview-phone']) ? null : '<img src="' . $PREFILL['grafik-meta-preview-phone'] . '" width="100%" height="100%" alt="' . $RecentPost['post_title'] . '" class="theme-recentposts-preview-phone" />') . '</span>') . ($a['show_postdate'] == 'false' ? null : '<span class="theme-recentposts-postdate">' . date('m/d/Y', strtotime($RecentPost['post_date'])) . '</span>') . ($a['show_title'] == 'false' ? null : '<span class="theme-recentposts-posttitle">' . $RecentPost['post_title'] . '</span>') . ($a['show_categories'] == 'false' || empty($info_categories) ? null : '<span class="theme-recentposts-postcategories">' . implode('', $info_categories) . '</span>') . ($a['show_excerpt'] == 'false' ? null : '<span class="theme-recentposts-postexcerpt">' . $PREFILL['grafik-meta-excerpt'] . '</span>') . '</a>'; } // Return Content... return '<div class="theme-recentposts' . (empty($a['class']) ? null : ' ' . $a['class']) . '"' . (empty($a['id']) ? null : ' id="' . $a['id'] . '"') . '>' . '<div class="theme-recentposts-interior">' . (empty($a['heading']) ? null : '<h2>' . $a['heading'] . '</h2>') . (empty($content) ? null : $content) . '</div>' . '</div>'; }
function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); $Num = apply_filters('$Num', $instance['Num']); if (!empty($instance['title'])) { //TEMISI BOSH QALDURULSA 'رەڭدار خەتكۈشلەر' BOLUP KORINIDU $title = $instance['title']; } else { $title = 'ئەڭ يېڭى يازمىلار'; } if (!empty($instance['Num'])) { $Num = $instance['Num']; } else { $Num = '10'; } $title = apply_filters('widget_title', $title, $instance, $this->id_base); $Num = apply_filters('$Num', $Num, $instance, $this->id_base); echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } ?> <ul> <?php $args = array('numberposts' => $Num); $recent_posts = wp_get_recent_posts($args); $i = 0; foreach ($recent_posts as $recent) { if ($i % 2 == 0) { echo '<li class="item odd">'; } else { echo '<li class="item even">'; } $i++; echo '<a href="' . get_permalink($recent["ID"]) . '" title="' . esc_attr($recent["post_title"]) . ' نى كۆرۈش"' . ' target = "' . 'blank">' . $recent["post_title"] . '</a> </li> '; } ?> </ul> <?php echo $after_widget; }
/** * Widget function. * * @see WP_Widget * @access public * @param array $args * @param array $instance * @return void */ function widget($args, $instance) { if ($this->get_cached_widget($args)) { return; } ob_start(); extract($args); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $count = $instance['count']; $category = $instance['category']; $posts = wp_get_recent_posts(array('post_type' => 'post', 'numberposts' => $count, 'post_status' => 'publish', 'category' => $category), OBJECT); global $post; echo $before_widget; echo '<section class="recent-posts-grid" data-layout="2-2-2-2">'; if ($title) { echo $before_title . $title . $after_title; } foreach ($posts as $post) { setup_postdata($post); add_filter('stag_showing_related_posts', '__return_true'); get_template_part('content', get_post_format()); } echo '</section>'; wp_reset_postdata(); remove_all_filters('stag_showing_related_posts'); echo $after_widget; $content = ob_get_clean(); echo $content; $this->cache_widget($args, $content); }
public static function getArticlesForReview() { $post_types = apply_filters('instant_articles_post_types', array('post')); // Cap the number of articles returned to // 100 because of performance concerns. return wp_get_recent_posts(array('numberposts' => min(self::MIN_ARTICLES, 100), 'post_type' => $post_types), 'OBJECT'); }
private function get_latest_news_stories_ps() { // Returns posts as arrays instead of get_posts' objects $recent_posts = wp_get_recent_posts(array('numberposts' => 4, 'category' => 10, 'post_status' => 'publish', 'meta_key' => '_thumbnail_id')); /* * Set incrementer */ $i = 0; $news_string = ''; foreach ($recent_posts as $post) { if ($i < 1) { $news_string .= '<a href="' . get_permalink($post['ID']) . '"> <div class="row"> <div class="columns"> <figure>' . get_the_post_thumbnail($post['ID'], 'thumbnail') . '</figure> <p>' . $post['post_title'] . '</p> </div> </div> </a>'; } else { $news_string .= '<a href = "' . get_permalink($post['ID']) . '"> <div class = "row"> <div class = "columns medium-12 large-4"> <figure>' . get_the_post_thumbnail($post['ID'], 'thumbnail') . '</figure> </div> <div class = "columns medium-12 large-8"> <p>' . $post['post_title'] . '</p> </div> </div> </a>'; } $i++; } return $news_string; }
function widget($args, $instance) { // Widget output $args = array('numberposts' => 1, 'offset' => 0, 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'post_status' => 'publish', 'suppress_filters' => true); $recent_posts = wp_get_recent_posts($args, ARRAY_A); $thumb_url = wp_get_attachment_image(get_post_thumbnail_id($recent_posts[0]['ID']), array(194, 220), true); ?> <div class="blog"> <div class="blog-image"> <img src="<?php echo get_template_directory_uri(); ?> /img/blog.png"/> </div> <div class="image"> <?php echo $thumb_url; ?> </div> <div class="content"> <?php echo $recent_posts[0]['post_excerpt']; ?> <a href="<?php echo get_permalink($recent_posts[0]['ID']); ?> ">Read more</a> </div> </div> <?php }
/** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { $recent_posts = wp_get_recent_posts(array('numberposts' => 9, 'post_type' => 'wedding_registry', 'orderby' => 'post_date', 'post_status' => 'publish')); $i = 0; echo '<div class="registry-row">'; foreach ($recent_posts as $recent) { $i++; $spouse_a = get_post_meta($recent["ID"], 'wedding_registry_field_a', true); $spouse_b = get_post_meta($recent["ID"], 'wedding_registry_field_b', true); if ($i < 9) { echo ' <div class="hidden-xs hidden-sm col-md-4 col-lg-3 reg-widg center-block"> <a href="' . get_permalink($recent['ID']) . '" title="' . $spouse_a . ' & ' . $spouse_b . '"> <div class="lgcaption caption registry-overlay text-center" style="display:none;"> <span class="icon-heart icom circled-icon"></span><p class="solid-text">' . $spouse_a . '<br/> & <br/>' . $spouse_b . '</p> </div> <div class="registry-widget-thumbnail center-block">' . get_the_post_thumbnail($recent['ID'], 'medium-cropped', array('class' => 'img-responsive center-block reg-thumb')) . '</div> </a> </div>'; } else { echo ' <div class="col-md-4 col-lg-3 reg-widg center-block last-reg"> <a href="' . get_permalink($recent['ID']) . '" title="' . $spouse_a . ' & ' . $spouse_b . '"> <div class="caption registry-overlay text-center" style="display:none;"> <span class="icon-heart icom circled-icon"></span><p class="solid-text">' . $spouse_a . '<br/> & <br/>' . $spouse_b . '</p> </div> <div class="registry-widget-thumbnail center-block last-reg">' . get_the_post_thumbnail($recent['ID'], 'medium-cropped', array('class' => 'center-block reg-thumb')) . '</div> </a> </div>'; } } echo '</div><div class="clearfix"> </div>'; }
function mtc_newsticker() { global $smof_data; $count_ticker = !empty($smof_data['news_ticker_number']) ? $smof_data['news_ticker_number'] : 5; switch ($smof_data['news_ticker_selection']) { default: case "recent_post": $args = array('numberposts' => $count_ticker); $recent_posts = wp_get_recent_posts($args); echo '<ul id="js-news" class="js-hidden">'; foreach ($recent_posts as $recent) { echo '<li class="news-item"><a href="' . get_permalink($recent["ID"]) . '" title="Look ' . esc_attr($recent["post_title"]) . '" >' . $recent["post_title"] . '</a> </li> '; } echo '</ul>'; break; case "most_commented_posts": $most_commented_posts = get_posts(array('numberposts' => $count_ticker, 'orderby' => 'comment_count', 'suppress_filters' => 0)); echo '<ul id="js-news" class="js-hidden">'; foreach ($most_commented_posts as $recent) { echo '<li class="news-item"><a href="' . get_permalink($recent->ID) . '" title="Look ' . esc_attr($recent->post_title) . '" >' . $recent->post_title . '</a> </li> '; } echo '</ul>'; break; } }
function wordlift_footer() { if ("true" !== get_option("wordlift_show_footer_bar", "true")) { return; } if (is_home()) { $args = array("numberposts" => 1, "orderby" => "post_date", "order" => "DESC", "post_type" => "post", "post_status" => "publish", "suppress_filters" => true); $recentPosts = wp_get_recent_posts($args, $output = ARRAY_A); if (0 === count($recentPosts)) { return; } $id = $recentPosts[0]["ID"]; } else { $id = get_the_ID(); } $context = WordPress_XmlApplication::getContext("wordLift"); $postEntitiesService = $context->getClass("postEntitiesService"); $entities = $postEntitiesService->get($id); $entitiesCount = count($entities); if (0 === $entitiesCount) { return; } $index = 0; $languages = @$postEntitiesService->getPostLanguages($id); echo "<div id=\"wordlift-bar\">"; echo "<ul>"; echo "<li class=\"separator\"></li>"; foreach ($entities as $key => &$entity) { $index++; $link = admin_url("admin-ajax.php?action=wordlift.gotoentity&e=" . urlencode($key)); $type = $postEntitiesService->getFirstValue($entity, "type"); $shortType = strtolower(substr($type, strrpos($type, "/") + 1)); $name = $postEntitiesService->getValueByLanguage($entity, "name", $languages); $name = htmlspecialchars($name, ENT_COMPAT, "UTF-8"); if (empty($name)) { continue; } $title = $postEntitiesService->getValueByLanguage($entity, "title", $languages); $image = $postEntitiesService->getFirstValue($entity, "image"); $description = $postEntitiesService->getValueByLanguage($entity, "description", $languages); $description = htmlspecialchars($description, ENT_COMPAT, "UTF-8"); echo "<li itemscope itemtype=\"{$type}\" class=\"entity {$shortType}\">"; echo "<a href=\"{$link}\">"; echo "<h1 itemprop=\"name\">{$name}</h1>\n"; if (!empty($title)) { echo "<h2 itemprop=\"title\">{$title}<h2>\n"; } echo "<img onerror=\"this.parentNode.removeChild(this);\" itemprop=\"image\" src=\"{$image}\" />\n"; echo "<p itemprop=\"description\">{$description}</p>\n"; echo "</a>"; echo "</li>"; echo "<li class=\"separator\"></li>"; } echo "</ul>"; echo "<div id=\"wordlift-bar-switch\">"; echo "</div>"; echo "</div>"; }
/** * Get recent posts * * Find all recent posts * * @since 1.0 * @access public * * @return ARRAY Array of post objects */ public function get_recent_posts($args = array()) { extract($args); if ($network) { $sql = "SELECT * from " . $this->db->base_prefix . "network_posts where post_type = '" . $post_type . "' ORDER BY post_date DESC LIMIT 0, " . $numberposts; return apply_filters('pf_recent_network_posts_result', $this->db->get_results($sql, OBJECT), $sql); } return apply_filters('pf_recent_posts_result', wp_get_recent_posts($args, OBJECT), $args); }
/** * Get recent posts * @example <?php recentposts(); ?> */ function recentposts() { $args = array('numberposts' => '5', 'post_status' => 'publish'); $recent_posts = wp_get_recent_posts($args); echo '<ul>'; foreach ($recent_posts as $recent) { echo '<li><a href="' . get_permalink($recent["ID"]) . '" >' . $recent["post_title"] . '</a></li> '; } echo '</ul>'; }
public function widget($args, $instance) { if (is_single()) { global $authordata, $post; echo $args['before_widget']; if (!empty($instance['title'])) { echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']; } $latest_args = array('author' => $authordata->ID, 'post__not_in' => array($post->ID), 'numberposts' => $instance['posts_no'], 'post_status' => 'publish'); if ($instance['random']) { $latest_args['orderby'] = 'rand'; } $latest_posts = wp_get_recent_posts($latest_args); if ($latest_posts) { echo '<ul>'; foreach ($latest_posts as $latest) { $post_categories = get_the_category($latest['ID']); $post_categories_output = array(); foreach ($post_categories as $category) { $category_output = '<a href="' . esc_url(get_category_link($category->cat_ID)) . '">' . esc_html($category->name) . '</a>'; array_push($post_categories_output, $category_output); } if (count($post_categories_output) > 0) { $post_categories_output = ' ' . __('in', 'qtools') . ' ' . implode(', ', $post_categories_output) . ' '; } else { $post_categories_output = ''; } echo '<li>'; if ($instance['thumbs'] && current_theme_supports('post-thumbnails')) { echo '<div class="qtools-widget-post-thumb">'; if (has_post_thumbnail($latest['ID'])) { echo '<a href="' . esc_url(get_permalink($latest['ID'])) . '">' . get_the_post_thumbnail($latest['ID'], 'thumbnail') . '</a>'; } else { echo '<a href="' . esc_url(get_permalink($latest['ID'])) . '" title="' . apply_filters('the_title_attribute', $latest['post_title']) . '"><img src="' . plugin_dir_url(dirname(__FILE__)) . 'img/no-thumb.png" alt="' . apply_filters('the_title_attribute', $latest['post_title']) . '"></a>'; } echo '</div>'; } echo '<div class="qtools-widget-post-info">'; echo '<h4 class="qtools-widget-post-title"><a href="' . esc_url(get_permalink($latest['ID'])) . '">' . apply_filters('the_title', $latest['post_title']) . '</h4></a>'; if ($instance['meta']) { echo '<div class="qtools-widget-post-meta"><a href="' . esc_url(get_author_posts_url($latest['post_author'])) . '">' . esc_html(get_the_author_meta('display_name', $latest['post_author'])) . '</a> ' . $post_categories_output . '</div>'; } echo '</div>'; echo '</li>'; } echo '</ul>'; if ($instance['posts_no'] < count_user_posts($authordata->ID)) { echo '<a href="' . esc_html(get_author_posts_url($authordata->ID)) . '" class="small-title link">' . esc_html__('More posts', 'qtools') . '</a>'; } } else { esc_html_e('No posts found!', 'qtools'); } echo $args['after_widget']; } }
function recentarticles_widget_sidebar() { // eiger Code Start echo '<li class="widget widget-recentarticlesuxebustyle"><div class="hd"><h3 class="widgettitle" style="float:left;">Recent</h3><a class="viewall mrx" style="float:right;" href="' . get_option('home') . '/archive/" title="View all posts">View all posts...</a></div><hr class="widget-hr" /><div class="bd"><ul>'; $recent_posts = wp_get_recent_posts(array('numberposts' => '3', 'post_status' => 'publish')); foreach ($recent_posts as $post) { echo '<li class="uxebu-recent-articles mbl"><a class="article-sidebar-link" href="' . get_permalink($post["ID"]) . '" title="Look ' . $post["post_title"] . '" >' . $post["post_title"] . '</a><br />' . get_the_author_meta('display_name', $post["post_author"]) . ' | ' . get_the_time('F jS', $post["ID"]) . '</li> '; } echo '</ul></div></li>'; // eiger Code Ende }
/** * How to display the widget on the screen. */ function widget($args, $instance) { extract($args); global $wp_query, $post; global $THEMEREX_CURRENT_SIDEBAR; /* Our variables from the widget settings. */ $title = apply_filters('widget_title', isset($instance['title']) ? $instance['title'] : ''); $number = isset($instance['number']) ? (int) $instance['number'] : ''; $show_date = isset($instance['show_date']) ? (int) $instance['show_date'] : 0; $show_image = isset($instance['show_image']) ? (int) $instance['show_image'] : 0; $show_author = isset($instance['show_author']) ? (int) $instance['show_author'] : 0; $show_counters = isset($instance['show_counters']) ? (int) $instance['show_counters'] : 0; $category = isset($instance['category']) ? (int) $instance['category'] : 0; $show_counters = $show_counters ? get_theme_option("blog_counters") : ''; $output = ''; if ($THEMEREX_CURRENT_SIDEBAR == 'top') { $output .= '<div class="columnsWrap"><div class="columns1_2">'; } $args = array('numberposts' => $number, 'offset' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'post', 'post_status' => current_user_can('read_private_pages') && current_user_can('read_private_posts') ? array('publish', 'private') : 'publish', 'ignore_sticky_posts' => 1, 'suppress_filters' => true); if ($category > 0) { $args['category'] = $category; } $ex = get_theme_option('exclude_cats'); if (!empty($ex)) { $args['category__not_in'] = explode(',', $ex); } $recent_posts = wp_get_recent_posts($args, OBJECT); $post_number = 0; foreach ($recent_posts as $post) { $post_number++; require themerex_get_file_dir('/templates/page-part-widgets-posts.php'); if ($THEMEREX_CURRENT_SIDEBAR == 'top' && $post_number == round($number / 2)) { $output .= ' </div><div class="columns1_2"> '; } if ($post_number >= $number) { break; } } if ($THEMEREX_CURRENT_SIDEBAR == 'top') { $output .= '</div></div>'; } if (!empty($output)) { /* Before widget (defined by themes). */ echo balanceTags($before_widget); /* Display the widget title if one was input (before and after defined by themes). */ echo balanceTags($before_title) . esc_html($title) . balanceTags($after_title); echo balanceTags($output); /* After widget (defined by themes). */ echo balanceTags($after_widget); } }
function show_recent_posts($a, $c) { extract(shortcode_atts(array('type' => 'blog'), $a)); // There is no content in this shortcode, at least there shouldnt be! $args = array('numberposts' => '5', 'post_type' => $type); $recent_posts = wp_get_recent_posts($args); foreach ($recent_posts as $recent) { echo '<h2><a href="' . get_permalink($recent["ID"]) . '" title="Look ' . esc_attr($recent["post_title"]) . '" >' . $recent["post_title"] . '</a></h2>'; echo '<p class="excerpt">' . $recent["post_excerpt"] . '<br/><span>Published: ' . $recent["post_date"] . '</span></p>'; echo '<hr/>'; } }
function cherry_generate_sitemap() { $file_dir = ABSPATH . 'sitemap.xml'; if (get_option('do_generate_sitemap') == 'off') { if (file_exists($file_dir)) { unlink($file_dir); } } else { global $site_link; $main_changefreq = 'monthly'; $main_priority = '1.0'; $site_link = get_home_url('/'); $get_recent_posts = wp_get_recent_posts(array('numberposts' => 1, 'post_type' => 'any', 'post_status' => array('publish', 'private'))); $lastmod = get_option('page_on_front') != 0 ? get_post(get_option('page_on_front'))->post_modified : $get_recent_posts[0]['post_modified']; $lastmod_xml = ''; if (null != $lastmod) { $_lastmod = explode(' ', $lastmod); $lastmod_xml = "\r\n\t\t\t<lastmod>" . $_lastmod[0] . "</lastmod>"; } $sitemap_code = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n\t<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\r\n\t\t<url>\r\n\t\t\t<loc>" . esc_url($site_link) . "</loc>" . $lastmod_xml . "\r\n\t\t\t<changefreq>" . $main_changefreq . "</changefreq>\r\n\t\t\t<priority>" . $main_priority . "</priority>\r\n\t\t</url>"; $post_types = get_post_types(array('public' => true, '_builtin' => false), 'names', 'or'); $sort_array = array('page' => '', 'post' => '', 'services' => '', 'portfolio' => '', 'slider' => '', 'team' => '', 'testi' => '', 'faq' => ''); $post_types = array_merge($sort_array, $post_types); unset($post_types['optionsframework'], $post_types['wpcf7_contact_form']); query_posts(array('post_type' => $post_types, 'posts_per_page' => '-1')); if (have_posts()) { while (have_posts()) { the_post(); if ($_POST['checked_' . get_post_type()] == "on") { $post_changefreq = isset($_POST['changefreq_' . get_post_type()]) ? "\r\n\t\t\t<changefreq>" . $_POST['changefreq_' . get_post_type()] . "</changefreq>" : ""; $post_priority = isset($_POST['priority_' . get_post_type()]) ? "\r\n\t\t\t<priority>" . $_POST['priority_' . get_post_type()] . "</priority>" : ""; $sitemap_code .= "\r\n\t\t<url>\r\n\t\t\t<loc>" . esc_url(get_permalink()) . "</loc>\r\n\t\t\t<lastmod>" . get_the_modified_date('Y-m-d') . "</lastmod>" . $post_changefreq . $post_priority . "\r\n\t\t</url>"; } } } wp_reset_query(); $sitemap_code .= "\r\n</urlset>"; $sitemap = fopen($file_dir, "w"); if (fwrite($sitemap, $sitemap_code)) { ping_search_system(); update_option('sitemap_done', 'true'); echo "Generate sitemap.xml done"; } else { update_option('sitemap_done', 'false'); echo "Generate sitemap.xml erroe"; } } exit; }
private function get_data() { $recent = array('show' => array(), 'fringe' => array()); $fringe_arguments = array('numberposts' => 1, 'post_type' => 'episode', 'post_status' => 'publish'); $recent['fringe'] = wp_get_recent_posts($fringe_arguments); $uncategorized = get_category_by_slug('uncategorized'); $fringe = get_category_by_slug('tf'); $show_arguments = array('numberposts' => 1, 'post_type' => 'episode', 'post_status' => 'publish', 'post__not_in' => array($recent['fringe'][0]['ID'])); if ($uncategorized || $fringe) { $arguments['category__not_in'] = array($uncategorized->term_id, $fringe->term_id); //var_dump($arguments); } $recent['show'] = wp_get_recent_posts($show_arguments); return $recent; }
/** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { $recent_posts = wp_get_recent_posts(array('numberposts' => 9, 'post_type' => 'wedding_registry', 'orderby' => 'post_date', 'post_status' => 'publish')); $i = 0; echo ' <div class=" registry-row-mobile"> <div id="wedding-reg-mobile" class="col-xs-12 col-sm-12 carousel slide" data-ride="carousel"> <div class="carousel-inner" role="listbox">'; foreach ($recent_posts as $recent) { $spouse_a = get_post_meta($recent["ID"], 'wedding_registry_field_a', true); $spouse_b = get_post_meta($recent["ID"], 'wedding_registry_field_b', true); $i++; if ($i == 1) { echo ' <div class="item active reg-slide center-block text-center"> <a href="' . get_permalink($recent['ID']) . '" title="' . $spouse_a . ' & ' . $spouse_b . '"> ' . get_the_post_thumbnail($recent['ID'], 'medium', array('class' => 'center-block text-center')) . ' <div class="mobile-caption text-center"></div> <p class="solid-text">' . $spouse_a . '<br/> & <br/>' . $spouse_b . '</p> </a> </div>'; } else { echo ' <div class="item text-center center-block reg-slide"> <a href="' . get_permalink($recent['ID']) . '" title="' . $spouse_a . ' & ' . $spouse_b . '"> <div>' . get_the_post_thumbnail($recent['ID'], 'medium-cropped') . '</div> <div class="mobile-caption text-center"></div> <p class="solid-text">' . $spouse_a . '<br/> & <br/>' . $spouse_b . '</p> </a> </div>'; } $spouse_a = get_post_meta($recent["ID"], 'wedding_registry_field_a', true); $spouse_b = get_post_meta($recent["ID"], 'wedding_registry_field_b', true); $img_src = wp_get_attachment_image_src(get_post_thumbnail_id($recent['ID']), 'medium-cropped'); $thumb_url = $img_src[0]; } echo '</div> <a class="left carousel-control" href="#wedding-reg-mobile" role="button" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="right carousel-control" href="#wedding-reg-mobile" role="button" data-slide="next"> <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div></div>'; }
function gen_meta_desc() { global $post; if (!is_home()) { return; } $args = array('numberposts' => '3'); $recent_posts = wp_get_recent_posts($args); $meta = ''; foreach ($recent_posts as $recent) { $meta .= $recent["post_title"] . ' - '; } $meta = substr($meta, 0, -1); echo "<!-- This site is optimized with WP SEO Auto Generating Metatag Description - http://www.indowp.com/plugins/wp-seo-auto-generating-metatag-description/ -->\n"; echo "<meta name='description' content='{$meta}' />\n"; echo "<!-- / IndoWP WordPress SEO plugin. -->"; }
/** * Fetch recent posts data from DB (cache it on first widget instance) and then * fetch the data from cache for all other widget instances. * * @param string $cache_name * @param int $number_of_posts */ public static function get_cached_data($cache_name, $number_of_posts) { // Get/set cache data just once for multiple widgets $recent_posts_data = wp_cache_get($cache_name); if (false === $recent_posts_data) { $recent_posts_original_args = array('numberposts' => $number_of_posts, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'post', 'post_status' => 'publish'); // Check if WPML plugin is active and set the suppress_filter parameter to false, // this solves the issue of multiple translations of the same blog post appear on single language page. if (self::is_wpml_plugin_activated()) { $recent_posts_original_args['suppress_filters'] = false; } $recent_posts_original = wp_get_recent_posts($recent_posts_original_args); // Prepare the data that we need for display $recent_posts_data = array(); foreach ($recent_posts_original as $key => $post) { $recent_posts_data[$key]['id'] = $post['ID']; $recent_posts_data[$key]['date'] = get_the_date(apply_filters('pw/widget_latest_news_short_date_format', 'M j'), $post['ID']); $split_date = explode(' ', $recent_posts_data[$key]['date']); $recent_posts_data[$key]['day'] = $split_date[1]; $recent_posts_data[$key]['month'] = $split_date[0]; $recent_posts_data[$key]['full_date'] = get_the_date(get_option('date_format'), $post['ID']); $recent_posts_data[$key]['full_date_time'] = get_the_date('c', $post['ID']); $attachment_image_id = get_post_thumbnail_id($post['ID']); $attachment_image_data = wp_get_attachment_image_src($attachment_image_id, 'pw-latest-news'); // get featured image data if a featured image is set if (!empty($attachment_image_data)) { $recent_posts_data[$key]['image_url'] = $attachment_image_data[0]; $recent_posts_data[$key]['image_width'] = $attachment_image_data[1]; $recent_posts_data[$key]['image_height'] = $attachment_image_data[2]; $recent_posts_data[$key]['srcset'] = self::get_attachment_image_srcs($attachment_image_id, array('pw-latest-news', 'full')); } $recent_posts_data[$key]['link'] = get_permalink($post['ID']); $recent_posts_data[$key]['title'] = $post['post_title']; $recent_posts_data[$key]['author'] = get_the_author_meta('display_name', $post['post_author']); $recent_posts_data[$key]['excerpt'] = self::get_post_excerpt($post['post_excerpt'], $post['post_content']); } wp_cache_set($cache_name, $recent_posts_data); } return $recent_posts_data; }
function show_recent_posts($a, $c) { extract(shortcode_atts(array('type' => 'blog'), $a)); // There is no content in this shortcode, at least there shouldnt be! $args = array('post_type' => $type); $icon_class = $type == 'blog' ? 'icon-bookmark-empty' : 'icon-folder-close-alt'; $recent_posts = wp_get_recent_posts($args); $str = ''; foreach ($recent_posts as $recent) { switch ($type) { case 'blog': $str .= '<article class="ribbon ' . $type . '"><h2><i class="' . $icon_class . '"></i> <a href="' . get_permalink($recent["ID"]) . '" title="Look ' . esc_attr($recent["post_title"]) . '" >' . $recent["post_title"] . '</a></h2><p class="excerpt">' . $recent["post_excerpt"] . '<br/><span class="muted small">Published: ' . $recent["post_date"] . '</span></p><a class="btn btn-small btn-info pull-right blog-link" href="' . get_permalink($recent["ID"]) . '" title="' . esc_attr($recent["post_title"]) . '">Read more <i class="icon-circle-arrow-right"></i></a><div class="clearfix"></div></article>'; break; case 'portfolio': $str .= '<article class="' . $type . ' pf-bg-' . $recent["ID"] . '"><h2>' . $recent["post_title"] . '</h2><p class="excerpt">' . $recent["post_excerpt"] . '</p><a class="call-to-action" href="' . get_permalink($recent["ID"]) . '" title="' . esc_attr($recent["post_title"]) . '">Read more <i class="icon-circle-arrow-right"></i></a></article>'; break; default: break; } } return $str; }
function generate_sitemap() { global $site_link; $main_changefreq = 'monthly'; $main_priority = '1,0'; $site_link = get_home_url() . '/'; $get_recent_posts = wp_get_recent_posts(array('numberposts' => 1, 'post_type' => 'any', 'post_status' => array('publish', 'private'))); $lastmod = get_option('page_on_front') != 0 ? get_post(get_option('page_on_front'))->post_modified : $get_recent_posts[0]['post_modified']; $lastmod_xml = $lastmod != null ? "\r\n\t\t\t<lastmod>" . $lastmod . "</lastmod>" : ''; $sitemap_code = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n\t<urlset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\" xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\r\n\t\t<url>\r\n\t\t\t<loc>" . $site_link . "</loc>" . $lastmod_xml . "\r\n\t\t\t<changefreq>" . $main_changefreq . "</changefreq>\r\n\t\t\t<priority>" . $main_priority . "</priority>\r\n\t\t</url>"; $args = array('public' => true, '_builtin' => false); $post_types = get_post_types($args, 'names', 'or'); $sort_array = array('page' => '', 'post' => '', 'services' => '', 'portfolio' => '', 'slider' => '', 'team' => '', 'testi' => '', 'faq' => ''); $post_types = array_merge($sort_array, $post_types); unset($post_types['optionsframework'], $post_types['wpcf7_contact_form']); query_posts(array('post_type' => $post_types, 'posts_per_page' => '-1')); if (have_posts()) { while (have_posts()) { the_post(); if (isset($_POST['checked_' . get_post_type()])) { $post_changefreq = isset($_POST['changefreq_' . get_post_type()]) ? "\r\n\t\t\t<changefreq>" . $_POST['changefreq_' . get_post_type()] . "</changefreq>" : ""; $post_priority = isset($_POST['priority_' . get_post_type()]) ? "\r\n\t\t\t<priority>" . $_POST['priority_' . get_post_type()] . "</priority>" : ""; $sitemap_code .= "\r\n\t\t<url>\r\n\t\t\t<loc>" . get_permalink() . "</loc>\r\n\t\t\t<lastmod>" . get_the_modified_date('Y-m-d') . "</lastmod>" . $post_changefreq . $post_priority . "\r\n\t\t</url>"; } } } wp_reset_query(); $sitemap_code .= "\r\n</urlset>"; $sitemap = fopen(ABSPATH . "sitemap.xml", "w"); if (fwrite($sitemap, $sitemap_code)) { ping_search_system(); update_option('sitemap_done', 'true'); echo "Generate sitemap.xml done"; } else { update_option('sitemap_done', 'false'); echo "Generate sitemap.xml erroe"; } exit; }
/** * Get a collection of items * * @param \WP_REST_Request $request Full data about the request. * @return \WP_Error|\WP_REST_Response */ public function get_items($request) { $data = array('posts' => array(), 'template' => '', 'siteTitle' => ''); $posts = array(); $path = $request['path']; $post_id = url_to_postid($path); if (is_numeric($post_id) && (int) $post_id > 0) { //A single post/page $posts = array(get_post($post_id)); $data['template'] = 'templates/singular'; $data['siteTitle'] = $posts[0]->post_title . ' | ' . get_bloginfo('name'); } elseif (rtrim(get_home_url(), '/') == rtrim(get_home_url(null, $path), '/')) { //Front page if (get_option('page_on_front')) { //Static $posts = array(get_post(get_option('page_on_front'))); $data['template'] = 'templates/singular'; } else { //Latest posts $posts = wp_get_recent_posts(apply_filters('ngp_homepage_recent_posts_args', array())); $data['template'] = 'templates/archive'; } $data['siteTitle'] = get_bloginfo('name') . ' | ' . get_bloginfo('description'); } else { //Path is not for a single post, may be an archive url, a search url or even a non-valid 404 url } foreach ($posts as $post) { if (is_array($post)) { $post = get_post($post['ID']); } if (!$this->check_read_permission($post)) { continue; } $item_data = $this->prepare_item_for_response($post, $request); $data['posts'][] = $this->prepare_response_for_collection($item_data); } $response = rest_ensure_response($data); return $response; }
private function get_latest_news_stories_ps() { // Returns posts as arrays instead of get_posts' objects $recent_posts = wp_get_recent_posts(array('numberposts' => 3, 'category' => 59, 'post_status' => 'publish', 'meta_key' => '_thumbnail_id')); /* * Set incrementer */ $i = 0; $news_string = ''; foreach ($recent_posts as $post) { if ($i < 1) { $news_string .= '<a href="' . get_permalink($post['ID']) . '"> <div class = "row collapse"> <div class = "columns small-4 medium-12"> <figure>' . get_the_post_thumbnail($post['ID'], 'thumbnail') . '</figure> </div> <div class = "columns small-12 small-centered"> <p><span class="anchortext">' . $post['post_title'] . '</span></p> </div> </div> </a>'; } else { $news_string .= '<a href = "' . get_permalink($post['ID']) . '"> <div class = "row collapse"> <div class = "columns small-4 medium-12 large-5"> <figure>' . get_the_post_thumbnail($post['ID'], 'thumbnail') . '</figure> </div> <div class = "columns small-12 small-centered medium-12 medium-uncentered large-7 large-push-1"> <p><span class="anchortext">' . $post['post_title'] . '</span></p> </div> </div> </a>'; } $i++; } return $news_string; }
function tfuse_shortcode_latest_post($atts, $content = null) { $out = ''; $recent_post = wp_get_recent_posts(array('numberposts' => 1)); if (!empty($recent_post)) { foreach ($recent_post as $post) { $image = wp_get_attachment_url(get_post_thumbnail_id($post['ID'], 'post-thumbnails')); $get_image = new TF_GET_IMAGE(); $img = $get_image->properties(array('class' => '', 'alt' => get_the_title($post['ID'])))->width(210)->height(82)->src($image)->resize(true)->get_img(); $current_post = get_post($post['ID']); $user_data = get_user_by('id', $current_post->post_author); $out .= '<article class="post"> <h2 class="entry-title"><a href="' . get_permalink($post['ID']) . '">' . get_the_title($post['ID']) . '</a></h2> <div class="entry-meta"> <time class="entry-date" datetime="">' . get_the_time(get_option('date_format'), $post['ID']) . '</time> <span class="author"> ' . __('by', 'tfuse') . ' <a href="' . get_author_posts_url($current_post->post_author, $user_data->data->user_nicename) . '">' . $user_data->data->user_nicename . '</a></span> </div> <span class="post-thumbnail">'; if (!empty($image)) { $out .= $img; } $out .= '</span> <div class="entry-content"><p>'; if (tfuse_options('post_content') == 'content') { $out .= $current_post->post_content; } else { $out .= !empty($current_post->post_excerpt) ? $current_post->post_excerpt : strip_tags(tfuse_shorten_string(apply_filters('the_content', $current_post->post_content), 150)); } $out .= '</p></div> <footer class="entry-meta"> <a href="' . get_permalink($post['ID']) . '" class="btn btn-yellow"><span>' . __('find out more', 'tfuse') . '</span></a> </footer> </article>'; } } return $out; }
function get_cached_data($cache_name) { // Get/set cache data just once for multiple widgets $recent_posts_data = wp_cache_get($cache_name); if (false === $recent_posts_data) { $recent_posts_original_args = array('numberposts' => self::MAX_POST_NUMBER, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'post', 'post_status' => 'publish'); $recent_posts_original = wp_get_recent_posts($recent_posts_original_args); // Prepare the data that we need for display $recent_posts_data = array(); foreach ($recent_posts_original as $key => $post) { $recent_posts_data[$key]['id'] = $post['ID']; $recent_posts_data[$key]['date'] = get_the_date('M j', $post['ID']); $split_date = explode(' ', $recent_posts_data[$key]['date']); $recent_posts_data[$key]['day'] = $split_date[1]; $recent_posts_data[$key]['month'] = $split_date[0]; $recent_posts_data[$key]['image'] = get_the_post_thumbnail($post['ID']); $recent_posts_data[$key]['link'] = get_permalink($post['ID']); $recent_posts_data[$key]['title'] = $post['post_title']; $recent_posts_data[$key]['author'] = get_the_author_meta('display_name', $post['post_author']); } wp_cache_set($cache_name, $recent_posts_data); } return $recent_posts_data; }
function tfuse_shortcode_latest_entry($atts, $content = null) { $out = ''; $recent_post = wp_get_recent_posts(array('numberposts' => 1)); if (!empty($recent_post)) { foreach ($recent_post as $post) { $image = wp_get_attachment_url(get_post_thumbnail_id($post['ID'], 'post-thumbnails')); $get_image = new TF_GET_IMAGE(); $img = $get_image->properties(array('class' => '', 'alt' => get_the_title($post['ID'])))->width(210)->height(210)->src($image)->resize(true)->get_img(); $current_post = get_post($post['ID']); $out .= ' <div class="home-post"> <div class="inner"> <div class="entry-aside"> <header class="entry-header"> <div class="entry-meta"> <div class="cat-links"> <a href="' . get_permalink($post['ID']) . '">' . __('Latest blog entry', 'tfuse') . '</a> </div> <time class="entry-date"><i class="icon-circle"></i>' . get_the_time(get_option('date_format'), $post['ID']) . '</time> <h1 class="entry-title"> <a href="' . get_permalink($post['ID']) . '">' . get_the_title($post['ID']) . '</a> </h1> </div> </header>'; if (!empty($image)) { $out .= '<a class="post-thumbnail" href="' . get_permalink($post['ID']) . '">' . $img . '</a>'; } $out .= '<div class="entry-content"> <p>'; if (tfuse_options('post_content') == 'content') { $out .= $current_post->post_content; } else { $out .= !empty($current_post->post_excerpt) ? $current_post->post_excerpt : strip_tags(tfuse_shorten_string(apply_filters('the_content', $current_post->post_content), 150)); } $out .= '</p> </div> <footer class="entry-meta"> <a href="' . get_permalink($post['ID']) . '" class="btn btn-transparent btn-lets-talk"><span>' . __('Read article', 'tfuse') . ' <i class="icon-chevron-right align-right-icon"></i></span></a> </footer> </div> </div> </div>'; } } return $out; }
function recent_posts() { ?> <ul> <?php $args = array('numberposts' => '5'); $recent_posts = wp_get_recent_posts($args); foreach ($recent_posts as $recent) { echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look ' . esc_attr($recent["post_title"]) . '" >' . $recent["post_title"] . '</a> </li> '; } ?> </ul> <?php }