WordPress.org

Ready to get started?Download WordPress

Forums

Category template slug query problem (1 post)

  1. themil
    Member
    Posted 4 years ago #

    Hey Everyone!

    I can't seem to get my head around this!
    For some reason WP, every time that you need to Import new content into itself from another (Say a testing/localhost site) this seem to go haywire! What seems to happen is though on the testing sight, everything is identical to the working, new categories come out of nowhere! Same name, different slug!
    But that is just something minor, but the I was able to implement the new 2.9 code of calling a slug rather than an ID.
    Problem is, sometimes rather than calling the actual category, it calls ALL new posts even if not specific to that category..!

    This code works:

    <?php if (have_posts()) : ?>
        <div class="wrapper">
      	<div class="left1">
        <?php $category_id = get_cat_id('restaurants'); $q = 'cat=' . $category_id; $recent = new WP_Query($q); while($recent->have_posts()) : $recent->the_post();?>
        <?php if( get_post_meta($post->ID, "Category_Image", true) ): ?>
        <a href="<?php the_permalink() ?>" rel="bookmark"><img src="<?php echo get_post_meta($post->ID, "Category_Image", true); ?>" /><br />
    	<?php the_title(); ?>
        </a>
    	<?php $count++;if ($count==1){echo "</div><div class='left2'>";} ?>
       	<?php if ($count==2){echo "</div><div class='left3'>";} ?>
    	<?php if ($count==3){echo "</div><div class='left4'>";} ?>
        <?php if ($count==4){echo "</div><div class='left5'>";} ?>
        <?php if ($count==5){echo "</div><div class='right'>";} ?>
        <?php if ($count==6){echo "</div><div class='wrapper'><div class='left1'>";} ?>
        <?php if ($count==7){echo "</div><div class='left2'>";} ?>
        <?php if ($count==8){echo "</div><div class='left3'>";} ?>
        <?php if ($count==9){echo "</div><div class='left4'>";} ?>
        <?php if ($count==10){echo "</div><div class='left5'>";} ?>
        <?php if ($count==11){echo "</div><div class='right'>";} ?>
        <?php if ($count==12){echo "</div><div class='wrapper'><div class='left1'>";} ?>
        <?php if ($count==13){echo "</div><div class='left2'>";} ?>
        <?php if ($count==14){echo "</div><div class='left3'>";} ?>
        <?php if ($count==15){echo "</div><div class='left4'>";} ?>
        <?php if ($count==16){echo "</div><div class='left5'>";} ?>
        <?php if ($count==17){echo "</div><div class='right'><div class='wrapper'>";} ?>
        <?php if ($count==18){echo "</div>";} ?>
      <?php else: ?>
        &nbsp;
        <?php endif; ?>
      <?php endwhile; ?>

    But when I call another slug which is this:

    <?php if (have_posts()) : ?>
        <div class="wrapper">
      	<div class="left1">
        <?php $category_id = get_cat_id('coming-events'); $q = 'cat=' . $category_id; $recent = new WP_Query($q); while($recent->have_posts()) : $recent->the_post();?>
        <?php if( get_post_meta($post->ID, "Category_Image", true) ): ?>
        <a href="<?php the_permalink() ?>" rel="bookmark"><img src="<?php echo get_post_meta($post->ID, "Category_Image", true); ?>" /><br />
    	<?php the_title(); ?>
        </a>
    	<?php $count++;if ($count==1){echo "</div><div class='left2'>";} ?>
       	<?php if ($count==2){echo "</div><div class='left3'>";} ?>
    	<?php if ($count==3){echo "</div><div class='left4'>";} ?>
        <?php if ($count==4){echo "</div><div class='left5'>";} ?>
        <?php if ($count==5){echo "</div><div class='right'>";} ?>
        <?php if ($count==6){echo "</div><div class='wrapper'><div class='left1'>";} ?>
        <?php if ($count==7){echo "</div><div class='left2'>";} ?>
        <?php if ($count==8){echo "</div><div class='left3'>";} ?>
        <?php if ($count==9){echo "</div><div class='left4'>";} ?>
        <?php if ($count==10){echo "</div><div class='left5'>";} ?>
        <?php if ($count==11){echo "</div><div class='right'>";} ?>
        <?php if ($count==12){echo "</div><div class='wrapper'><div class='left1'>";} ?>
        <?php if ($count==13){echo "</div><div class='left2'>";} ?>
        <?php if ($count==14){echo "</div><div class='left3'>";} ?>
        <?php if ($count==15){echo "</div><div class='left4'>";} ?>
        <?php if ($count==16){echo "</div><div class='left5'>";} ?>
        <?php if ($count==17){echo "</div><div class='right'><div class='wrapper'>";} ?>
        <?php if ($count==18){echo "</div>";} ?>
      <?php else: ?>
        &nbsp;
        <?php endif; ?>
      <?php endwhile; ?>

    The only change is the slug being called!
    I've tried changing the loop to this but with no success:

    <?php $category_id = get_cat_id('tours-sightseeing'); $q = 'cat=' . $category_id; $recentPosts = new WP_Query(); $recentPosts->query($q);?>
        <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>

    If the category template file isn't implemented (which is what the code is in, eg: category-restuarants.php & category-coming-events.php), It displays what it's meant too, the 3 only items that are in the requested category!

    Please, help! And thanks in advanced :)

Topic Closed

This topic has been closed to new replies.

About this Topic