Query_post() – unsafe?
-
I would ask this on the Page Builder support site, but it is quite inactive and questions seem to be going unanswered. I think it’s a simple coding question so perhaps here will be fine.
I’m using the ‘grid-loop’ to display posts on pages. However, I’m creating multiple ‘grid-loop’ files for each category, since a different category of posts will be displayed on their own respective page.
For each new grid-loop file, I’m adding in query_posts( ‘cat=ID’ ); and using that to display the category I want. I’ve read that using these queries is unsafe or something? I’m using a different file for each category’s respective loop.
Here’s the code for category 5’s loop.
<?php /** * Loop Name: Grid Child */ ?> <?php if( have_posts() ) : $i = 0; ?> <div class="vantage-grid-loop"> <?php query_posts( 'cat=5' ); while( have_posts() ): the_post(); $i++ ?> <article <?php post_class(array('grid-post')) ?>> <?php if( has_post_thumbnail() ) : ?> <a class="grid-thumbnail" href="<?php the_permalink() ?>"> <?php the_post_thumbnail('vantage-grid-loop') ?> </a> <?php endif; ?> <h3><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h3> <div class="excerpt"><?php the_excerpt() ?></div> </article> <?php if($i % 4 == 0) : ?><div class="clear"></div><?php endif; ?> <?php endwhile; ?> </div> <?php vantage_content_nav( 'nav-below' ); ?> <?php endif; ?>The query is near the top. Will I have any problems with it? It seems to be doing exactly what I want, and I suck at anything coding related so it’s the best I can do.
The topic ‘Query_post() – unsafe?’ is closed to new replies.