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

  1. Bram
    Posted 3 years 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">
                    $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; ?>
                        			<?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; ?>
            <?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,


  2. curtismchale
    Plugin Author

    Posted 3 years 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.


    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

  • Post Tags and Categories for Pages
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic