Tag Info

New answers tagged

1

Try just using the traditional $i iterator (untested) but I can't see why this wouldn't work.. <?php $i = 0; while ( have_posts() ) : the_post(); $i++; if ( $i == 1 ): ?> <!-- First Post --> <div id="post"> <a class="post_image" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> ...


1

Yep, it's not very common, but perfectly viable and nifty technique. After the posts are retrieved in WP_Query they are passed through the_posts filter like this (where $this is WP_Query instance): $this->posts = apply_filters_ref_array( 'the_posts', array( $this->posts, &$this ) ); You just loop through array and assign the extra data you need ...


0

My solution was really simple: $input = array("defaultImage1.jpeg", "defaultImage2.jpeg", "defaultImage3.jpeg", "defaultImage4.jpeg", "defaultImage5.jpeg", "defaultImage6.jpeg"); $rand_keys = array_rand($input, 2); echo '<img class="story-carousel" src="'.$upload_dir['url'].'/'.$input[$rand_keys[0]].'" alt="">';


0

Try this one , .. $ID = get_the_ID(); $page_data = get_page( $ID ); $excerp = strip_tags($page_data->post_excerpt); if ( !empty( $excerp ) ) : the_excerpt(); else : echo get_permalink() endif;


0

In Custom category page put this code , to work correctly to assign post_type' => 'post <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'prev_text' >' Previous','post_type' => 'post', 'posts_per_page' => 2, 'paged' => $paged ); $wp_query = new WP_Query($args); while ( have_posts() ) : ...


0

It's far easier to use built-in loop functions such as pagination when you use a category template based on the template hierarchy. You mentioned using the category ID to load posts into your custom template page, but if you instead name the template file based on the category ID, you can simply use the default WP loop, and include <?php echo ...


1

You could try to use the .children method to filter through your response - let's say the posts are comming in containers with a particular selector on them - say, you add class="mypost" on the divs when you build the response -, then you can do something like this in your success method: // ... ...


0

I took a quick peek at the other question referenced in other comments, and the gist of how you loop through attachments there meshes with what is shown in the wp_get_attachment_image documentation example. In a nutshell, any attachments on a particular post will reference that post by ID. In particular, it's crucial to understand that attachments are ...


0

Custom post types are excluded from the main query by default (except on taxonomy pages and custom post type archive pages), that is why you don't see posts from your custom post type on your category page. You need to include your custom post type posts in the main query manually. That is done with pre_get_posts which alters the main query before it is ...


1

You can get attachment URL like this. <?php if ( have_posts() ) : while (have_posts()) : the_post(); ?> <a href="<?php $featured_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); echo $featured_image_url[0]; ?>"> <?php the_title(); ?> </a> <?php endwhile; endif; ?> ...


0

If I'm understanding you correctly you just need two more arguments in your $args array. Firstly, category_name - see WP_Query - Category Parameter. We get the value from the $wp_query global via get_query_var(), so like this: 'category_name' => get_query_var( 'category_name' ) Secondly, for the number of posts to show there is posts_per_page as it is ...


0

Update ... Here's the Final Code That Worked for Me This may not be perfect, but it seems to be working well for me with no errors. Feel free to add any suggestions for improvement if you have any. JS Code jQuery(document).ready(function($) { var count = 2; jQuery("#la-chooser").change(function() { loadArticlebyCat(this.value); }); ...


0

I've been trying to figure out a solution for this too - I have a plugin with custom post types, those custom post types require a custom archive but creating a specific template file means it wouldn't work with every theme. The closest alternative I can think of that hasn't been mentioned above is to read the archive/index.php file on plugin activation ...


1

In the end i made two queries, the first one to get the ids of the posts and the second one to give back the posts in the type of sorting i wanted to: $flag = false; //arguments for first query $args = array( 'post_type' => 'post', 'posts_per_page' => 500, ); $query = new WP_Query($args); //make first query only to get the ids while ...


2

What about an approach like this: $first_category_args = array( // category id 'cat' => 123, // get all from cat 'posts_per_page' => -1, // don't prepend sticky 'ignore_sticky_posts' => 1, // only return ids 'fields' => 'ids' ); // array of ids $first_category_query = new ...


1

This stores a variable to check if the most recently displayed post was in category 1. If the next post is also in category 1, it adds it to an array of stored posts. This allows you to store multiples posts in case you have many category 1 posts in a row. Finally it spits out all stored posts if you've reached the last item in the loop. $prev_cat1 ...


1

Ok the problem was with using 'year' as the argument name, if I changed it to something else such as 'y' it seems to work.


0

Yes you can pass the variable in category_name. But I think it should be get_the_title() instead of the_title(). $title = get_the_title(); $args = array( 'category_name' => $title ); Try this. But remember category_name only accepts category slug, not category name. You can also use following method if your page title/slug are different. And I ...


0

This is for when you want to use get_the_excerpt() outside the loop: function custom_get_excerpt($post_id) { $temp = $post; $post = get_post( $post_id ); setup_postdata( $post ); $excerpt = get_the_excerpt(); wp_reset_postdata(); $post = $temp; return $excerpt; }


0

Not tested but this should work: add_action('manage_pages_custom_column', 'display_page_custom_cols', 10, 2); function display_page_custom_cols($col_name, $post_id) { global $wpdb; $user_group = $wpdb->get_results("SELECT * From custom_user_group",OBJECT_K); if ('user_group' == $col_name) { $pages = explode(',',get_post($post_id)); ...


3

You can make use of the custom field parameters in WP_Query like you have, you just need to extend it a bit further You can do your sorting by post_views_count and use meta_query to get all posts that has the highest post view count and has a post thumbnail You can probably try something like this $args = array( 'order' => 'DESC', ...


1

The simplest explanation is that the HTML rendered in your code does not match what you're actually looking for. Without seeing the JS responsible for the slider, it's impossible to say where you went wrong, but you should compare the mocked-up version (that works) with what you're actually getting (HTML source after page render) to see if there were any ...


0

What about trying a different approach using get_pages() ? $destination = get_page_by_title( 'Destinations'); $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $num_pages_per_page = 4; $args = array( 'sort_order' => 'ASC', 'child_of' => $destination->ID, 'number' => $num_pages_per_page, 'offset' => ( ...


0

You should reset the query after your active slider. So place this code after your first loop (after endwhile; endif; ): //Reset Query wp_reset_postdata(); Also try setting the paged atribute: $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; // WP_Query arguments $args = array ( 'post_parent' => $destination->ID, ...


0

If the Home page is set to be a static page like you have, I think that the posts page is supposed to be a different page. http://codex.wordpress.org/Settings_Reading_Screen You can display your recent posts on front-page.php with WP Query, though: http://codex.wordpress.org/Class_Reference/WP_Query Here's a mostly inclusive starter code, followed by the ...


0

There's a much simpler way and lighter way. By definition sticky posts will come first on the loop. So on your featured area (before any call to the_post() ) you can put: <div> <h3>Special Featured Loop</h3> <?php the_post(); //this will get the first post, and generate all the tags the_title(), the_permalink(),... ?> ...


2

There are many choices here, and it is all up to you what you want to achieve and how you want to achieve it. My idea would be to use the templates available to avoid a lot of if else conditional statement. The Template Hiearchy makes provision for templates for terms, taxonomy-{$taxonomy}-{$term}.php, so you could create a tempate for each term. So for ...


0

The most probable cause of this is the incorrect use of pre_get_posts, so I would look in my functions.php for any instance of pre_get_posts. I would suspect that pre_get_posts is used to set posts_per_page to 5 across the complete site. Irrelevenat, but you make use of the build in loop counter $wp_query->current_post as a counter in stead of creating ...


0

You can use pre_get_posts action to exclude categories from homepage. function wcs_exclude_cat( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '-23' ); } } add_action( 'pre_get_posts', 'wcs_exclude_cat', 1 ); Change featured category id in above code (with minus sign). And to exclude ...



Top 50 recent answers are included