Tag Info

New answers tagged

0

You want to query for the pages on the current site? WP_Query is your friend! first tell it what we want $args = array( 'post_type' => 'page' ); then create the query $query = new WP_Query( $args ); now check if it found any pages if ( $query->have_posts() ) { If it did, do a standard posts loop: while( $query->have_posts() ) { ...


0

If I understand, you need to create a template that list all your pages (actors) on one template. If this is the case, you need to create the actor archive template to allow you to: Add a page where you can list all your actors Left the page template intact So, the template that you need to create is archive-actors.php Then, on this template, you need ...


1

place a single box opening and closing markup outside the loop, then only close/open a new one when it's every 3rd post and not last by using the built in loop vars current_post and post_count if( ( ( $your_query->current_post + 1 ) % 3 == 0 ) && ( $your_query->current_post + 1 ) != $your_query->post_count ){ // close the box ...


0

H'okay, so, using this resource, I was found that replacing the cat keyword with category__in (that's a double underscore) did only return the articles who's parent were the category we were looking at. It's not a totally robust solution; for example, the number of posts in each category will go to posts per category * 2, so I'll have to fix that this ...


0

This is personal preference, but I don't really like using $wp_query and complicating things. There are two ways to solve this problem, one, by using a temp variable with $wp_query and two, changing the name of your variable and fixing pagination, which I would recommend, again, personal preference METHOD 1 As I said, you can assign a temp variable to ...


1

Use wp_reset_query() to restore the original query. This also calls wp_reset_postdata, so you can just replace that.


1

This can be achieved by making use of Masonry a Cascading grid layout library Which is included in WordPress since 3.5 and has been updated to v3 with the release of version 3.9 of WP. It really is a nice tool to accomplish different kind of grid layouts. Of course it isn't necessary to use this library, but it is indeed really good for grid layouts, ...


0

I agree with Pat above - I'd say from my own experience it probably helps in the long run making a Custom Post Type for houses to keep hundreds of the things separate from your main pages (or blog). For starting with coding it all - sometimes to kick off with and starting to learn about these things it will give you a headstart to begin with plugins. I ...


2

When the loop is complete, have_posts() rewinds it back by calling the rewind_posts() method of the $wp_query object, see here. Here's another (more simple?) setup that you could try: while( have_posts()): the_post(); if ( 0 == $wp_query->current_post ): // post 1 elseif ( 1 == $wp_query->current_post ): // post 2 ...


0

The main query that runs on archive pages are quite specific to archive pages, and this query is not replicated with a default custom query. As your code stands, your query will retrieve posts according to published date, ie from newest to oldest, and not according to archive. THE PROBLEM There are a couple of issues here that I would like to point out. ...


0

You can use the transition_post_status action to manipulate the post content at the time when it is published. You just need to add a function like the one below into your theme or plugin: function post_published( $new_status, $old_status, $post ) { if ( $new_status == 'publish' && $old_status != $new_status) { //Do whatever you want to ...


0

For showing data in static template field you need to run WP_Query with your arguments Then code will look like this <?php $args = array('post_type'=>'post'); // The Query $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) { echo '<ul>'; while ( $the_query->have_posts() ) { ...


0

This quite a broad question to answer. I'm not going to go into detail here and into core code, you'll need to go and read the links I'm going to provide. I'm going to try to keep my answer sweet and short and useful :-) Take the bundled theme twentyfourteen for example, when you open any page template, you'll find this piece of code if( have_posts() ) : ...


0

Why is it that 2, identical php file produce different results? In my example, the "sample-page.php" will display the "PAGE CONTENT", while "home.php" will display "RECENT POSTS" Because there are two different things that can be at front page, depending on how you configure it — list of blog posts or front page (with list of posts displayed elsewhere, ...


1

Just create an array with your classes and loop through alongside with the main loop: function custom_top_products() { $classes = array( 'first', 'second', 'third', 'fourth', 'fifth' ); $classes_count = count( $classes ); $posts = new WP_Query( array( 'post_type' => 'products', 'post_status' => 'publish', 'orderby' ...


1

For anyone with the same problem, here's the answer. I finally figured it out. // Display Profile Sidebar ACF add_action('genesis_sidebar', 'employee_title'); function profile_photo() { if ( is_singular('profile') && genesis_get_custom_field('employee_title') ) echo '<div id="employee-title"> '. genesis_get_custom_field('employee_title') ...


0

Use function get_users() $users = get_users(); foreach ($users as $user) { echo $user->ID; echo $user->display_name; the_author_image($user->ID); echo $user->description; }


2

You can display author's list by using function wp_list_authors for more info : http://codex.wordpress.org/Function_Reference/wp_list_authors And for author Template Hierarchy see below link http://codex.wordpress.org/Author_Templates


1

If I understand your question correctly, you can try the following: add_filter( 'the_content', 'incrementparagraphs', 10, 1 ); function incrementparagraphs( $content ) { return preg_replace_callback( '|<p>|', function ( $matches ) { static $i = 0; return sprintf( '<p ...


1

For your author box to work, it needs to be inside the loop. You have one fundamental flaw though with your second loop. You are currently using two different loops in one, the first one being the main loop, and the second one a custom loop to fetch related posts As it stand, and where you placed your author box, it is getting its information from the ...


2

Why wouldn't you just pull them in the order you need instead of reversing the array? $args = array( 'post_type' => 'attachment', 'posts_per_page' => -1, // correct key is posts_per_page, not numberposts 'orderby' => 'date' 'order' => 'ASC', 'post_parent' => $post->ID ); $attachments = get_posts( $args );


0

This doesn't seem terribly efficient but you could just look up the next/prev posts in the loop used to display the post then output the post titles in the nav calls. // loop if ( have_posts() ) : while ( have_posts() ) : the_post(); // ... post display // next & prev post data $older = get_previous_post(); $newer = get_next_post(); endwhile; ...


0

Re-reverse the array! if ( $attachments ) { $attachments = array_reverse( $attachments ); foreach ( $attachments as $attachment ) : ?> <p> <?php echo wp_get_attachment_image( $attachment->ID, 'full' ); ?> </p> <?php endforeach; }


1

EDIT: Answer has been found and I am posting it for anyone else who has this issue. If you have better ways of accomplishing this then please post below for the benefit of others. Place this code in your category.php. It will automatically grab the category from the URL and pass it to the cat => $category_id and update the loop accordingly. <ul ...


1

INFORMATIONAL CONTENT Pages, like posts, are stored in the database as post_types, the big difference here is that pages lives outside the normal time-based listing. Check at what the codex say What Pages Are: Pages are for content that is less time-dependent than Posts. Pages can be organized into pages and subpages. Pages can use different Page ...


2

Strictly, you don't need to use a loop in a page template, but it doesn't hurt, the content of the page will still load, the loop will simply only run once as there is only one post/page. Many themes include a loop in page templates, I guess for some compability issue. If you are building your page template from scratch, you don't need to add a loop to it, ...


1

Finally I got the solution. One of the major problems was the usage of "get_post_custom" for fetching the database. I used "get_post_meta" instead and it was a lot easier to work with the array that was created by that function. I am sure that it would have been possible to do it with the first function as wee but I do not really understand its ...


1

I'm having trouble understanding the question, but I'm assuming the code snippet you posted containing query_posts is in a category, archive or index template which is called when you follow on of the links generated by get_category_link (). If so, the query_posts function is overriding the default loop, but you're not including the category to filter by so ...


1

You have the orderby parameter in your query but you are missing the companion order. This gives ascending/descending rule to the sortation. WordPress Codex reference


-2

Well, assuming the post content will be provided by Youtube embedded code, a change in the regular expression is needed. The function must obtain the source of the iframe. So would be as follows: function get_thumbnail_fromyoutube( $size = 0 ) { global $post, $posts; $youtube = ''; $get_url = preg_match_all('/src="([^"]+)"/', $post->post_content, ...


1

Having 3 divs for the text content is not a problem, but they shouldn't be contained by the same div as the images... You can have: <div id="container"> $count = 1; while loop <img id img$count..> <div id div$count...> $count++; Endwhile </div> You then position the divs absolutely and hide ...


1

As Tom mentioned, $link is false because your post types don't have archives. You need to add the has_archive argument when you register your post types, and set rewrite to true so the rewrite rule for your archive is generated.


2

Try this to get the count of posts: <?php $connected = new WP_Query( array( 'connected_type' => 'posts_to_pages', 'connected_items' => get_queried_object(), 'nopaging' => true, ) ); echo "<h2>Found: $connected->found_posts</h2>"; ?> You could write a variable like: $the_count = $connected->found_posts; Then ...


0

From the function reference for get_posts(): For full parameters list see WP_Query. From the WP_Query reference: ignore_sticky_posts (boolean) - ignore sticky posts or not (available with Version 3.1, replaced caller_get_posts parameter). Default value is 0 - don't ignore sticky posts. Note: ignore/exclude sticky posts being included at the ...


0

There is no inherent technical limitation to how many posts can WP loop query. However there is always resources (CPU and memory) ceiling of specific server and configuration. If you are leaking/eating memory in any way (for example adding up some results with every post iteration) it will get exhausted quickly. WP query class (wpdb) drags all of the ...


1

custom-header.php <!-- Start Top Header affix nav--> <div id="affix" data-spy="affix" data-offset-top="94" data-offset-bottom="0"> <!-- **** START - NAVBAR SCROLLSPY FIX DO NOT REMOVE **** --> <div id="top" class="hide"></div> <!-- **** END - NAVBAR SCROLLSPY FIX DO NOT REMOVE **** --> <!-- **** START - NAV **** ...


0

I found this question when looking how to do this without the post object. My additional research turned up this slick technique: $text = apply_filters('the_excerpt', get_post_field('post_excerpt', $post_id));


0

Use get_the_post_thumbnail with a new WP_Query. <?php if ( has_post_thumbnail()) { $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large'); echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >'; echo get_the_post_thumbnail($post->ID, 'thumbnail', array('class' ...


0

Getting things mixed up before, got it working now. Thanks. This is the code I finally ended up with for my purposes: <section id="top-columns"> <?php $args = array ( 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => true, 'number' => '4' ); $terms = get_terms( ...


0

There are a few things wrong: In your code you are using the same $args array in the WP_Query call that you used in your get_terms call. Perhaps you meant to use $postargs in the WP_Query call? @Milo is correct...you should be using posts_per_page, not number. Your tax_query array element 'field' says 'name' but you pass it the term slug and not the term ...


0

$wp_query = new WP_Query( $args ); if ( have_posts() ) : If you're doing this inside a function or some other piece of code, then your $wp_query is not the same $wp_query that the main Loop functions ( like have_posts() ) are actually looking at. The main Loop functions use the global $wp_query instance, which is the main one generated by WordPress for ...


1

I couldn't figure out a WordPress way to do this and looking at the WP source, it looks like this probably will never really be possible. However, I was able to get a solution using vanilla PHP by redirecting standard output into a buffer and loading the buffer into a variable. $listings = new WP_Query(...); ob_start(); while ( have_posts() ) { ...


0

If you're looking for just the content from a post before it gets loaded into a template, then you're probably looking for get_the_content().


1

get_the_terms returns an array of terms - so $terms is an array. Therefore, your condition: if( $terms->slug != 'product-gallery' ) will always return false, and therefore skip every post every time. Try if ( in_array( 'product-gallery', $terms ) ) continue; The above is untested.


0

Try calling have_posts() and the_post() with the object operator. Edit your code thusly: $wp_query = new WP_Query( $args ); if ( $wp_query->have_posts() ) : //... while ( $wp_query->have_posts() ) : $wp_query->the_post(); //more dots ... dot dot dot ... endwhile; //... else: echo 'No stuff ...


3

T a look at how to properly construct a query with WP_Query. $args = array( 'post_type' => 'cameras', 'posts_per_page' => 5, ); $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) { echo '<ul>'; while ( $the_query->have_posts() ) { $the_query->the_post(); echo '<li>' . ...



Top 50 recent answers are included