0

First of all, I really apologize for the title of this question.

I'm currently working on a real estate wordpress theme for that will feature ads from the town that I live in.

I basically want to have 3 categories: for sale, for lease and sold and to be able to move let's say a post(house add) from one category to another category. Each category should have a page where each house that's currently on that category is shown as an excerpt(like the blog index page)

The thing is I don't know how to aproach this? (I'm a beginner developer).

Should I store the house ads in pages or posts. Should I have special page templates?

Could someone give me a set of steps that I need to follow in order to achieve this? (looking for some plain English advice, not code).

Thanks!

  • I'd use posts (possibly custom posts, but you may not need them), put them in the appropriate categories, and then use WordPress's built-in category archives (or possibly taxonomy archives, if you're using custom post type & custom taxonomy) to make the listing pages. As to template files -- see the Template Hierarchy for a concise look at what file(s) you might need in a theme. – Pat J Jul 7 '14 at 20:03
0

I agree with Pat above - I'd say from my own experience it probably helps in the long run making a Custom Post Type for houses to keep hundreds of the things separate from your main pages (or blog).

For starting with coding it all - sometimes to kick off with and starting to learn about these things it will give you a headstart to begin with plugins. I taught myself PHP using the 'trial and error' method and a local server. So plugins really helped me get to grips with how to write more complicated and personalised code. That and stackexchange & WPSE obviously!

To help register Custom Post Types as a beginner I would use something like Cutsom Post Type UI which seems to be the highest rated and most used of the CPT plugins although I have no experience of it myself.

I would then personally store the data as post meta and use the update_post_meta() info here function as I find taxonomies can be tricky and can cause some permalink tantrums with some plugins but it's just a personal thing! But if you're going to be editing them as custom post types anyway it in the wp-admin UI area then ignore that function and go the next step.

The next stage would be to get yourself a copy of Advanced Custom Fields which I still use to be honest as it saves a bundle of time compared to coding your own metaboxes every time you'd like to spruce the place up a bit. It also gives you nice little php shortcodes to call by in your code like get_field('house_price') which you can then pop into a template or page anywhere you like to achieve a nice uniform layout.

To distinguish between the categories in your template then all you need to do is write a simple query. There are hundreds of pages about this, so I'll just put an example (sorry - code)

    $args = array(
          'post_type' => 'house',
          'post_status' => 'publish',
          'meta_key' => 'state',
          'meta_value' => 'sold', //Example of the three state of houses you could have as mentioned above.
          'orderby' => 'ID', //choose to order by anything look here [http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters] for more info
          'order' => 'ASC', //to put the oldest posts first - sell em!
          'posts_per_page' => -1,
          'ignore_sticky_posts'=> 1,
          );
  $results = new WP_Query($args);
 //    '<pre>'.print_r($results).'</pre>'; // This is a useful line to keep - uncomment it to print all results found - it can then be used to work out if the query is doing the right thing or not.
 while ($results->have_posts()) {
$results->the_post();
the_title();
the_content();
echo '</hr>'; // puts a horizontal line between results
}

wp_reset_postdata(); //re-sets back to normal       

}

At the end of the day everyone has a method they prefer or find easier than others so if you're looking to get stuck in the MOST VALUABLE thing to have is a local server set up... google MAMP or WAMP (depending on Mac or Windows) and look at some of the methods described to set it up as it means you can have a good play around with anything you're editing (or breaking) before you start pulling apart a live site.

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.