Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Center area post/pages (http://forum.bytesforall.com/forumdisplay.php?f=32)
-   -   [SOLVED] How to create category pages (http://forum.bytesforall.com/showthread.php?t=7612)

glb9235 Jun 16, 2010 09:43 AM

[SOLVED] How to create category pages
 
Thought I would post this, since I spent hours looking for a solution before I solved it. I was looking for any way to create a page where certain content was on the top (sticky or otherwise), and allow posts to populate it from a specific category. I didn't want just a list of post titles, I wanted the full posts. Here's my fix. I edited the page2cat.php from this plugin:

http://pixline.net/wordpress-plugins/category-page-wordpress-plugin/en/


Here was the original function:
Code:

function page2cat_content_catlist($content){
global $post;
        if ( stristr( $content, '[catlist' )) {
                $search = "@(?:<p>)*\s*\[catlist\s*=\s*(\w+|^\+)\]\s*(?:</p>)*@i";
                if        (preg_match_all($search, $content, $matches)) {
                        if (is_array($matches)) {
                                $title = get_option('p2c_catlist_title');
                                if($title != "") $output = "<h4>".$title."</h4>"; else $output = "";
                                $output .= "<ul class='p2c_catlist'>";
                                $limit = get_option('p2c_catlist_limit');
                                foreach ($matches[1] as $key =>$v0) {
                                        $catposts = get_posts('category='.$v0."&numberposts=".$limit);
                                                foreach($catposts as $single):
                                                $output .= "<li><a href='".get_permalink($single->ID)."'>".$single->post_title."</a></li>";
                                                endforeach;
                                        $search = $matches[0][$key];
                                        $replace= $output;
                                        $content= str_replace ($search, $replace, $content);                                       
                                }
                        $output .= "</ul>";
                        }
                }
        }
return $content;
}

Change this:
Code:

                                        foreach($catposts as $single):
                                                $output .= "<li><a href='".get_permalink($single->ID)."'>".$single->post_title."</a></li>";
                                                endforeach;

To this:
Code:

                                                foreach($catposts as $single):
                                                $excerpt = $single->post_content;
                                                $output .= "<li><a href='".get_permalink($single->ID)."'>".$single->post_title."</a></li><p>".$excerpt."</p>";
                                                endforeach;

Thats it! I fiddled around a lot so if there was something else I changed and yours doesn't work, let me know.

juggledad Jun 16, 2010 01:42 PM

glb9235: make sure to see what happens when you go to a second page (change teh number of posts per page to easily test it.) I tryed playing with page2cat at one point and it kept restarting the posts from the beginning on each new page.

glb9235 Jun 16, 2010 01:50 PM

Hmm, that did seem to cause problems. Mine didn't create pages at all, just cut off after a certain number of posts. Any ideas?

I had forgotten to mention I added this to the functions.php file:

Code:

function neat_trim($str, $n, $delim='...') {
$str = str_replace("\n","",$str);
$str = strip_tags($str);
  $len = strlen($str);
  if ($len > $n) {
      preg_match('/(.{' . $n . '}.*?)\b/', $str, $matches);
      return rtrim($matches[1]) . $delim;
  }
  else {
      return $str;
  }
}

Edit: Extending it to 25 posts is an option in the plugin settings.

Jeff G Jun 16, 2010 03:16 PM

Hmm. I really want to be have page links from page menu navigation correspond to some categories of posts: is the above the only way to do this??

That seems very complicated, but maybe I'm not understanding what glb9235 was actually accomplishing. Already, I have this:

http://endthelockout.org/

That second line is, of course, the categories. All I really want to do is integrate those into the page menu bar. Do I need to edit the code as glb9235 has done, or is there an easier solution?

<<crossing fingers>>

Thanks so much for any assistance!

lmilesw Jun 16, 2010 08:53 PM

Did you ever look at the List Category Posts plugin? This uses a shortcode with plenty of variables. One of which is to show entire post.

glb9235 Jun 17, 2010 06:52 AM

Quote:

Did you ever look at the List Category Posts plugin? This uses a shortcode with plenty of variables. One of which is to show entire post.
Thats it! I can't believe I searched so hard and wasn't able to find a plugin that does exactly what I wanted.

Jeff: You can use the plugin mentioned above to do this, or use the Page Links To plugin to put links to your category pages on the page menu bar.

Edit:

I was able to tweak the List Category Posts plugin template to work with atahualpa. It now uses mostly the same formatting as you set for normal posts - with header, byline, and body. Thought it might be useful.

Code:

//Posts loop:
foreach($catposts as $single):
        $output .= '<div class="post"><div class="post-headline"><h2><a href="' . get_permalink($single->ID) . '">' . $single->post_title . '</a></h2></div>';
        //Style for date:
        if($atts['date']=='yes'){
                $output.= ' <div class="post-byline"> ' . get_the_time($atts['dateformat'], $single) .'</div>';
        }
        //Show author?
        if($atts['author']=='yes'){
                $lcp_userdata = get_userdata($single->post_author);
                $output.=' <div class="post-byline"> ' .$lcp_userdata->display_name .'</div>';
        }
        //Show content?
        if($atts['content']=='yes' && $single->post_content){
                $lcpcontent = apply_filters('the_content', $single->post_content); // added to parse shortcodes
                $lcpcontent = str_replace(']]>', ']]&gt', $lcpcontent); // added to parse shortcodes
                $output.= '<div class="post-bodycopy clearfix">' . $lcpcontent . '</div>'; // line tweaked to output filtered content
        }
        //Show excerpt?
        if($atts['excerpt']=='yes' && $single->post_excerpt && !($atts['content']=='yes' && $single->post_content) ){
                $output .= '<div class="post-bodycopy clearfix">' . $single->post_excerpt . '</div>';
        }
        $output.='</div>';
endforeach;
?>


lmilesw Jun 17, 2010 09:12 AM

Sometimes they are illusive and keyword searches don't always work. I find some plugins in unusual places and I spend WAY TOO MUCH TIME on the computer. But wait... That's what I do to make a living. Glad it worked for you.


All times are GMT -6. The time now is 03:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.