ThemeShaper Forums » Thematic

[closed]

Adding Custom (static) Category Info to 40+ Category pages

(21 posts)
  • Started 4 years ago by rpeterika
  • Latest reply from rpeterika
  • This topic is resolved
  1. Wordpress/Thematic Trial-by-fire... unfortunately I'm starting to get burned.

    http://www.ekisticsdesignstudio.com is the website

    Here is my problem, generally:
    I would like for a bunch of category archive pages to have descriptions and images before the posts, and a list of things after the posts. From what I understand, I can use hooks to insert info into these locations, though I don't really know how (or what I have tried has worked). The secondary issue here is that there will be 40+ different category archive pages, each with different descriptions, images, and lists.

    Inserting text in the category description works partially, but it seems I can't put HTML in that or include pictures. This doesn't solve the problem of including the list after the posts.

    Our goal is to: Go to a category archive, read a description of the category and see some pictures explaining the concept, scroll down and see posts categorized in that category, and then scroll down further for a list of projects that don't have posts associated to them (as in they don't deserve a whole post, but we want to show the list). Then go to another category archive and do it all again with different information.

    What I don't understand:
    1) How can I call "post-like" information before posts in the category archives
    2) How can I call "post-like" lists after the posts in category archives
    3) How do I store this "post-like" information in the database? Can I?
    4) PHP, totally foreign, but copy-pasting and find-replacing is doable...

    I've tried my best to explain the problem, based on the comments from some users I think this is an easy thing to do - just a little too much for me.

    Thanks in advance, RP

    Posted 4 years ago #
  2. I have setup up a child theme, tweaked CSS and some PHP to remove some unnecessary functionality. I feel like I'm staring at this stuff in content-extensions.php, I just don't know how to change it.

    To clarify, when I say "post-like" I mean static content.

    Posted 4 years ago #
  3. a while back Ridgely posted some cool stuff about using the page title function to kick out category names and descriptions. maybe that could help?

    http://forums.themeshaper.com/topic/tip-modify-thematic-page-title

    Posted 4 years ago #
  4. '$content .= '<div class="archive-meta">';/*Begin Category Description*/
    if ( !(''== category_description()) ) : $content .= apply_filters('archive_meta', category_description()); endif;
    $content .= '</div></div>' . "\n"; /*End description and close encompassing div*/'

    It seems like this section would start to do what I'm trying to do but I don't think (or haven't been able to) insert html/images into the category description.

    Is there a way that I could have some phantom posts and call the entry-content as the top description and call the excerpt as the list, maybe? Just brainstorming on potential workarounds...

    Posted 4 years ago #
  5. Sorry the code entry part didn't work...

    Posted 4 years ago #
  6. what about this plugin:
    http://wordpress.org/extend/plugins/category-images/

    in the documentation is says you can return the results instead of echoing them. you could then add the returned variable from this plugin to the $content variable from above. i think that would work? also sounds really cool... you should post your code when you get it working.

    Posted 4 years ago #
  7. Started me on the right track... found another plugin called "category meta"
    http://wordpress.org/extend/plugins/wp-category-meta/

    Seems a little more flexible

    Added two image metas and one list meta, now to take it for a test drive...

    Posted 4 years ago #
  8. it was so weird and timely that you posted this today. i have a project where it looks like i am going to be using categories as sub-sites.

    check this out... i think it could be helpful:
    http://www.strangework.com/2010/07/01/how-to-save-taxonomy-meta-data-as-an-options-array-in-wordpress/

    Posted 4 years ago #
  9. Yes, but now how do I call that featured post?

    Posted 4 years ago #
  10. huh?

    Posted 4 years ago #
  11. From what I understand about the taxonomy meta data plugin is that you can set a featured post to the category. So I am trying to figure out how to call the post content of that featured post once you are in the category archive.

    I'm assuming you have reviewed the code from the last link...

    //test spot...
    				tme_save_featured($term_id);
    				echo $current_featured;
    				?>Current Featured ^
                    <?php echo $category_featured;
    				?>Category Featured ^
                    <?php echo $term_id;
    				?>Term ID ^ 
    
                    <?php
    				$queried_post = get_post($category_featured);
    				$content = $queried_post->post_content;
    				$content = apply_filters('the_content', $content);
    				$content = str_replace(']]>', ']]>', $content);
    				echo $content;

    With this chunk of frankensteined code I am doing a couple of things... trying to see if the plugin is assigning any values to those three terms at the top, which if it is I'm not calling the values right.

    Also I trying to the the post content of that featured post, but instead I get the content of the one post that falls under this category.

    I've almost spent all day trying to figure this out now... almost there too...

    Posted 4 years ago #
  12. well if you have that posts ID number then you can can the_title($id) and the_content($id) inside the loop that $id variable defaults to whatever post is currently being handled by the loop, but outside the loop you can feed it a post ID number.

    i know what you mean about spending the day on something. i just finished a brutal slider with all kinds of ridiculous functionality about what goes IN the slider. phew. time for a break. good luck. and definitely let me know how it goes. i think i need category meta next.

    Posted 4 years ago #
  13. Getting closer... real close actually!

    So using this chunk:

    <?php
    				$args=array(
    				   'post_type'=>'post',
    				   'post__in' => array($category_featured)
    				);
    				$the_query = new WP_Query($args);
    				?>
    
                     <?php
    				 $taxo_meta_post = get_posts('$the_query');
    				 foreach($taxo_meta_post as $post) :
    					setup_postdata($post);
    				 ?>
    				 <?php the_content(); ?>
    				 <?php endforeach;
    				 wp_reset_query();

    I've been able to call the content of the featured post (per taxonomy meta ID)! SUCCESS! But, it also calls the content from other random posts (The latest posts I think), and only three...

    Do you know how I can echo the array($category_featured)? (I'd like to inspect the query)
    or Have a suggestion on why the other content is being shown?

    Thanks for all your help so far... with your suggestions I've really leaped forward in code comprehension!

    Posted 4 years ago #
  14. False alarm, not working yet, it is just calling the content of the latest posts... I made another page and it call that featured content and then the previous featured content and then the other posts...

    Not there yet.

    Posted 4 years ago #
  15. if you are in a template you can just print_r($array) with whatever the array is called to see its full contents. sometimes i also do this

    function test_stuff(){
      echo "bacon!" . $variable_i_want_to_inspect ;
      print_r($suspicious_array);
    }
    add_action('thematic_before','test_stuff');

    does the tax meta plugin explain how to get the ID for that featured post?

    also your chunk of code is a little suspect. i dont know if this will fix it, but you either use a new WP_Query OR get_posts, not both. and in this situation it is better to use get posts and not monkey w/ the regular query.

    $args=array(
       'post_type'=>'post',
       'post__in' => array($category_featured)
    );
    
    $taxo_meta_post = get_posts('$args');
    	foreach($taxo_meta_post as $post) :
    	  setup_postdata($post);
    	  the_content();
            endforeach;

    be sure to echo out $category_featured somewhere so that you can see what kind of info is in that variable. it might not be what you expect

    Posted 4 years ago #
  16. print_r($category_featured) isn't giving me anything, which may be related to the fact that the tax meta plugin DOESN'T explain how to call that ID. I made a guess that I could call the array(category_featured) based on the notes, but it isn't showing "449" or similar (as I should expect).

    I even checked the database to see if a value was written and I can't find a related number other than object_id. The Category Meta plugin wrote new database values for "image1" and "proj-list" (that I created)

    Here is what the language is...

    As you can see we are saving the Category ID and Featured Post ID as a single associative array option value in WordPress named category_featured. As you add Featured Post ID values to each of your categories they will be added to this array and saved in WordPress.

    Now that I just read that again, maybe what I need to do is to setup a conditional if category_ID is equal to this_category then get_posts(featured_post_ID). Now I need to figure out how to do that...

    The investigation continues.

    Posted 4 years ago #
  17. OK, found the database value in the wp_options table, just like Brad said:

    I’m going to save that meta data (the ID in this case) as a single array of options in the WordPress options table.

    And this is the value for "category_featured":
    a:3:{i:7;i:442;i:101;i:449;i:14;i:0;}

    Reality check!
    category ID 7 does have featured ID of 442... looks good compared to "i:7;i:442"
    category ID 101 does have featured ID of 449... looks good compared to "i:101;i:449"
    category ID 14 does have featured ID of 0... I didn't enter anything in that category

    So my worry that the data wasn't being stored is extinguished. Back to calling the array correctly...

    I don't know what the a:3: means though?

    Posted 4 years ago #
  18. how are you defining $category_featured in your function? you have to give it a value or you will end up with the empty array... as denoted by print_r being blank. print_r should should data similar to what is in the database. that at least does tell us that the info is going into the db, now you need to get it out. it is in the options table?

    if you add this to the function i showed you before to echo things to thematic_before just to test them out.

    $test = get_option('category_featured');
    print_r($test);

    do you get some data?

    Posted 4 years ago #
  19. Print_r worked this time, exactly as you have it above ^. I didn't understand what how to set up the variables the first time you mentioned the print_r function.

    I am able to get the "Featured post" out of the database by being on the corresponding category archive, but now I'm stuck on calling that single featured Id post content.

    <?php
    
    				// Get the category id of this archive, as an integer
    				foreach(get_the_category() as $category)
    				{ $thecat = $category->cat_ID; }								 
    
    				// Find the corresponding featured post for $thecat
    				$tax_meta = get_option( 'category_featured' );
    				$tax_meta_id = $tax_meta[$thecat];
    				echo $tax_meta_id;
    
    				// Add the post content of the feature post
    				$tax_meta_content = get_post($tax_meta_id);
    
    				foreach($tax_meta_content as $post) :
       				setup_postdata($post);
    
    				the_content(); 
    
    				endforeach;
    
    				// Display the content of the category_featured array
    				$test = get_option('category_featured');
    				print_r($test);
    
    				?>

    What I get with this code is:

    442Array ( [7] => 442 [101] => 449 [14] => 0 )

    442 is the associated feature_id, good. Array prints and looks good. But the content for post 442 didn't get shown in between those two functions.

    This only works on archives with categorized posts. If no posts exist within that archive then the post foreach function has a fatal error.

    I'll continue troublsehooting

    Posted 4 years ago #
  20. Got it working!

    <?php
    
    	// Get the category id of this archive, as an integer
    		$thecat = get_query_var('cat'); //works!
    
            // Find the corresponding featured post for $thecat
    		$tax_meta = get_option( 'category_featured' );
    		$tax_meta_post_id = $tax_meta[$thecat]; //works!
    
    	// Add the post content of the feature post
    		$tax_meta_post = get_post($tax_meta_post_id);
    		$tax_meta_content = $tax_meta_post->post_content;
    		echo $tax_meta_content; 
    
    ?>

    The whole time I forgot to echo the featured post content!

    Thanks again for all your help!

    One problem I still have is that the featured post content isn't formatted the same the post... any ideas on how to adjust this?

    Posted 4 years ago #
  21. In review:

    Using the Taxonomy Meta plugin linked above, I set a featured post for each category archive and created a post for each category archive meta content.

    Then, in category.php I inserted the code from the post above.

    Now my category archives have post content associated with each archive (though the formatting is still unresolved)

    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.