Forums

[resolved] Altering the loop - in custom (not mine) php... (9 posts)

  1. amateur6
    Member
    Posted 2 years ago #

    Okay, I think I understand how to use the loop to alter which categories show up on which separate pages. I have two categories (news and jobs) and two main pages to display excerpts of each of those, and now I need to have the article pages for each to link only to others of the same category. So a news post will only have other news posts in the <- previous and next -> links. I believe I can do that by altering each loop on separate article templates.

    But -- as I started to browse the php file, I realized my developer had done something beyond my understanding. The template file is here:
    http://wordpress.pastebin.com/pQd0mGC5

    The relevant section (I believe) is between the highlights. Anyone have any ideas where I can insert something like <?php query_posts($query_string . '&cat=-3,-8'); ?> as shown in the codex at http://codex.wordpress.org/The_Loop?

    An last question -- by -3,-8 does that mean I need to use the category number or can I use a category name (such as -news)?

    Many thanks as always!

  2. vtxyzzy
    Member
    Posted 2 years ago #

    I am not sure I quite understand. A link to your site might help.

    As for inserting -3 in the cat list, I am not sure that will do what you want. Your query is defined by $wp_query = new WP_Query($args);, and you can't have a second query without messing up that one. I think that adding the -3 exclusion in this code will only help if some posts are in two categories, but I could be wrong. Anyway, if you want to try excluding category 3, you can alter the $args array like this:

    $args=array(
       'category__in' => array($cat),
       'category__not_in' => array(3),
       'orderby' => 'date',
       'order' => 'DESC',
       'paged' => $paged,
       'posts_per_page' => $post_per_page,
       'caller_get_posts' => $do_not_show_stickies
    );

    For your last question: Yes, when you are excluding a category with 'cat=-2', or 'category__not_in', you must use an id.

  3. amateur6
    Member
    Posted 1 year ago #

    Sorry for the delay.

    Link: http://teknikor.com/content/news/

    As you'll see, if you click on the top News item and go to its individual post, the link to "previous" is a news item, but the "next" link is a job offering! That's what I'm looking to solve.

    Confusion is probably on my end, I must be misinterpreting the codex's loop page. Is that just for sidebar info or info under the post or something?

    Thanks on clarifying that last point, too.

  4. vtxyzzy
    Member
    Posted 1 year ago #

    This may not be the complete solution, but it is a first step if it works. Please make a backup copy of single.php, them change this:

    <div class="navigation">
          <div class="alignleft"><?php previous_post_link('&laquo; %link') ?></div>
          <div class="alignright"><?php next_post_link('%link &raquo;') ?></div>
       </div>

    to this:

    <div class="navigation">
          <div class="alignleft"><?php previous_post_link('&laquo; %link',true) ?></div>
          <div class="alignright"><?php next_post_link('%link &raquo;',true) ?></div>
       </div>
  5. vtxyzzy
    Member
    Posted 1 year ago #

    Sorry, I left out one parameter:

    <div class="navigation">
          <div class="alignleft"><?php previous_post_link('&laquo; %link','%title',true) ?></div>
          <div class="alignright"><?php next_post_link('%link &raquo;','%title',true) ?></div>
       </div>
  6. amateur6
    Member
    Posted 1 year ago #

    Sorry, I may be being dense -- Isn't that mostly css? I don't see how it address my issue of separating posts of the News (category) from Jobs (category)...

  7. vtxyzzy
    Member
    Posted 1 year ago #

    It isn't css, it changes the parameters to previous/next_post_link in single.php. That means when you see a link on a single post page, it will only show posts that are in the same category as the current post. I think that is the original problem you described.

    It isn't the final solution, because it will make all single post displays stay in category, and you probably don't want that for your blog section (assuming you have one). But I want to make sure that it solves the current problem before proceeding.

  8. amateur6
    Member
    Posted 1 year ago #

    Oop, sorry -- thanks! We actually DON'T have a blog on that site, so unless they decide to add one, I'm all set. And if they do, well, I'll worry about that then.

    Thanks SO MUCH!

  9. vtxyzzy
    Member
    Posted 1 year ago #

    You are welcome.

Topic Closed

This topic has been closed to new replies.

About this Topic