Forum Replies Created

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter mabufo

    (@mabufo)

    I’m going to have to at least learn some basic control structures in php for use in the future. Thanks for the assist.

    Thread Starter mabufo

    (@mabufo)

    As I suspected, the problem lies with the initial query_posts() call: query_posts('showposts=1', "cat=$negated_special_cat");

    Because showposts is only set to 1, it only looks at the most recent post – which is in my special category – so it skips over it and ends up not returning anything (or something to that effect). Increasing the showpost amount seems a tad hackish – but is there a way I can change that call so it works properly? Perhaps if I set the control panel setting on how many posts to display, and removed the showpost parameter? Because i only want it to show ONE non special post.

    EDIT: okay, I removed the showposts=1 from the param list of the query wrapper function, and changed the control setting to show one post, and it worked!

    My question now is: will this new query assignment return the 5 most recent special posts – or will it return whatever posts happen to be in the special category from the 5 most recent posts?
    <?php $my_query = new WP_Query('category_name=special&showposts=5'); ?>

    Thread Starter mabufo

    (@mabufo)

    Of course: https://wordpress.pastebin.com/m49c3d3e8

    That is the index.php file.

    Thread Starter mabufo

    (@mabufo)

    Sorry, I must have clicked submit more than once – I didn’t mean to do that.

    In the research that I did – I actually stumbled across that page – but I also found one about setting up a second loop to do something like this at this page: https://codex.www.ads-software.com/The_Loop . So I figured I would try it and see how far I got.

    I set up a test blog that currently has 4 test posts. Two of the are in the category I want excluded (called ‘special’), and two of them are categorized, and thus should be shown. The special posts are the most recent.

    as far as I can see the second loop that displays the special posts works just fine – you know, because it displays them. But the first loop that displays the posts that are not in the special category is not displaying any posts. I only want 1 non special post to be displayed next to the 5 special posts.

    Here is the loop code I’m looking at. I think the problem sits with the wrapper query function’s arguments. I don’t know exactly how it works but I think that because show posts is set to 1 – it only looks at the post that was most recently added – and because the most recent post is not special (see the negation in the argument list) – it doesn’t put anything into the posts array – but I’m not really sure if that’s what’s happening or how to fix it. Here’s that code:

    <?php
    				// Here is the call to only make two posts show up on the homepage REGARDLESS of your options in the control panel
    				//THIS IS SET TO ONE DUE TO THE NEW STYLE EDIT AND THE ADDITION OF A SECOND LOOP///////
    
    				$special_cat = get_cat_ID("special"); // gets the ID of the category we want to make 'special'
    				$negated_special_cat = $special_cat * -1;
    				query_posts('showposts=1', "cat=$negated_special_cat"); //called with the negated ID to exclude those posts
    			?>

    Now here is the first loop making use of the above query:

    <?php if (have_posts()) : ?>
    				<?php $first = true; ?>
    
    				<?php while (have_posts()) : the_post(); ?>
    				<?php if (in_category($special_cat) && is_home() ) continue;  //we have to exclude the special category from the left?> 
    
    					<div class="story<?php if($first == true) echo " first" ?>">
    						<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>
    						<div class="details">
    						Posted by <?php the_author_posts_link() ?> on <?php the_time('M d Y');?> |
    						<?php the_category(', ') ?> <?php edit_post_link('Edit this', '', ''); ?>
    						</div>
    						<?php the_excerpt() ?>
    						<div class="details">
    						<?php comments_popup_link('no comments', '1 comment', '% comments'); ?> for now | <span class="read-on"><a href="<?php the_permalink() ?>">read on</a></span>
    						</div>
    					</div>
    					<?php if($first==true) { $first= false;} else {echo '<div class="clear"></div>';$first= true; } ?>
    
    				<?php endwhile;//end of loop ?>
    
    ...
    ...
    ...
    
    <?php else : ?>

    And here is the second loop that actually is displaying posts – but if my assumption is correct this one is going to have the same problem as the first if the newest 5 posts aren’t in the right category.

    <!--BEGIN SECOND LOOP (QUERY POSTS IN SPECIAL CATEGORY ONLY!!!!)-->
    				<?php $my_query = new WP_Query('category_name=special&showposts=5'); //makes a new query object because we can't use the old one ?>
    				<div class="story<?php if($first == true) echo " first" ?>">
    				<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    						<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>
    						<div class="details">
    						Posted by <?php the_author_posts_link() ?> on <?php the_time('M d Y');?> |
    						<?php the_category(', ') ?> <?php edit_post_link('Edit this', '', ''); ?>
    						</div>
    						<?php the_excerpt() ?>
    						<div class="details">
    						<?php comments_popup_link('no comments', '1 comment', '% comments'); ?> for now | <span class="read-on"><a href="<?php the_permalink() ?>">read on</a></span>
    						</div>
    
    				<?php endwhile;//end of loop ?>

    is my assumption about the problem correct? If it is, how do I fix my query call above the first loop so it grabs the newest post that isn’t in the special category? And likewise, how do I grab the 5 newest posts in the special category? If that actually is not the problem like I think it is, how do I fix the first loop so it actually displays a non special post?

    Thank you guys.

    Thread Starter mabufo

    (@mabufo)

    Okay fixed:

    Price: <?php $price = get_post_meta($post->ID, ‘price’, $single = true); ?> <?php echo $price; ?>

    Forum: Plugins
    In reply to: First time plugin creation
    Thread Starter mabufo

    (@mabufo)

    I’m looking to add a hidden form field to my comment form is all.

    Thread Starter mabufo

    (@mabufo)

    Even with plugins disabled, this is still happening. It’s happening all over my wordpress installation, including the admin panel. But, the wierd thing is that it’s only happening some of the time.

    I wonder if this is a hosting issue, and not a word press issue. I’m using bluehost if anyone wants to know.

Viewing 7 replies - 1 through 7 (of 7 total)