function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); $post_number = $instance['post_number']; echo $before_widget; echo $before_title . $title . $after_title; $random_query = new WP_Query('posts_per_page=' . $post_number . '&orderby=rand'); if ($random_query->have_posts()) { echo "<ol>"; while ($random_query->have_posts()) { $random_query->the_post(); ?> <li><a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "><?php the_title(); ?> </a></li> <?php } echo "</ol>"; } echo $after_widget; }
function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); $number = $instance['number']; echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } echo '<ul>'; query_posts(array('post_type' => 'portfolio', 'showposts' => $number)); if (have_posts()) { while (have_posts()) { the_post(); ?> <li> <a href="<?php the_permalink(); ?> "> <?php the_post_thumbnail('portfolio'); ?> </a> </li> <?php } } wp_reset_query(); echo '</ul>'; echo $after_widget; }
function my_facebook_tags() { if (is_single()) { ?> <meta property="og:title" content="<?php the_title(); ?> " /> <meta property="og:site_name" content="<?php bloginfo('name'); ?> " /> <meta property="og:url" content="<?php the_permalink(); ?> " /> <meta property="og:description" content="<?php the_excerpt(); ?> " /> <meta property="og:type" content="article" /> <?php if (has_post_thumbnail()) { $image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large'); ?> <meta property="og:image" content="<?php echo $image[0]; ?> " /> <?php } } }
function tpp_posts_widget() { $tpp_posts_query = new WP_Query(array('posts_per_page' => 10, 'orderby' => 'comment_count', 'order' => 'DESC', 'post__in' => get_option('sticky_posts'))); ?> <h3><?php _e('Posts on this page:'); ?> </h3> <?php if ($tpp_posts_query->have_posts()) { while ($tpp_posts_query->have_posts()) { $tpp_posts_query->the_post(); ?> <a href="<?php echo the_permalink(); ?> " title="<?php echo the_title(); ?> "><?php echo the_title(); ?> </a> (<?php echo comments_number(); ?> ) <br /> <?php } } ?> <?php }
function widget($args, $instance) { global $post, $wp_query; Protect(); extract($args, EXTR_SKIP); $post_query = 'showposts=1&cat=' . $instance['thecat']; $posts =& query_posts($post_query); if (have_posts()) { while (have_posts()) { the_post(); echo $before_widget; $title = empty($instance['title']) ? 'Latest Excerpt' : apply_filters('widget_title', $instance['title']); if (!empty($title)) { echo $before_title . $title . $after_title; } ?> <ul> <li><a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a></li> <li><?php the_excerpt(); ?> </li> </ul> <?php echo $after_widget; } } UnProtect(); }
function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? 'From The Blog' : $instance['title']); $posts_number = empty($instance['posts_number']) ? '' : $instance['posts_number']; $blog_category = empty($instance['blog_category']) ? '' : $instance['blog_category']; echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } ?> <ul> <?php query_posts("showposts=" . $posts_number . "&cat=" . $blog_category); if (have_posts()) { while (have_posts()) { the_post(); ?> <li><a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a></li> <?php } } wp_reset_query(); ?> </ul> <!-- end ul.nav --> <?php echo $after_widget; }
function widget($args, $instance) { // prints the widget extract($args, EXTR_SKIP); echo $before_widget; $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']); $category = empty($instance['category']) ? '' : apply_filters('widget_category', $instance['category']); $post_type = empty($instance['post_type']) ? 'post' : apply_filters('widget_post_type', $instance['post_type']); $post_number = empty($instance['post_number']) ? '5' : apply_filters('widget_post_number', $instance['post_number']); ?> <div class="featured_video"> <?php if ($title) { ?> <h3 class="clearfix"> <?php echo $title; ?> </h3><?php } ?> <?php global $post; $args = ''; if ($category) { $args .= '&category=' . $category; } $latest_menus = get_posts('numberposts=' . $post_number . $args . '&post_type=' . $post_type); foreach ($latest_menus as $post) { setup_postdata($post); if (get_post_meta($post->ID, 'video', true) || get_post_meta($post->ID, 'Video', true) || get_post_meta($post->ID, 'VIDEO', true)) { if (get_post_meta($post->ID, 'video', true)) { $video = get_post_meta($post->ID, 'video', true); } elseif (get_post_meta($post->ID, 'Video', true)) { $video = get_post_meta($post->ID, 'Video', true); } elseif (get_post_meta($post->ID, 'VIDEO', true)) { $video = get_post_meta($post->ID, 'VIDEO', true); } ?> <div class="video"> <?php echo $video; ?> <h4><a class="widget-title" href="<?php the_permalink(); ?> "><?php the_title(); ?> </a></h4> </div> <?php } ?> <?php } ?> </div> <?php echo $after_widget; }
function widget($args, $instance) { extract($args); @($title = $instance['title'] ? $instance['title'] : '最热文章'); @($num = $instance['num'] ? $instance['num'] : 5); echo $before_widget; ?> <div class="panel panel-zan hidden-xs"> <div class="panel-heading"><?php echo $title; ?> </div> <div class="panel-body"> <ul class="list-group"> <?php // 设置全局变量,实现post整体赋值 global $post; $posts = zan_get_hotest_posts($num); foreach ($posts as $post) { setup_postdata($post); ?> <li class="zan-list clearfix"> <figure class="thumbnail zan-thumb"> <?php the_post_thumbnail(array(75, 75)); ?> </figure> <a href="<?php the_permalink(); ?> "> <h5><?php the_title(); ?> </h5> </a> <div class="sidebar-info"> <span><i class="fa fa-calendar"></i> <?php the_time('m月j日, Y'); ?> </span> <span><i class="fa fa-comment"></i> <a href="<?php the_permalink(); ?> #comments"><?php comments_number('0', '1', '%'); ?> </a></span> </div> </li> <?php } wp_reset_postdata(); ?> </ul> </div> </div> <?php echo $after_widget; }
/** @see WP_Widget::widget */ function widget($args, $instance) { extract($args); echo $before_widget; $a = array("orderby" => "id", "order" => "asc"); $categories = get_categories($a); foreach ($categories as $category) { echo $before_title; // var_dump($category); echo "<h2>" . $category->name . "</h2><ul>"; global $post; $args = array('category' => $category->term_id, "numberposts" => -1, "orderby" => "title", "order" => "ASC"); $myposts = get_posts($args); foreach ($myposts as $post) { setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a></li><?php } echo "</ul>"; wp_reset_query(); echo $after_title; } echo $after_widget; }
function widget($args, $instance) { extract($args); $countt = apply_filters('widget_guanzhu_sina', empty($instance['countt']) ? __('nothing') : $instance['countt']); //小工具前台标题 echo $before_widget; echo '<i class="iconfont iconfont-siadebar"></i> <h3 class="widget-title"> 热门文章 </h3> <div class="widget-main widget-main-hot"> <ul>'; if (intval($countt) <= 10) { $popular = new WP_Query('orderby=comment_count&posts_per_page=' . $countt); $count_di = 1; while ($popular->have_posts()) { $popular->the_post(); echo '<li><span>' . $count_di . '</span>' . '<a href="'; the_permalink(); echo '">'; the_title(); echo '</a></li>'; $count_di++; } } echo '</ul>'; echo '</div>'; echo $after_widget; }
function categori_news(){ query_posts('cat=9&showposts=10&posts_per_page=3'); while (have_posts()) : the_post(); /*Dima insert*/the_excerpt(); ?> <div class="content-box"> <div class="bgr01"><div class="bgr02"><div class="bgr03"> <div <?php post_class() ?> id="post-<?php the_ID(); ?>" style=" float:none; "> <div class="title"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <div class="date_all"> <?php the_time('l, j ?F, Y') ?> </div> <div class="post"> Написал <?php the_author_link() ?> <?php the_time('g:i A') ?> </div> </div> <div class="content_box"> <?php the_content('Читать всё'); ?> </div> <div class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?></div> <div class="comments"><?php comments_popup_link('0 комментарии', 'комментарии', '% комментарии '); ?></div> <div class="link-edit"><?php edit_post_link('Edit', ''); ?></div> </div> </div></div></div> </div> <?php endwhile;}
function load_5speed_archive() { echo "<h3 class=\"list-title\">My list of reasons why I drive a manual transmission car:</h3>"; echo "<div class=\"5speed\">"; while (have_posts()) { the_post(); ?> <li> <h3 style="margin-bottom:0px;"># <a href="<?php the_permalink(); ?> " rel="bookmark" title="Reason <?php the_title_attribute(); ?> "><?php the_title(); ?> </a></h3> <?php the_content(); ?> </li> <?php } echo "</div>"; }
public function widget($args, $instance) { ?> <?php echo $args['before_widget']; ?> <?php echo $args['before_title']; echo $instance['title']; echo $args['after_title']; ?> <div class="list-group"> <?php $arg = array('posts_per_page' => 5, 'post_type' => 'post', 'orderby' => 'date', 'order' => 'DESC'); $newposts = new WP_Query($arg); while ($newposts->have_posts()) { $newposts->the_post(); ?> <a class="list-group-item" href="<?php the_permalink(); ?> "><?php the_title(); ?> </a> <?php } wp_reset_postdata(); ?> </div> <?php echo $args['after_widget']; ?> <?php }
function woo_widget_tabs_latest($posts = 5, $size = 45) { global $post; $latest = get_posts(array('suppress_filters' => false, 'ignore_sticky_posts' => 1, 'orderby' => 'post_date', 'order' => 'desc', 'numberposts' => $posts)); foreach ($latest as $post) { setup_postdata($post); ?> <li> <?php if ($size != 0) { woo_image('height=' . $size . '&width=' . $size . '&class=thumbnail&single=true'); } ?> <a title="<?php the_title_attribute(); ?> " href="<?php the_permalink(); ?> "><?php the_title(); ?> </a> <span class="meta"><?php the_time(get_option('date_format')); ?> </span> <div class="fix"></div> </li> <?php } wp_reset_postdata(); }
function grid_archive_theme($post) { ?> <div class="archive-listing classic-grid"> <a href="<?php the_permalink(); ?> "> <div style="background-image:url('<?php if (wp_get_attachment_url(get_post_thumbnail_id($post->ID))) { $url = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); } else { $url = default_product_thumbnail_url(); } echo $url; ?> ');" class="classic-grid-element"></div> <div class="product-name"><?php the_title(); ?> </div> <?php do_action('archive_price', $post); ?> </a> </div> <?php }
/** @see WP_Widget::widget */ function widget($args, $instance) { $cache = wp_cache_get('widget_recent_products', 'widget'); if ( !is_array($cache) ) $cache = array(); if ( isset($cache[$args['widget_id']]) ) { echo $cache[$args['widget_id']]; return; } ob_start(); extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('New Products', 'jigoshop') : $instance['title'], $instance, $this->id_base); if ( !$number = (int) $instance['number'] ) $number = 10; else if ( $number < 1 ) $number = 1; else if ( $number > 15 ) $number = 15; $show_variations = $instance['show_variations'] ? '1' : '0'; $args = array('showposts' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'post_type' => 'product'); if($show_variations=='0'){ $args['meta_query'] = array( array( 'key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN' ) ); $args['parent'] = '0'; } $r = new WP_Query($args); if ($r->have_posts()) : ?> <?php echo $before_widget; ?> <?php if ( $title ) echo $before_title . $title . $after_title; ?> <ul class="product_list_widget"> <?php while ($r->have_posts()) : $r->the_post(); $_product = &new jigoshop_product(get_the_ID()); ?> <li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"> <?php if (has_post_thumbnail()) the_post_thumbnail('shop_tiny'); else echo '<img src="'.jigoshop::plugin_url().'/assets/images/placeholder.png" alt="Placeholder" width="'.jigoshop::get_var('shop_tiny_w').'px" height="'.jigoshop::get_var('shop_tiny_h').'px" />'; ?> <?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a> <?php echo $_product->get_price_html(); ?></li> <?php endwhile; ?> </ul> <?php echo $after_widget; ?> <?php // Reset the global $the_post as this query will have stomped on it //wp_reset_postdata(); endif; if (isset($args['widget_id']) && isset($cache[$args['widget_id']])) $cache[$args['widget_id']] = ob_get_flush(); wp_cache_set('widget_recent_products', $cache, 'widget'); }
function mdwpbp_related_posts() { global $post; $tags = wp_get_post_tags($post->ID); if ($tags) { foreach ($tags as $tag) { $tag_arr = $tag->slug . ','; } $args = array('tag' => $tag_arr, 'numberposts' => 5, 'post__not_in' => array($post->ID)); $related_posts = get_posts($args); if ($related_posts) { echo '<p class="related-posts-header">Related Posts</p><ul id="mdwpbp-related-posts">'; foreach ($related_posts as $post) { setup_postdata($post); echo '<li class="related-post"><a href="'; the_permalink(); echo '">'; the_title(); echo '</a></li>'; } echo '</ul>'; } } // if ($tags) wp_reset_postdata(); }
function stars_teams($gender, $season) { $args = array('season' => $season, 'gender' => $gender, 'post_type' => 'team', 'posts_per_page' => -1); $teams = new WP_Query($args); ?> <h3><?php echo ucfirst($gender) . ' ' . $season; ?> Teams</h3> <?php if ($teams->have_posts()) { while ($teams->have_posts()) { $teams->the_post(); ?> <p class="team-list-item"><a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a></p> <?php } } ?> <?php }
function post_excerpts_here() { //posts with date, author, time, content excerpts, and title.. if (have_posts()) { while (have_posts()) { echo '<div class="excerpt-div">'; the_post(); echo '<h2 class="post-title"><a href="'; the_permalink(); echo '" title="'; the_title(); echo '">'; the_title(); echo '</a></h2>'; echo '<h4 class="post-info">'; echo 'Created on '; the_date(); echo ' at '; the_time(); echo ' by '; the_author_meta(first_name); echo '.</h4>'; echo '<p class="post-excerpt">'; the_excerpt(); echo '</p>'; echo '</div>'; } // end while } // end if }
function tpp_posts_widget() { ?> <h3>Posts on this page:</h3> <?php if (have_posts()) { while (have_posts()) { the_post(); ?> <div> <a href="<?php echo the_permalink(); ?> " title="<?php echo the_title(); ?> "><?php echo the_title(); ?> </a> (<?php echo comments_number(); ?> ) </div> <?php } } ?> <?php }
function get_news_ticker($tickercat, $count) { global $post; $args = array('posts_per_page' => $count, 'cat' => $tickercat); $loop = new WP_Query($args); echo "<ul>"; while ($loop->have_posts()) { $loop->the_post(); ?> <li class="ticker-item"> <b><?php the_time('M j, Y'); ?> </b> - <a href="<?php the_permalink(); ?> "> <?php the_title(); ?> </a> </li> <?php } echo "</ul>"; wp_reset_postdata(); }
function get_the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') { $content = get_the_content($more_link_text, $stripteaser, $more_file); $content = apply_filters('get_the_content', $content); $content = str_replace(']]>', ']]>', $content); $content = strip_tags($content); if (strlen($_GET['p']) > 0) { echo $content; } else { if (strlen($content) > $max_char && ($espacio = strpos($content, " ", $max_char))) { $content = substr($content, 0, $espacio); $content = $content; echo $content; //echo "<a href='"; //the_permalink(); echo "..."; echo "<br>"; echo "<div class="; echo "'read-more'>"; echo "<a href='"; the_permalink(); echo "'>" . $more_link_text . "</a></div></p>"; } else { echo $content; } } }
function wpbss_main_menu_fallback() { global $post; $args = array('post_type' => 'page', 'post_status' => 'publish', 'hierarchical' => 0); $pages = get_pages($args); //var_dump($pages); ?> <ul class="nav navbar-nav"> <?php foreach ($pages as $post) { setup_postdata($post); ?> <li> <a href="<?php the_permalink(); ?> "><?php echo $post->post_title; ?> </a> </li> <?php } wp_reset_postdata(); ?> </ul> <?php }
function tpp_posts_widget() { $tpp_posts_query = new WP_Query(); $tpp_posts_query->get_posts(); ?> <h3>Posts on this page:</h3> <?php if ($tpp_posts_query->have_posts()) { while ($tpp_posts_query->have_posts()) { $tpp_posts_query->the_post(); ?> <a href="<?php echo the_permalink(); ?> " title="<?php echo the_title(); ?> "><?php echo the_title(); ?> </a> (<?php echo comments_number(); ?> ) <?php } } ?> <?php }
/** * Display an optional post thumbnail. * * Wraps the post thumbnail in an anchor element on index views, or a div * element when on single views. * * @since Twenty Fifteen 1.0 */ function launchpad_post_thumbnail() { if (post_password_required() || is_attachment() || !has_post_thumbnail()) { return; } if (is_singular()) { ?> <div class="post-thumbnail"> <?php the_post_thumbnail(); ?> </div><!-- .post-thumbnail --> <?php } else { ?> <a class="post-thumbnail" href="<?php the_permalink(); ?> " aria-hidden="true"> <?php the_post_thumbnail('post-thumbnail', array('alt' => get_the_title())); ?> </a> <?php } // End is_singular() }
/** * kool_preview_boxes shows the next set of posts. It shows as many boxes as * you show posts on your blog page. This works best when there is an even * number of posts displayed (2,4,6,8,10) but it can work with an odd number * if alignment is set or if the width of boxes is set to 100% which would allow * for a column effct. * * To use kool_preview simply add the function call in your theme's index after * the content is displayed. I could technically go before as well. */ function kool_preview_boxes() { global $post; if (is_paged()) { $target_page = get_query_var('paged') + 1; } else { $target_page = 2; } $args = array('paged' => $target_page, 'orderby' => 'post_date', 'post_type' => 'post', 'post_status' => 'publish'); $k_posts = new WP_Query($args); if ($k_posts and $k_posts->have_posts()) { while ($k_posts->have_posts()) { $k_posts->the_post(); $thumb_query = array('numberposts' => 1, 'post_type' => 'attachment', 'post_parent' => $post->ID); echo '<div class="preview_box" >'; $attachment = get_posts($thumb_query); foreach ($attachment as $attach) { if ($attach) { $img = wp_get_attachment_image_src($attach->ID, $size = 'thumbnail', $icon = true); echo "<img class='preview_thumb' src='{$img['0']}' >"; } } echo '<a rel="bookmark" href='; the_permalink(); echo '>'; echo the_title() . '</a><br>'; the_excerpt(); echo "</div>"; } } }
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; }
function most_viewed() { ob_start(); $posts = wmp_get_popular(array('limit' => 4, 'post_type' => 'paper', 'range' => 'all_time')); global $post; if (count($posts) > 0) { foreach ($posts as $post) { setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?> "> <?php if (get_field('short_title')) { the_field('short_title'); } else { the_title(); } ?> </a></li> <?php } } wp_reset_query(); $contents = ob_get_contents(); ob_end_clean(); return $contents; }
function facebook_login_shortcode($atts, $content = null) { extract(shortcode_atts(array('text' => 'Login / Register with Facebook', 'size' => 'medium'), $atts)); ob_start(); global $post; ?> <a href="<?php echo wp_login_url(); ?> ?loginFacebook=1&redirect=<?php echo the_permalink(); ?> " class="button <?php echo $size; ?> facebook-button" onclick="window.location = '<?php echo wp_login_url(); ?> ?loginFacebook=1&redirect='+window.location.href; return false;"><i class="icon-facebook"></i><?php echo $text; ?> </a><?php $content = ob_get_contents(); ob_end_clean(); return $content; }
function rmcc_report_listing_shortcode1($atts) { global $wp_query, $cur_post_id; ob_start(); $args = array('post_type' => 'wp_research', 'posts_per_page' => 3, 'order' => 'DESC', 'orderby' => 'post_date', 'post__not_in' => array($cur_post_id)); query_posts($args); if (have_posts()) { ?> <ul> <li style="color:#d51067">Other CFE reports: </li> <?php while (have_posts()) { the_post(); ?> <li class="menu-item-type-wp_research"><a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a></li> <?php } wp_reset_query(); ?> </ul> <?php $myvariable = ob_get_clean(); return $myvariable; } }