• Resolved SeaBerGBer

    (@seabergber)


    I am trying to have category pages that display only one category of post. I realize this has been brought up many times but there always seems to be a different answer and none of them seem to be working. I have successfully done this on another theme in the past and my new one is not behaving the same at all. I made a new template file and copied my index information into it. The index code looked like this:

    <?php get_header() ?>
    
      <section class="section" role="main">
    
        <?php echo ace_breadcrumb(); ?>
    
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
          <?php get_template_part('loop'); ?>
    
        <?php endwhile; ?>
    
          <section class="pagination">
            <p><?php echo get_pagination_links(); ?></p>
          </section>
    
        <?php else : get_template_part('none'); endif; ?>
    
      </section><!-- .section -->
    
      <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>
Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter SeaBerGBer

    (@seabergber)

    In the past, adding this before the loop worked. Now it won’t.

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php the_content(); ?>
    <?php endwhile; endif; ?>
    
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'category_name' => 'Real Colorado Weddings',
    	'paged' => $paged
    );
    query_posts($args);
    ?>

    Assuming that code works, the query_posts() must come before the loop.

    In addition to that, it’s better to use category-slug instead of the name
    https://codex.www.ads-software.com/Function_Reference/query_posts#All_Posts_in_a_Category

    Thread Starter SeaBerGBer

    (@seabergber)

    I should say that code worked for my old theme. I’m completely clueless what to do with the new one.

    Could you please be a bit more specific on what exactly you’re trying to do ?

    1. Limit the front home listing page to display only posts from one category.
    2. Make one certain page to display list of posts from one category.

    Or else ?

    Thread Starter SeaBerGBer

    (@seabergber)

    Make one certain page to display a list of posts from one category. I have it working with my old theme but I have no clue what to add to this code to get it to work now.

    I have created a template file with the template name coding at the top and then copied the index code into it after the template name. Now I’m stuck. =/

    Does the permalink matter ? If not, WP builds all the archive pages automatically, you can just make a link to it using this pattern.

    https://example.com/category/my-cat-slug

    In case you want content in that category archive page display different from others, make another copy of category.php and rename the copy with category-slug.php, where slug is that category’s slug, and make changes in it.

    If it must be a page template, can you please post the whole code ( maybe using pastebin ) of that template along with loop.php so we can see what’s goin on.

    Thread Starter SeaBerGBer

    (@seabergber)

    Oh man. That is a million times easier than what I was trying to do. Even worse, the newer versions of WordPress seem to let you create category links on the menu that can be named whatever you want. I think one of the reasons I had to do this the hard way before was that I wanted the title on the menu to be different from the category name. I wish I would have looked at the menu customization area of the dashboard again before wasting 2 days on this. Thank you so much for alerting me to this. I feel like a class A idiot. *SMH*

    Thread Starter SeaBerGBer

    (@seabergber)

    RESOLVED

    Actually, this kind of thing happens to all of us at some point ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Single Post Type’ is closed to new replies.