ThemeShaper Forums » Thematic

[closed]

Posts inside the Pages and subpages

(56 posts)
  • Started 4 years ago by oscar
  • Latest reply from amoore
  • This topic is resolved
  1. I wanna put Posts inside the pages and, point pages like category. Is it possible ?
    What´s the best and easier way to do it ??

    www.claudiawalesko.com.br/blog and www.oscar.fot.br/blog

    thanks a lot

    Posted 4 years ago #
  2. Create a file in your child theme directory name it whatever you like just make it end with .php
    example: my-page-cat-query.php inside this file paste this code:

    <?php
    /*
    Template Name: Category Query Page Template
    */
    include( TEMPLATEPATH . '/index.php' ); //this loads the thematic parent framework index.php
    ?>

    Now save the file and add this code to your child theme functions.php

    function child_theme_custom_query() {
    
        	if (is_page('48')) { // change '48' to the id # of your page
    
    	$limit = get_option('posts_per_page');
        	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
            //change '4' to you category id # and change the value of $limit to the # of posts you want displayed per page
        	query_posts('cat=4' . '&showposts=' . $limit=2 . '&paged=' . $paged );
    
        	$wp_query->is_archive = true; $wp_query->is_home = false;
        	}
    }
    
    add_action('thematic_above_indexloop', 'child_theme_custom_query');

    Now log in to your sites WordPress admin area and edit your page to use the new custom template you saved earlier. Using my example code you should be looking for a template named ' Category Query Page Template' in the dropdown menu in the admin.

    That should do it. I will mention that this method still allows for the index-insert sidebar to show up on this new cat queried page.

    Posted 4 years ago #
  3. Em Hr,

    It was exactly what I needed !!!! THANKS A LOT BOY.
    But just one setting...How can I do to my new post not generate a new submenu and dropdown menu ??? And I want to make visible all previous posts in their respective pages.

    I will never stop to thank you !

    Oscar

    Posted 4 years ago #
  4. I'm glad it helped. I'm not really understanding what you're trying to do now. Can you give me a little more detail.

    -Gene

    Posted 4 years ago #
  5. EM HR,

    It´s ok, what you did. Exactly how I wanted.
    But, when I create a new post, the title of it appear like a new item in dropdown menu of the page. I don´t want its happen. In the category it can, but not in the page.
    Look at my test page www.oscar.fot.br/blog

    I created a post inside the [ABOUT], called [testando hr em], I want it appear above the post [ABOUT], and don´t create a dropdown menu. It´s possible ?

    I never get tired of you thank you !!

    Posted 4 years ago #
  6. It looks to me like you created a page [ABOUT] and then you created a page [testando hr em] which you have set to be a child page of [ABOUT] If you do not want it to be a child page of the [ABOUT] then log in to the WP admin and set the [testando hr em] page's "Attribute" of "Parent" to " Main Page(no parent)" That will make it appear as a top level menu list item and not in the submenu of [ABOUT]

    Posted 4 years ago #
  7. Gene,

    Now, I can tell you, with precision, what I need.
    I want put posts inside of the child pages. For example: I have a child pages [about] [documents] and [subject], when I writing of me, I want put this post inside the [about]. Another post I´ll write about philosophy, then I´ll put inside the [documents] and so...
    How can I do it ???

    Your Goodness is to light your way !

    thanxs a lot

    oscar

    Posted 4 years ago #
  8. I'm not exactly sure what your objectives are but if you want posts of one category to appear on your About Page then the method I demonstrated earlier will work.

    For example:

    Set the page template for the About page to the 'Category Query Page Template' template you created.

    All the posts you want to appear on the about page you will now assign a specific category. The id of the category you have chosen needs to be set in function child_theme_custom_query() and all should work well for you.

    This method might be overcomplicating things. Maybe a category archive is all you need? I hope this has helped. Keep on trying and you'll figure out what works best for you.

    -Gene

    Posted 4 years ago #
  9. Hi Gene,

    there are any way to put posts into of the page ??? This is what a need.
    The Category Query Page Template, allow me publish a new Page, but, I want put the Post into a Page.
    thanxs a lot

    oscar

    Posted 4 years ago #
  10. Put the function child_theme_custom_query() code in my example above into your functions.php in your child theme.

    First you will need to change if (is_page('48')) so that is uses the page id number of your About page. Here you will be replacing the number 48.

    then change query_posts('cat=4' . '&showposts=' . $limit=2 . '&paged=' . $paged ); so that 'cat=4' uses the category id of the posts you want on that page. Here you will be replacing the number 4.

    Once you have done those two things then the posts will appear on the About page if it is set to use the Category Query Page Template template you have created.

    Posted 4 years ago #
  11. Gene,

    now I´ll have a lunch. Later I´ll to do it what you told. However, I fell congratulated, so much, with you. Tell me, how can I pay you ? write me oscar.curitiba@gmail.com

    THANKS A LOT, YOU ARE THE GUY !

    Posted 4 years ago #
  12. Gene,
    I´m learning PHP whit you (my personal Master !!!), I understood what did you do. But, just one more question: This change made the posts appear in ABOUT page(id=2), and when I want put posts in another Page (documents) for example ??? What I have to do ?

    Thanks a lot

    oscar

    Posted 4 years ago #
  13. Yeah you could run an array through the function and automate this for many pages. In this example you dont need to change the function at all. Only change or add to the $custom_cat_query array. You'll need to set the Category Query Page Template for each page.

    $custom_cat_query=
    array(	
    
    	"about" => array(
      		"page-id"                => "2",   // Replace  the number 2 with your page id
      		"category-id"         => "2",   // Replace  the number 2 with your category id
      		"post-limit"            => "2",   // Replace the number 2 with the number of posts you want per page
      								  // --- or delete "post-limit"  line to default to WPAdmin "Reading Settings" option
      	),
    
      	// now you do the same for the next page repeat like above
      	// you can keep creating more arrays like this for more category-query pages
    
     	"documents" => array(
      		"page-id"             => "2",
      		"category-id"       => "2",
                    "post-limit"          => "2",
      	),
    
     );
    
    function child_theme_custom_query() {
    
      global $custom_cat_query;
    
      foreach($custom_cat_query as $value) {
        if (is_page($value['page-id'])) {
        if ($value['post-limit'] == "") $value['post-limit'] == get_option('posts_per_page');
        	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        	query_posts('cat='.$value['category-id'] . '&showposts=' . $value['post-limit'] . '&paged=' . $paged );
        	$wp_query->is_archive = true; $wp_query->is_home = false;
        	}
    	}
    }
    add_action('thematic_above_indexloop', 'child_theme_custom_query');

    We are all learning together around here.
    -Gene

    Posted 4 years ago #
  14. Hi Gene,

    sorry .. I couldn't resist. Question & Solution are too interesting :)

    This would be a solution using custom fields including a nice meta box:

    /*
    	Let's start with the additions for WP-Admin / Pages
    */
    
    /* Defining the custom fields that we need */
    $new_meta_boxes =
      array(
      "page_query_posts" => array(
      "name" => "page_query_posts",
      "type" => "checkbox",
      "std" => "false",
      "title" => "Should this page include any posts",
      "description" => "Check if yes"),
      "category" => array(
      "name" => "category",
      "type" => "text",
      "std" => "",
      "title" => "Category ID",
      "description" => "Please enter the Category ID"),
      "limit" => array(
      "name" => "limit",
      "type" => "text",
      "std" => "",
      "title" => "Limit to number of posts",
      "description" => "Please enter the max. number of posts")
    );
    
    /* Defining the look and feel of our new metabox */
    function new_meta_boxes() {
      global $post, $new_meta_boxes;
    
      foreach($new_meta_boxes as $meta_box) {
        $meta_box_value = get_post_meta($post->ID, $meta_box['name'], true);
    
        if($meta_box_value == "")
          $meta_box_value = $meta_box['std'];
    
    	echo'<input type="hidden" name="'.$meta_box['name'].'_noncename" id="'.$meta_box['name'].'_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';
    
       	switch ( $meta_box['type'] ) {
    		case 'text':
    			echo'<label style="font-weight: bold; display: block; padding: 5px 0 2px 2px" for="'.$meta_box['name'].'">'.$meta_box['title'].'</label>';
    
    			echo'<input type="text" name="'.$meta_box['name'].'" value="'.$meta_box_value.'" size="55" />';
    
    			echo'<label for="'.$meta_box['name'].'">'.$meta_box['description'].'</label>
    ';
    		break;
    
    		case 'checkbox':
    
    			echo'<input type="checkbox" name="'.$meta_box['name'].'"  value="true"';
    			checked('true', $meta_box_value);
    			echo' /> <label style="font-weight: bold; padding: 5px 0 2px 2px" for="'.$meta_box['name'].'">Contains Posts </label>
    ';
    		break;
    	}
      }
    }
    
    /* Once defined, we create the new metabox */
    function create_meta_box() {
      global $theme_name;
      if ( function_exists('add_meta_box') ) {
        add_meta_box( 'new-meta-boxes', 'Query Posts', 'new_meta_boxes', 'page', 'normal', 'high' );
      }
    }
    
    /* ... and we need to save our valuable data */
    function save_postdata( $post_id ) {
      global $post, $new_meta_boxes;
    
      foreach($new_meta_boxes as $meta_box) {
      // Verify
      if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) {
        return $post_id;
      }
    
      if ( 'page' == $_POST['post_type'] ) {
      if ( !current_user_can( 'edit_page', $post_id ))
        return $post_id;
      } else {
      if ( !current_user_can( 'edit_post', $post_id ))
        return $post_id;
      }
    
      $data = $_POST[$meta_box['name']];
    
      if(get_post_meta($post_id, $meta_box['name']) == "")
        add_post_meta($post_id, $meta_box['name'], $data, true);
      elseif($data != get_post_meta($post_id, $meta_box['name'], true))
        update_post_meta($post_id, $meta_box['name'], $data);
      elseif($data == "")
        delete_post_meta($post_id, $meta_box['name'], get_post_meta($post_id, $meta_box['name'], true));
      }
    }
    
    /* Let's start some actions */
    add_action('admin_menu', 'create_meta_box');
    add_action('save_post', 'save_postdata');
    
    /* The admin part is done */
    
    /* .. and now Gene's code extended with the custom fields */
    function child_theme_custom_query() {
    	global $post;
    
    	if (get_post_meta($post->ID, 'page_query_posts', true)) {
    
    		$limit = get_post_meta($post->ID, 'limit', true);
    		$category = get_post_meta($post->ID, 'category',true);
        	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
         	query_posts('cat=' .$category. '&showposts=' . $limit . '&paged=' . $paged );
    
        	$wp_query->is_archive = true; $wp_query->is_home = false;
        	}
    }
    
    add_action('thematic_above_indexloop', 'child_theme_custom_query');
    ?>

    Could be extended by integrating a drop down menu for the category.

    Chris

    Posted 4 years ago #
  15. Chris -

    You totally read my mind. I've just spent the last day learning/working on custom meta boxes for a child theme to employ switchable page layouts. I'll definitely be adding this to the mix. There's one or two more little things that I'd like to add to it and when I do I'll get you to look it over if you don't mind.

    It's really amazing what you can do with just one little template in a child theme. In the past I would have duplicated all that effort in multiple templates full of code. I'm glad I found Thematic. It's been a great learning experience hanging around here.

    -Gene

    Posted 4 years ago #
  16. Gene -

    will do that .. I'm working on Thematic for almost one year now and even for me it is fascinating to experience what you can do with it, how you can extend it, that is has nearly no limits.

    Chris

    Posted 4 years ago #
  17. Chris / Gene,

    Where I´d put the code for the Chris solution ?!????

    Posted 4 years ago #
  18. Oscar-

    Keep the new template in your child theme directory. Then you would delete the previous code examples and put Chis's code in your functions.php. No need to edit anything. Then you be able to choose the input the category id and select the page template and number of posts all on the Edit Page screen in the WP Admin area .

    Posted 4 years ago #
  19. Gene,

    I can´t see this new options that you said...I can send you my login information for you see.
    What I got, was publish a new post without appear at anyone menu or dropdown menu item.

    Sorry, you must be tired with me...but I´m trying learn,

    THANXS A LOT

    Posted 4 years ago #
  20. NVM...I´m a complete idiot ! I didn´t put new file in the appropriate folder at host.
    Now everything all right ! EXACTLY HOW I WISH !!!!

    Gene and Chris I have to pay YOU 16usd, by my POWERBLOG.

    I have no words to say THANK YOU !!!!!!!

    Posted 4 years ago #
  21. Many thanks Gents...much appreciated.

    Chris & 'em hr', you certainly have a gift...:-)

    Only one other question. And I may have just been up too late (I can feel a 'Doh!' coming on)...Category ID? Where do I find these? I've tried Category Titles & Plugs...

    Using Firebug I can find Post IDs/Numbers...The code works with Post Numbers, e.g. 'post 1, post 2, post 3', but that only works on one page. The other page only lists all the blog items like the Blog Home page, or the same category items as the other page.

    Many thanks again guys...

    Posted 4 years ago #
  22. noshitWFP,

    Here I´ve created one category for each page, then I put category ID number in Query Posts (WP admin panel).
    When I publish new post, I choose the category I had mentioned before. That´s all !
    look my test page: www.oscar.fot.br/blog

    I hope that has helped you

    oscar

    Posted 4 years ago #
  23. Stephen -

    go to WP-Admin / Posts / Categories, hover over the category name and the link in the status line should end with something like cat_ID=xyz.

    Chris

    Posted 4 years ago #
  24. Hi Oscar,

    Thanks mate...that's great :-) Very helpful :-)

    I just did a variation on that theme...I used fired bug to check the post number of the Category Links in the Sidebar.

    I then created a 2nd Category Query Page Template in my Child Theme. Pointed the naughty Page to that Template (i.e. Template2) and used "post 'Category Sidebar Link - Post #' (in my case "post 36") & boink...it worked. Well enough for now anyway. Mine looks the same as the Category Summary Page.

    I'm going to try your version because it looks like yours brings out an article with formatting.

    Many thank again Oscar...and to you all...very much appreciated.

    Cheers

    Stephen Glanville

    Posted 4 years ago #
  25. Hey Chris-

    I've been trying a different approach and I can't seem to get the custom fields to save. My goal is to set multiple meta areas of meta boxes.
    Here is my array

    $new_meta_areas =  array(
    	"query_area" => array(								// this will become the $id and $callback for add_meta_box()
    		"title" => "Post Aggregation", 			   		// will be the meta-box title in admin
    		"page" => "page",		   						// will accept a string or flat array
    		"context" => "", 		   						// defaults to 'normal'
    		"priority" => "high", 							// defaults to 'low'
    
          	"meta_boxes" => array(		   					// trying to optimize : customfields get stored in an array
     			"page_query_posts" => array(
     				"type" => "checkbox",
     				"std" => "false",
        		 	"title" => "Should this page include any posts",
     				"description"=> "Check if yes"),
     			"category" => array(
     				"type" => "text",
     				"std" => "",
        			"title" => "Category ID",
     				"description"=> "Please enter the Category ID"),
     			"limit" => array(
     				"type" => "text",
     				"std" => "",
     				"title" => "Limit to number of posts",
     				"description" => "Please enter the max. number of posts")
    		 )
    	 ),
    
    	"layout_area" => array(
    		"title" => "Thematic Layout",
    	    "callback" => "callback 2",
            "page" => array("page","post"),
            "context" => "side",
            "priority" => "",
    
      		"meta_boxes" => array(
     			"layout" => array(
      				"type" => "select",
      				"std" => "",
      				"title" => "Layout",
      				"description" => "Select a layout",
    				"options" => array(
    		  			"Two Col Right fixed" => "two-c-r-f",
    		  			"Two Col Left Fixed" => "two-c-l-f",
    		  			"Three Col Fixed" => "three-c-f",
    		  			"Three Col Right Fixed" => "three-c-r-f",
     		  			"Three Col Right Fixed Primary" => "three-c-r-f-p"
     		  		 )
    			 )
    		 )
    	 )
    );

    here's the create function and add_meta callback

    function create_meta_box() {
     	global $theme_name, $new_meta_areas;
    
      	if ( function_exists('add_meta_box') ) {
    		foreach($new_meta_areas as $meta_area => $value) {
    			$context = $value['context'];
    		    if ($context == '')  $context = 'normal';
    
    		    $priority = $value['priority'] ;
    		    if ($priority == '') $priority = 'low';
    
    		    if (is_string($value['page'])) $value['page'] = array($value['page']);
    		    foreach($value['page'] as $page => $page_value){
    		    	add_meta_box( $meta_area , $value['title']  , $meta_area, $page_value , $context, $priority );
        	    }
      		}
      	}
    }
    
    add_action('admin_menu', 'create_meta_box');
    
    function layout_area() {
    	global $post, $new_meta_areas;
    
    	$meta_area = $new_meta_areas['layout_area'];
    
    	foreach($meta_area['meta_boxes'] as $meta_box_name => $meta_box_option){		
    
      		foreach($meta_box_option['options'] as $option_type => $option_value ) { 
    
    			echo'<select name="'.$meta_box_name.'_noncename" id="'.$meta_box_name.'_noncename" >';
    			echo'<option';
    
    				if ( get_post_meta($post->ID, $meta_box_name, true) == $option_value ) {
    				  	echo ' selected="selected"';
    				} elseif ( $option_value == $option_type['std'] ) {
    				  	echo ' selected="selected"';
    				}
    
    			   echo' value="' . $option_value . '">'. $option_type .'</option>';
    		}
    		echo'</select>';
    		echo'<label for="'.$meta_box_name.'">'.$meta_box_option['description'].'</label>
    ';
    	}
    }

    and here is the save function

    function save_postdata( $post_id ) {
      	global $post, $new_meta_areas;
    
    	foreach($new_meta_areas as $meta_area => $value) {
    		foreach($meta_area['meta_boxes'] as $meta_box_name => $meta_box_option)	{
    			foreach($meta_box_option['options'] as $option_type => $option_value ) { 		
    
      		if ( !wp_verify_nonce( $_POST[$meta_box_name.'_noncename'], plugin_basename(__FILE__) )) {
      			return $post_id;
      		}
    
      		if ( 'page' == $_POST['post_type'] ) {
      		    if ( !current_user_can( 'edit_page', $post_id )) return $post_id;
      		} else {
      			if ( !current_user_can( 'edit_post', $post_id )) return $post_id;
      		}
    
      		$data = $_POST[$meta_box_name];
    
      		if(get_post_meta($post_id, $meta_box_name) == "")
      			add_post_meta($post_id, $meta_box_name, $data, true);
      		elseif($data != get_post_meta($post_id, $meta_box_name, true))
      			update_post_meta($post_id, $meta_box_name, $data);
      		elseif($data == "")
      			delete_post_meta($post_id, $meta_box_name, get_post_meta($post_id, $meta_box_name, true));
      			}
      		}
      	}
    }
    
    add_action('save_post', 'save_postdata');

    I'm not going to include the query area callback for testing it may be simpler to work with just the layout area. Take a look and see if you can figure out what I'm doing wrong.

    Thanks - Gene

    Posted 4 years ago #
  26. Gene,

    To use your example, Have I put the code above into functions.php ????

    Ps.: I´m spending my free time studing php here: http://devzone.zend.com/article/627
    One day, I´ll be good in php, not as well as you, but I shall not prohibit
    trying...

    oscar

    Posted 4 years ago #
  27. No you shouldn't use the last bit I posted. It doesnt work properly and I'm tired of messing with it... maybe Chris will have some insight.

    I'm glad to hear you're studying php :) I noticed earlier that your site is a .br domain. Here is the only PHP resource that I use constantly and its localized in Brazilian Portuguese http://www.php.net/manual/pt_BR/getting-started.php

    -Gene

    Posted 4 years ago #
  28. Dear Chris (and Gene if you're keen),

    Thanks for the Category ID response...I seemed to have got it anyway, though be it via a different route. Though I do appreciate that I can now being certain:-P

    I got everything working nicely the other night thank you :-)

    Now that I have taken that step and seen what it looks like, I have been able to to refine my initial question.

    At the risk of going way overboard and asking too much, I wonder would you be up for a further refinement on the above code? (Before I continue I feel it appropriate to admit up-front that lazy minds annoy me; therefore I feel to apologise in advance for not taking the time to thoroughly learn PHP. My current and entire focus is getting my new business on its feet; I don't consider the few mods I require to warrant learning PHP at this point. Hence my reliance on fine folks like yourself, which I greatly appreciate :-)

    Ok, back to the code:

    I really like what the above code has done so far. But now that I've seen the outcome I wonder would you consider tweaking it to do the following:

    The outcome of the above code looks like this (i.e. Category view) - http://edits.nosh-it-wood-fired-pizza.com.au/nosh-it-edits-blog/;

    Is it possible to get it to present the post excerpts like this (Blog landing view) - http://edits.nosh-it-wood-fired-pizza.com.au/ , whilst still filtering and listing by Category?

    Many thanks for your consideration.

    Regards

    Stephen Glanville

    Posted 4 years ago #
  29. Hi Gene,

    I'm working on your code.

    layout_area() is a bit messed up. :) .. that's the reason why you have a ton drop-downs with only one list entry.

    Rest will follow.

    Chris

    Posted 4 years ago #
  30. Yeah I should'nt have opened the selct in side the last loop. But I'm still not sure where is the best place to put the nonce and why the hell it wont save to the customfield.

    Thanks for looking into it.

    function layout_area() {
    	global $post, $new_meta_areas;
    
    	$meta_area = $new_meta_areas['layout_area'];
    
    	foreach($meta_area['meta_boxes'] as $meta_box_name => $meta_box_option){		
    
    	echo'<input type="hidden" name="'.$meta_box_name.'_noncename" id="'.$meta_box_name.'_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';
    
    		echo'<select name="'.$meta_box_name.'">';   
    
    		foreach($meta_box_option['options'] as $option_type => $option_value ) { 
    
    			echo'<option';
    
    				if ( get_post_meta($post->ID, $meta_box_name, true) == $option_value ) {
    				  	echo ' selected="selected"';
    				} elseif ( $option_value == $option_type['std'] ) {
    				  	echo ' selected="selected"';
    				}
    
    			   echo' value="' . $option_value . '">'. $option_type .'</option>';
    		}
    		echo'</select>';
    		echo'<label for="'.$meta_box_name.'">'.$meta_box_option['description'].'</label>
    ';
    	}
    }
    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.