Tag Info

New answers tagged

1

The code that makes this a two-column layout is centered on the $st_cat_counter variable. This is incremented with each iteration and when it's an even number ($st_cat_counter / 2) a row is closed and a new row is started: echo '</div><div class="row">';} elseif ($st_cat_counter == 1) You should simply be able to change "/ 2" to "/ 3". This ...


1

What you want to do is not possible with pagination. I've been thinking about it and came up with this. This is how I will do it Get the current page you are on with $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; Run a custom query in which you get the first post, which will most probably be the newest one. Do a check to see if you are ...


2

It goes to the page, but I can't figure out how to modify my loop so it only shows posts that match the current term, in this example "element", nor display the title of the page as "Element". The following arguments for your loop should do: $args = array( 'post_type' => 'design_asset', 'posts_per_page' => 100, 'orderby' => ...


1

Steve, you've asked a couple of questions which I had a look at, and I came to the conclusion that your loop is causing all of your headaches. My loop to display ALL the posts is: $args = array( 'post_type' => 'design_asset', 'posts_per_page' => 100, 'orderby' => 'title', 'order' => 'ASC' ); $loop = new WP_Query( $args ); while ( ...


1

I think your problem is in the exact code that you've mentioned. pre_get_post is a bastard if you don't use it correctly. With any archive type conditions used in pre_get_posts, it will affect both front end and back end. This include archives pages, category and taxonomy pages, tag pages and author pages. You'll need to do a check that you only run ...


0

It's also possible to create comma separated lists with a terminal 'and' (Oxford style or not) using only CSS: http://stackoverflow.com/questions/6587807/comma-delimited-lists-with-css-i-want-an-oxford-comma


0

If you're adding the image directly in the editor, then the_content() will always echo the image. Which means the title can only be above the blog post or below it. You should try adding the image as a featured image. Take a look at this link to see how to add featured image support, and how to use it-> http://codex.wordpress.org/Post_Thumbnails Basically ...


0

It looks like the plugin is using the update_post_meta function, which in turn uses the update_metadata function which includes the action hooks update_postmeta and updated_postmeta which fire immediately before and after the post meta is stored to the database. You could hook into one of these to update the user meta of the author of the post. Pseudo code: ...


0

you did not describe what you edited to add the isotope filtering, but you seem to have removed post_class() from this line to add your isotope class: <article class="<?php echo $termsString; ?>item"> change it to: <article <?php post_class( $termstring . 'item' ); ?>"> http://codex.wordpress.org/Function_Reference/post_class


2

I would do something like OmAk suggested but I would add some fallback : $activists_thumbs = has_post_thumbnail() ? the_post_thumbnail() : 'path/img_fallback.jpg'; It's better to check if you have something before actually using it. EDIT: wp_reset_postdata() is enough (instead of wp_reset_query() )


3

You can make use of get_post_type( $post ) to check whether a post belongs to a certain post type Inside your loop, you can do the following check while ($my_query->have_posts()) : $my_query->the_post(); if ( 'activists' == get_post_type() ) { /* Custom code for 'activists' post type. */ } else { /* Custom code for the other post types. ...


0

You can use this: <a href="<?php the_permalink(); ?>" title="<?php echo the_title_attribute(); ?>"> <?php the_post_thumbnail(); ?> </a> This will place the featured image with a link to the main post. More details about how you can use image_size when calling the function: the_post_thumbnail


0

Per your example, the contents have to be contained in the if/while statement (if they have posts). Otherwise the boxes will appear and the content will be blank, rather than the content AND boxes hidden completely as you want. Try this: <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="box"> <h2 ...


0

Your file is named content.php, and this line: get_template_part( 'content', get_post_format() ); will load the same file for posts with standard post format, causing your down-the-rabbit-hole loop.


1

I don't know of any WordPress-specific way to exclude duplicate-title posts from a query and I'm sure that there are multiple ways to address this. The solution that jumps to mind is to store each post title in an array and then check to see if that title is already there before outputting the post. Some quick untested code: <?php $args = array( ...


0

Use get_field instead of the_field. That way you can assign it to a varilable. $first_comment = get_field('first_content_block'); $second_comment = get_field('second_content_block'); echo do_shortcode("[vr_jsp] $first_comment, $second_comment [/vr_jsp]"); I haven't tried it, but see if that works.


1

I don't have direct experience with this, but from what I read... Sticky posts don't show up by default on category pages, so adding the categories may throws the query into an "I don't care about sticky posts" mode. You could try running a query first that just grabs the sticky posts, using arguments like this: $sticky = get_option( 'sticky_posts' ); ...


0

First off, you should be using WP_Query vs query_posts. Have a look at the Taxonomy Parameters. Mainly tax_query and relation. // Repost from link above $args = array( 'post_type' => 'post', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'movie_genre', ...


0

UPDATE: Okay, Looking at the Error, it should be easy. Just remove any Whitespaces or Clear Lines at the end of your Plugin file after the last "?>". http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc Did you copy&paste the code here? Because it seems like you have some whitespaces that should not be there in the ...


0

"The Loop" is already a loop, so I don't see the need for your second loop. In fact, the secondary while loop shouldn't work because you keep resetting it to 1 for every post. You also have some PHP syntax issues like $echo (that's a variable) instead of echo and the way you concatenate the number variable with the "slide-" string. The following [untested ...


0

Try this: <div class="all-posts"> <div class="post-group> <?php $i = 0; if (have_posts() ) : while ( have_posts() ) : the_post(); if ($i%4 == 0) echo '</div><div class="post-group">'; ?> <div class="post"> <?php the_title(); ?> </div> <?php ...


0

Like @jdm2112, I'm not a Gensis user, but here is an alternative method to retrieving the featured image. I use this method because it offers more functionality to altering the featured image (ie: thumbnail size). You can add these functions to your functions.php file. public function get_featured_image_id() { return (int) $this->get_meta( ...


0

Displaying the featured image (referred to as 'thumbnail' in WP funcations) should not require you to replace your page loop. I'm not a Genesis user so there's a chance that is the case. Displayin the feature image for the page is as simple as using the WP function the_post_thumbnail . Here is WP ref for full details. Simply using this where you want the ...


-1

In your codes you did not check if there exists any codes matching your query. So it is advisble to check first if query contains posts - $query->have_posts() - and then proceed. You may have a look at the code here


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 going into the template-knowledgebase.php file and 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. I also edited the else statement of the if to be endif and removed the extraneous endif. This is what my ...


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; }



Top 50 recent answers are included