• Alright, this is quite the task that I need to accomplish, so please let me know if you can help me on this.

    I have a dog website, https://www.thecaninedirectory.com, which is just a directory of all dog breeds (incomplete so far).

    Within the site, I want to categorize the dog breeds by AKC (American Kennel Club) breeds. So I have pages like https://www.thecaninedirectory.com/akc-group/hound-group, and similar to the other 6 categories.

    As I’ve created posts, I’ve been categorizing the dog into one of the 7 groups.

    Now what I want to do, is have on this page, https://www.thecaninedirectory.com/akc-group/hound-group, a list of all posts under the category “Hound”.

    On the homepage, I like the way that the recent posts are organized, and I would like to have the categories displayed in the same way on https://www.thecaninedirectory.com/akc-group/hound-group.

    I know that the homepage is using some sort of “limit posts” plugin to organize the content like that, I just don’t know how to get it to display all posts under a certain category under the “hound group” page.

    This is the code for the limitpost plugin:

    <?php
    /*
    Plugin Name: Limit Posts
    Plugin URI: https://labitacora.net/comunBlog/limit-post.phps
    Description: Limits the displayed text length on the index page entries and generates a link to a page to read the full content if its bigger than the selected maximum length.
    Usage: the_content_limit($max_charaters, $more_link)
    Version: 1.1
    Author: Alfonso Sánchez-Paus Díaz y Julián Simón de Castro
    Author URI: https://labitacora.net/
    License: GPL
    Download URL: https://labitacora.net/comunBlog/limit-post.phps
    Make:
        In file index.php
        replace the_content()
        with the_content_limit(1000, "more")
    */
    
    function the_content_limit($max_char, $more_link_text = 'Read&rarr;', $stripteaser = 0, $more_file = '') {
        $content = get_the_content($more_link_text, $stripteaser, $more_file);
        $content = apply_filters('the_content', $content);
        $content = str_replace(']]>', ']]>', $content);
        $content = strip_tags($content,'');
    
       if (strlen($_GET['p']) > 0) {
          echo "<p>";
          echo $content;
          echo "&nbsp;<a href='";
          the_permalink();
          echo "'>"."Read More &rarr;</a>";
          echo "</p>";
       }
       else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
            $content = substr($content, 0, $espacio);
            $content = $content;
            echo "<p>";
            echo $content;
            echo "...";
            echo "&nbsp;<a href='";
            the_permalink();
            echo "'>".$more_link_text."</a>";
            echo "</p>";
       }
       else {
          echo "<p>";
          echo $content;
          echo "&nbsp;<a href='";
          the_permalink();
          echo "'>"."Read More &rarr;</a>";
          echo "</p>";
       }
    }
    
    ?>

    This is the code for the Archives page

    <?php get_header(); ?>
    <?php get_sidebar(); ?>
    <div id="content">
    
    <?php if (have_posts()) : ?>
    
    		 <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
    <?php /* If this is a category archive */ if (is_category()) { ?>
    		<h2 class="pagetitle">‘<?php echo single_cat_title(); ?>’ Category</h2>
    
     	  <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
    		<h2 class="pagetitle">Archive for <?php the_time('F jS, Y'); ?></h2>
    
    	 <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
    		<h2 class="pagetitle">Archive for <?php the_time('F, Y'); ?></h2>
    
    		<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
    		<h2 class="pagetitle">Archive for <?php the_time('Y'); ?></h2>
    
    	  <?php /* If this is an author archive */ } elseif (is_author()) { ?>
    		<h2 class="pagetitle">Author Archive</h2>
    
    		<?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
    		<h2 class="pagetitle">Blog Archives</h2>
    
    		<?php } ?>
    
    		<?php while (have_posts()) : the_post(); ?>
    
    <div class="single" id="post-<?php the_ID(); ?>">
    <div class="title">
    
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    
    </div>
    <div class="date"><span class="author">Posted by <?php the_author(); ?></span> <span class="clock"> On <?php the_time('F - j - Y'); ?></span><span class="comm"><?php comments_popup_link('ADD COMMENTS', '1 COMMENT', '% COMMENTS'); ?></span>	</div>	
    
    <div class="cover">
    <div class="entry">
    
    <?php if(function_exists('the_content_limit')) { ?>
    <?php the_content_limit(350);  ?>
    <?php } else { ?>
    <p> Activate the limitpost plugin to see the post contents ! </p>
    <?php } ?> 
    
    <div class="clear"></div>
    
    </div>
    
    </div>
    
    <div class="singleinfo">
    
    <div class="category">categories: <?php the_category(', '); ?> </div>
    
    </div>
    
    </div>
    		<?php endwhile; ?>
    
     <div id="navigation">
    		<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
    </div>
    
    	<?php else : ?>
    
    		<h1 class="title">Not Found</h1>
    		<p>Sorry, but you are looking for something that isn't here.</p>
    
    	<?php endif; ?>
    
    </div>
    
    <?php get_footer(); ?>

    Hopefully i gave enough information to solve this problem, and I will be most grateful for anyone that can help me with this.

    Please let me know of anything I can do in return for whoever solves this.

    thanks!
    -Luke

Viewing 12 replies - 1 through 12 (of 12 total)
  • display all posts

    All posts under a certain category? or,
    All content of each post under a certain category?

    If you mean ‘All posts under a certain category’,
    create ‘page-hound-group.php’ and write below code.

    <?php get_header(); ?>
    <?php get_sidebar(); ?>
    <div id="content">
    <?php
     query_posts('cat=467&showposts=-1');
     if (have_posts()) :
      while(have_posts()) :
        the_post();
    ?>
     /* write here the rest of your code */
    <?php
      endif;
      wp_reset_query();
    ?>
    </div>
    <?php get_footer(); ?>

    If you mean ‘All content of each post under a certain category’,
    create ‘page-hound-group.php’ and paste your all code.
    And use
    <?php the_content(); ?>
    instead of

    <?php if(function_exists('the_content_limit')) { ?>
    <?php the_content_limit(350);  ?>
    <?php } else { ?>
    <p> Activate the limitpost plugin to see the post contents ! </p>
    <?php } ?>

    If I understand the problem correctly, you want the akc-group/hound-group page to display posts in the Hound category.

    The simplest way I know to do that is to use the Page Links To plugin.

    1. Install and activate the plugin. It will add a new section to the bottom of the Add/Edit Page screen.
    2. Edit the page you want to display a category.
    3. Scroll down to the ‘Page Links To’ section at the bottom.
    4. In the ‘Point to this URL’ box, enter ‘https://yoursiteurl/?cat=14&#8217;, replacing yoursiteurl with your own URL, and 14 with the category id you want that page to display.
    5. Click ‘Update Page’.

    That should be all you need.

    Thread Starter lukafer2

    (@lukafer2)

    Thank you very much Kz and vtxyzzy!

    So Kz, I want to do the first option that you gave me. In the first code, what code should I put where you wrote “/* write here the rest of your code */”? And how does that code know display the “hound category”?

    Thanks you very much for your help
    -Luke

    One caution, if you follow the approach Kz gave, you will need to create a new file for every category. That isn’t especially hard after you do the first one, but I think it is extra work.

    If you use the Page Links To plugin, you only need to add the URL to each of your category pages.

    /* write here the rest of your code */

    lines from 30 to 67 of the code for the Archives page on your first post.

    Thread Starter lukafer2

    (@lukafer2)

    Alright so my code now looks like this on the page-hound-group.php:

    <?php get_header(); ?>
    <?php get_sidebar(); ?>
    <div id="content">
    <?php
     query_posts('cat=467&showposts=-1');
     if (have_posts()) :
      while(have_posts()) :
        the_post();
    ?>
     <div class="single" id="post-<?php the_ID(); ?>">
    <div class="title">
    
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); 
    
    ?></a></h2>
    
    </div>
    <div class="date"><span class="author">Posted by <?php the_author(); ?></span> <span class="clock"> On <?php the_time('F - j - Y'); 
    
    ?></span><span class="comm"><?php comments_popup_link('ADD COMMENTS', '1 COMMENT', '% COMMENTS'); ?></span>	</div>	
    
    <div class="cover">
    <div class="entry">
    
    <?php if(function_exists('the_content_limit')) { ?>
    <?php the_content_limit(350);  ?>
    <?php } else { ?>
    <p> Activate the limitpost plugin to see the post contents ! </p>
    <?php } ?> 
    
    <div class="clear"></div>
    
    </div>
    
    </div>
    <?php
      endif;
      wp_reset_query();
    ?>
    </div>
    <?php get_footer(); ?>

    But for some reason when I go to https://thecaninedirectory.com/akc-group/hound-group/, I get this message:

    Parse error: syntax error, unexpected T_ENDIF in /home/content/s/a/m/samhancock24/html/thecaninedirectory/wp-content/themes/splendour/page-hound-group.php on line 34

    I really do apologize for my lack of knowledge on this topic, and I really do appreciate you helping me, but do you know how I can solve that problem?

    I have a feeling I put the code in wrong, but I’m not sure where i messed up.

    Thank you very much
    -Luke

    use

    <?php
      endwhile;
      endif;
      wp_reset_query();
    ?>

    instead of

    <?php
      endif;
      wp_reset_query();
    ?>

    Thread Starter lukafer2

    (@lukafer2)

    Wow you are a genius! It is now displaying the posts, but for some reason they keep going further and further to the right. You can see from this page: https://thecaninedirectory.com/akc-group/hound-group/

    Also do you know how I can get it display a picture of the dog like it does on the homepage…If not that’s perfectly fine, you’ve already done a lot for me.

    Thank you very much
    -Luke

    I don’t want to offend anyone, but you really should try the plugin I suggested. I think it will solve your problems.

    Thread Starter lukafer2

    (@lukafer2)

    I looked in to trying that plugin, but it seemed like it would just redirect to the category page. I’m looking for something where I can just display the categories differently on a certain page

    OK – I guess I misunderstood what you wanted. Good luck!

    I have one other suggestion. If you hard-code the category into the template, you will need a separate templage for each category. If you want to use one template, you can make the changes below. This will let you put a Custom Field called ‘category-to-show’, with a value of the category name, in a page and then use the one template.

    From what I can see, you should change this:

    <?php
     query_posts('cat=467&showposts=-1');
     if (have_posts()) :

    to this:

    <?php
    $this_cat=get_post_meta($post->ID,'category-to-show',TRUE);
    if ($this_cat == "") :
       echo "<h2>This page is missing the 'category-to-show' Custom Field</h2>";
    else;
       $args = array('showposts' => 1,
             'category_name' => $thiscat,
           };
       query_posts($args);
       if (have_posts()) :

    and change

    <?php
      endwhile;
      endif;
      wp_reset_query();
    ?>

    to this

    <?php
      endwhile;
      endif;
      endif;
      wp_reset_query();
    ?>

    This will let you add new categories as needed without modifying the template.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Category Display (HELP!!)’ is closed to new replies.