• I changed some code on the index page to exclude a category, but now all article links are opening the same page…

    This is what I added in place of the standard “have_posts()” code:

    <?php query_posts($query_string . '&cat=-8'); ?>
    						 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
                             <!-- Display the Title as a link to the Post's permalink. -->
                             <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    
                              <div class="entry">
                                <?php the_content(); ?>
                              </div>
    
                              <div class="feed">
                                <p>Share On</p>
                                <a href="#" class="tw_sml"></a>
                                <a href="#" class="in_sml"></a>
                                <a href="#" class="gp_sml"></a>
                                <a href="#" class="fb_sml"></a>
                              </div>
    
                             <?php endwhile; else: ?>
                             <p>Sorry, no posts matched your criteria.</p>
                         <?php endif; ?>

    Please help! Thank you-

Viewing 13 replies - 1 through 13 (of 13 total)
  • I’m not so hot with php but it looks like this stuff msy need to be in there:

    div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    					<div class="entry">

    possibly right before the_content?

    Also take note that there are plugins which can exclude categories conditionally.

    Thread Starter etoddt

    (@etoddt)

    Thank you Deepbevel – I added that code before the <div class=”entry”> tag like you suggested –

    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                                <?php the_content(); ?>
                              </div>

    But all permalinks still point to the same page. It’s like the <a href="<?php the_permalink() ?>"...> part is linking to a category instead of the full article. It’s odd –

    I’ll try this plugin route you mention – Do you recommend any plugin in particular?

    Thread Starter etoddt

    (@etoddt)

    I found the error. I had also included a loop in the sidebar that was scripted to only include one category of posts – the same category that all my articles were erroneously linking to before. Once removed, that fixed the linking problem.

    However, that creates another concern – Can I not have multiple loops running in different spots on my website (say the index.php and sidebar.php) without conflicts?

    Thanks deepbevel – I’ll try this Exclude Categories plugin and see how it goes.

    check this out:
    two-loops

    Thread Starter etoddt

    (@etoddt)

    Thanks Deepbevel – I checked that link out you send and I think that is exactly what I’m looking to do.

    But… I didn’t see how it’s implemented anywhere. What confuses me a bit is the “posts set in admin” part. How does one set up posts in the admin? Is there an option to loop things in the dashboard? I’ve always just used the regular loop on the index.php page.

    Any help has been much appreciated!

    I haven’t tried it yet, you might ask the user who started the thread, although they won’t reveal the site yet.

    I assumed it was simply a matter of assigning the category to the new loop, the posts in that category should show up in it. t

    “To specify category, add:

    &category_name=xxx

    right after =5 in my example above “

    Then I would think the post loop shows up whereever you put the code.

    Thread Starter etoddt

    (@etoddt)

    Wait – I think what you’re saying is there’s an option in the admin to limit how many posts the index.php page displays, right?

    I’m still not sure how the code in the second loop is supposed to be different – right now any loop I put in there duplicates the posts from first loop..

    the number of posts can ussually be specified in code, the other member who found the code was able to specify 5 posts. Otherwise if you specify a category, it won’t show posts that are not in that category. maybe I don’t understand what you want to do..?

    Truth is I’m still a bit confused as to why this is needed, seems a category page/widget would show the most recent posts in a specified category, like having it’s own loop.

    Thread Starter etoddt

    (@etoddt)

    Solved the issue with a plugin – and lots of CSS.

    So, I found a plugin that lets you select a specific Category and display its contents: http://wordpress.org/extend/plugins/category-posts/

    This solution allows me to exclude a category from my main loop using the <?php query_posts($query_string . '&cat=-8'); ?> code immediately before my main loop.

    Then I use the plugin I installed above to show the category I excluded in the sidebar. This way I can display separate categories in two separate areas while keeping everything as a post in WP Dashboard.

    Thanks for the assists Deepbevel – your suggestions ultimately pointed me in the right direction. πŸ™‚

    Merry Christmas!

    geez, if I’d only known that’s all you needed. All this tech talk takes me away from what I know about WP sometimes! haha! I’m such a hack.

    Comment about the first code. The error is going because you didn’t reset the query. This is a frequent mistake. If you have more than one query at one time, always use wp_reset_query() to prevent queries interferences like you described.
    http://codex.wordpress.org/Function_Reference/wp_reset_query

    Nice call! That’s one I might have noticed too had I been on my toes, I use similar code for a simliar purpose and had that issue before.

    Thanks!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘All Permalinks pull up the same page…’ is closed to new replies.