WordPress.org

Ready to get started?Download WordPress

Forums

Post Tags and Categories for Pages
query_posts returns pages (2 posts)

  1. Bram
    Member
    Posted 1 year ago #

    Hi there,

    In my website, I have an activities-page. On this page, the content of the 'activities'-page is displayed first, followed by all posts (which contain the actual events) below. To make users select which categories of posts they'd like to show, I'd like to add categories to the 'activities'-page (using this plugin) which works great.

    Displaying these posts/events, however, gives some difficulties. Below is the code I'm using. $categories is an array with the categories that need to be displayed, $main_id is the ID of the activities-page.

    <?php for($i = 0; $i < count($categories); $i++){ ?>
            <div class="activiteiten">
                <?php
                    $post_array = query_posts(array('post_per_page' => '-1', 'post_type' => 'post', 'category_name' => $categories[$i], 'exclude' => $main_id, 'post_status' => 'publish'));
                    echo "<h1>". $categories[$i] ."</h1>";       
    
                        if (have_posts()) :
                        	while (have_posts()) : the_post(); ?>
                        	<div class="activiteit">
                        		<h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
                        		<div class="activiteitinfo">
                                    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                        				<?php if ( has_post_thumbnail()) : the_post_thumbnail(); else : ?>
                        					<img src="<?php bloginfo('template_directory'); ?>/img/no-thumbnail.png" width="110px" class="" />
                        				<?php endif; ?>
                        		    </a>
                        			<?php the_excerpt(); ?>
                        			<p class="meer"><a href="<?php the_permalink(); ?>">Lees verder &raquo;</a></p>
                        		</div><!-- /.activiteitinfo -->
                            </div><!-- /.activiteit -->
                        	<?php endwhile;
                    ?>
                    <?php else : ?>
                        <p>Op dit moment zijn er geen activiteiten in deze categorie gepland.</p>
                    <?php endif; ?>
            </div>
            <?php }
        ?>

    The problem is in the query_posts-function. If I add the 'category_name'-parameter, the 'post-type'- and 'exclude'-parameters are neglected.

    Thanks a lot for any help and tips,
    Bram

    http://wordpress.org/extend/plugins/post-tags-and-categories-for-pages/

  2. curtismchale
    Member
    Plugin Author

    Posted 1 year ago #

    You should never use query_posts if you think you should use it, think again.

    Below are 2 great resources to learn more about why you really shouldn't be using query_posts ever.

    http://developer.wordpress.com/2012/05/14/querying-posts-without-query_posts/
    http://wordpress.tv/2013/03/15/andrew-nacin-wp_query-wordpress-in-depth/

    This really isn't a 'support' question for my plugin either and will get more attention on wordpress.stackexchange.com or on the main forums here.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic