Tag Info

Hot answers tagged

5

Let's see if I can confuse myself. If either of your two OR conditions is true the code executes. is_home and is_front_page can return true for different pages, negated in your case. If you have a static from page, which it sounds like you do, then is_home is the blog index page. Note: WordPress 2.1 handles this function differently than prior ...


4

You can add code below to the beginning of loop.php add_action('pre_get_posts', 'wpse_change_post_order'); function wpse_change_post_order($query){ $query->set('order','ASC'); $query->set('orderby','date'); } the oldest posts will be in the home page.


3

Before I address your main issue, I must point out a glaring syntax error: <?php if( !is_home() || !is_front_page() ) { ?> <p><?php the_time('F Y'); ?></p> <?php endif } ?> Why is the endif there? It makes no sense whatsoever, and everything in programming has a purpose/reason. You might as well change it to ...


3

It sounds like you want a filter on the_content. function add_content_wpse_97277($content) { global $post; if ($post->ID == 123) { $content .= 'additional content'; } return $content; } add_filter('the_content','add_content_wpse_97277'); I don't know what conditions you need though. You did not explain that in the question. The above should ...


3

To print just the total number of comments for a given post ID, use the count argument: echo get_comments( array ( // post ID 'post_id' => 149, // return just the total number 'count' => TRUE ) ); To get the total number of all comments of all posts on the current page, you can use the comment_count property ...


3

Drawing on Sagive SEO's post this also seems to work without using counters. echo '<ul>'; while ( have_posts() ) { echo '<li><div class="slide">'; the_post(); the_content(); // If there is 1 more post, advance current post and add its content. if ( $wp_query->current_post + 1 < $wp_query->post_count ) { ...


2

If you are using post_class() in your content template like this … <div <?php post_class(); ?>> … you can filter that and add a special class: add_filter( 'post_class', 'mark_first_post' ); function mark_first_post( $classes ) { remove_filter( current_filter(), __FUNCTION__ ); $classes[] = 'first-post'; return $classes; } Your ...


2

AJAX requests (which you imply you are using but do not explain/demonstrate) do not load your active theme, which is where functions.php resides (unless you were referring to a functions.php file that you created in your plugin's directory). As such, your call_user_func() is likely failing as the function that you are attempting to call is not loaded. Note ...


2

Easy using WP query (get to know it...) <ul> <?php $recentPosts = new WP_Query(); $recentPosts->query('showposts=2'); // SET AMOUNT HERE ?> <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?> <li><div class="slide"><?php the_content(); ...


2

First line of the codex for get_content: Displays the contents of the current post. This template tag must be within The_Loop. Also, this line: <meta property="og:description" content="<?php string_limit_words(the_content(), 15);" ?> /> would need to get_the_content(), as the_content() will output, and you need to return. <meta ...


2

I am not going to write your form for you, but create a form and submit it to a page to do the processing, or use the AJAX API. Then use WP_User_Query to actually search for users. It is a very WP_Query-like class that should let you do everything you want including search for user metadata from the $wpdb->usermeta table by passing a meta_query parameter ...


2

... for example inside my loop if i have added following argument 'post_per_page' =>-1 my loop is showing all posts but now i can't insert my custom number of posts inside admin panel if I enter "Blog pages show at most" 3 (three representing number of posts) they are ignored and loop is showing all posts. Of course you can't. You have ...


2

Calling the_post() is what advances the internal current_post counter that have_posts() checks the value of within the loop. With this in mind, you can call the_post() once outside the loop and use any template tags you wish, then run the loop as normal and it will pick up and continue from the second post. the_post(); // this is the first post! ...


2

Track the IDs, and "exclude" them with post__not_in. It is hard to tell exactly what does what with the disjointed way you posted your code but the general case solution is .. $c_posts = new WP_Query("showposts=10"); $tracker = array(); if ($c_posts->have_posts()) { while ($c_posts->have_posts()) { $c_posts->the_post(); $tracker[] = ...


2

When you initiate a Loop, split it up like so: <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <!-- do stuff ... --> <?php endwhile; ?> <?php endif; ?> Anything inside the if statement but outside the while statement will run if have_posts is true, but will not be ...


2

Use array_unique() <?php foreach($users as $user) { $states[] = get_cimyFieldValue($user->ID, 'STATE'); // Grabing their state from their profile page } $states = array_unique($states); ?> <div class="state"> <input type="hidden" name="search_type" value="members"> <select ...


1

There's no reason to use multiple loops to get this effect: The look you want comes from the jQuery Masonry script, which is included in recent versions of WordPress. Your post list as you describe it is just the standard post index, so use a single standard loop -- that is, a WordPress loop, as described in the Codex: http://codex.wordpress.org/The_Loop. ...


1

There is no term_id parameter. You need a tax_query. $args = array( 'post_type' => 'my_post', 'posts_per_page' => 6, 'tax_query' => array( array( 'taxonomy' => 'yourtaxname', 'field' => 'id', 'terms' => 1 ) ) ); $query = new WP_Query( $args ); Notice that I've use new ...


1

If your slider shows posts in a particular category, which is defined by the variable $panel, then you can cleanly separate the slider posts from the normal flow. Display Slider Use new WP_Query() in your template to output the slider: $slider = new WP_Query( array( // 'showposts' is deprecated; use 'posts_per_page' 'posts_per_page' => 10, ...


1

If the goal is such: I do not want to show the date/time on the front page to keep the layout cleaner, only on the other pages that this loop is displayed on. Then you should be able to use a simple conditional: <?php if ( ! is_front_page() ) { ?> <p><?php the_time('F Y'); ?></p> <?php } ?> Without knowing exactly ...


1

In principle you should be able to achieve that by using categories for your posts. So while your normal loop for the single.php might look like this (I'll just leave the markup I had in there since I took this out of a file I had lying around. It may of course be different from yours.) <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ...


1

Consider this snippet here to accomplish your task. If you add it to your functions.php file, the Open Graph tags will be populated automatically as part of the wp_head action.


1

I would create an "Events" custom post type and then create a "Call to Action" custom taxonomy and associate this taxonomy with the custom post type. This way you can have an unlimited amount of events which can be associated with taxonomy terms (your Call to Action). This makes much more sense since you project that you will have few Call to Action types ...


1

Manipulating HTML with regular expressions is not a good idea. I suggest you use DOMDocument: // input $html = apply_filters('the_content', get_the_content()); $dom = new \DomDocument(); $dom->loadHtml($html); $blockquotes = $dom->getElementsByTagName('blockquote'); foreach($blockquotes as $blockquote){ foreach($blockquote->childNodes as $e){ ...


1

You are calling a weird parameter in line 24 which i dont understand... did you copy paste this function from elsewhere? anyhow... change line 24 from: '$param_type' => array($term->term_id), To this: 'cat' => array($term->term_id), Good luck and dont forget to read @toscho comment for future questions.


1

The shop page is actually an archive page for posts of type 'product'. Its template is in woocommerce/archive-product.php. You need to use the pre_get_posts action to preprocess the query before the loop, conditional_tags to recognize that you are in the product archive page, and a taxonomy query to filter the product categories, which belong to the ...


1

It sounds like what you are trying to do is make a kind-of "related posts" feature for your "Locations" single post display based on the category. You don't need to be checking to see if the post is in the "Locations" post type. You are using single-locations.php unless you site is broken only "Locations" posts should show up there. You really only need to ...



Only top voted, non community-wiki answers of a minimum length are eligible