Wordpress Themes - WP Forum at BFA
Click here to register or to donate.
Auto self-registration is not available here - far too many spammers. This forum has many, many backlinks and because of that there is an intense desire among spammers to drop their links here.

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme » Center area post/pages »

[SOLVED] How to create category pages


  #1  
Old Jun 16, 2010, 09:43 AM
glb9235
 
3 posts · Feb 2010
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.
  #2  
Old Jun 16, 2010, 01:42 PM
juggledad's Avatar
juggledad
 
23,655 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
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.
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #3  
Old Jun 16, 2010, 01:50 PM
glb9235
 
3 posts · Feb 2010
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.

Last edited by glb9235; Jun 16, 2010 at 01:58 PM.
  #4  
Old Jun 16, 2010, 03:16 PM
Jeff G
 
39 posts · Mar 2010
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!
  #5  
Old Jun 16, 2010, 08:53 PM
lmilesw's Avatar
lmilesw
 
10,174 posts · Jul 2009
Central New York State USA
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.
__________________
~Larry (CNY Web Designs)
This site should be a membership site since it so full of good stuff.
Please consider donating which gives you access to even more good stuff.
  #6  
Old Jun 17, 2010, 06:52 AM
glb9235
 
3 posts · Feb 2010
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;
?>

Last edited by glb9235; Jun 17, 2010 at 07:31 AM.
  #7  
Old Jun 17, 2010, 09:12 AM
lmilesw's Avatar
lmilesw
 
10,174 posts · Jul 2009
Central New York State USA
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.
__________________
~Larry (CNY Web Designs)
This site should be a membership site since it so full of good stuff.
Please consider donating which gives you access to even more good stuff.

Bookmarks

Tags
categories, page2cat, pages

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to create links in posts and pages lmt Center area post/pages 8 Jan 22, 2010 08:57 PM
How to Create a Title Category? lee07666 Page & Category Menu Bars 12 Sep 28, 2009 05:43 AM
Create new category bar with custom includes backstpub Page & Category Menu Bars 0 Aug 25, 2009 04:32 PM
Please help: want to create fixed image for top of each category page WebWeaver Atahualpa 3 Wordpress theme 4 Jun 18, 2009 09:56 AM
[SOLVED] Where are the Pages I create in Atahualpa, stored on the file index configur Leoni Atahualpa 3 Wordpress theme 2 Jun 11, 2009 08:08 PM


All times are GMT -6. The time now is 08:13 PM.


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