Advertisement:

Author Topic: [TUTORIAL] How to make City and Regions specific main pages  (Read 31591 times)

computerbar

  • Tutor
  • Sr. Member
  • *
  • Posts: 279
[TUTORIAL] How to make City and Regions specific main pages
« on: March 09, 2012, 04:24:18 am »
UPDATE:
In the new version 3.2 you can use city/region based subdomains. where the ads are shown based on the subdomain selected.. in short you do not need this mod if you are using the subdomain feature...
I recommend that you upgrade you osclass to 3.2...

I have updated my site  to 3.2 and the example links below point to 3.2 now and are not related to the tutorial now..
==========================================


Thanks for your pm and request. Sorry I was not feeling well and could not do it however I am here to show how to make OSClass sexy.

This tutorial is based on Modern theme (OSCLASS 3.0.1) however it can be implemented in any version of Osclass and themes.

For twitter boot strap you can see http://jamal.pk

OK here we go

* Install Osclass if needed

* Create page in admin menu and give it title as "myhome", internal name "myhome" and description as "My awesome local page" REMEMBER the iternal name is the important part of this mod so choose wisely or just name it myhome to keep it simple.

* Now you need a ftp client to go to your website root folder. I use filezilla it is free

* In your theme folder make a copy of your main.php and name it myhome.php
* then in your website root folder make copy of search.php and name is as myhome.php

****Now the real fun begins that took me a good whole night to work it out then ;) ***

To understand how this works you need to know how osclass chain of commond works.

User come to your website
When the user click on any category say jobs link that is set up to look for search.php. The clicky goes to index.php where it is redirected to search.php on root and search.php convert that query into results show it the theme search.php page.

Now this mod is to change the regions and cities links to look for myhome.php.
When user select the city say mardan from the dropdown list on the main page the link goes to index.php where it is redirected to myhome.php on root and then the required result i.e. a function in myhome.php looks for city of mardan and its listing in database and return the results in myhome.php in your theme folder.

I hope I explained it clearly the whole process. lets make it happen now one by one.


First you need to add the myhome.php case to the index.php
 
edit index.php to find the below and add the myhome case under it.

        case ('search'):    // search pages
                            require_once(osc_base_path() . 'search.php') ;
                            $do = new CWebSearch() ;
                            $do->doModel() ;
        break;
            case ('myhome'):   //myhome
                            require_once(osc_base_path() . 'myhome.php') ; //osc_lib_path() in new version see below
                            $do = new CWebMyhome() ;
                            $do->doModel() ;
        break;
      

Now lets go to myhome.php on root and we need to edit it to change all mSearch references to mMyhome (be careful its mMyhome)
on line 20 change CWebSearch to CWebMyhome [as above set in index.php] then use you find and replace function in ftp client to change all mSearch to mMyhome.

Then on line 33 and 381 replace the word search to myhome.

That done now save and upload and close this page.

Next open main.php inside your theme folder we need to change the locations link in the sidebar to myhome instead of going to search page.

To show Regions and Cities with ads using the following code [NoTICE the link url added that redirct it to myhome.php]
               
            <div class="navigation">
                    <?php if(osc_count_list_regions() > 0 ) { ?>
                    <div class="box location">
                        <h3><strong><?php _e("Regions", 'modern') ; ?></strong></h3>
                        <ul>
                        <?php while(osc_has_list_regions() ) { ?>
                            <li><a href="../index.php?page=myhome&sRegion=<?php echo osc_list_region_name(); ?>"><?php echo osc_list_region_name() ; ?></a> <em>(<?php echo osc_list_region_items() ; ?>)</em></li>
                        <?php } ?>
                        </ul>
                    </div>
                    <?php } ?>
               
                            <?php if(osc_count_list_cities() > 0 ) { ?>
                    <div class="box location">
                        <h3><strong><?php _e("Cities", 'modern') ; ?></strong></h3>
                        <ul>
                        <?php while(osc_has_list_cities() ) { ?>
                            <li><a href="../index.php?page=myhome&sCity=<?php echo osc_list_city_name(); ?>"><?php echo osc_list_city_name() ; ?></a> <em>(<?php echo osc_list_city_items() ; ?>)</em></li>
                        <?php } ?>
                        </ul>
                    </div>
                    <?php } ?>
                </div>

Save upload and close main.php now.

Next open myhome.php in theme folder and replace location div as above in the sidebar aswell.

NOW let add some code as below somewhere on the top just above <div class="content home"> that would tell the user which region or city they are viewing...

      <div>
      <span>Your are in....<a href="../index.php?page=myhome&sCity=<?php echo osc_search_city() ; ?>"><?php echo osc_search_city() ; ?></a><a href="../index.php?page=myhome&sRegion=<?php echo osc_search_region() ; ?>"><?php echo osc_search_region() ; ?></a></span>
      </div>
      
Save and upload. click on any region in your site and you should see the message.. Pretty cool huh...  8) you are nearly there...
       

Again In this myhome.php we to do a bit of work to change the categories links to be changed to myhome results i.e. when there user is viewing Mardan city and them click on JOBS category they will be only shown the adverts from Mardan. lets do it.

For Categories your code show look like below [Notice the url link added] you can also use the same url for your Top menu categories if you have any eg in twitter/becute themes

<div class="category">
                            <h1><strong><a class="category cat_<?php echo osc_category_id() ; ?>" href="../index.php?page=myhome&sCity=<?php echo osc_search_city();?>&sRegion=<?php echo osc_search_region();?>&sCategory[]=<?php echo osc_category_id() ; ?>"><?php echo osc_category_name() ; ?></a> <span>(<?php echo osc_category_total_items() ; ?>)</span></strong></h1>
                            <?php if ( osc_count_subcategories() > 0 ) { ?>
                                <ul>
                                    <?php while ( osc_has_subcategories() ) { ?>
                                        <li><a class="category cat_<?php echo osc_category_id() ; ?>" href="../index.php?page=myhome&sCity=<?php echo osc_search_city();?>&sRegion=<?php echo osc_search_region();?>&sCategory[]=<?php echo osc_category_id() ; ?>"><?php echo osc_category_name() ; ?></a> <span>(<?php echo osc_category_total_items() ; ?>)</span></li>
                                    <?php } ?>
                                </ul>
                            <?php } ?>
                        </div>



Next to show latest advert in the selected City or Region
in myhome.php above find the latest_ads div and insert the under it as code below
               <div class="latest_ads">
            
             <h5><?php if(osc_search_total_items()>0){ echo ' ('.osc_search_total_items().')';}?><?php _e(' Adverts in ', 'modern') ; ?><?php echo osc_search_city() ; ?><?php echo osc_search_region() ; ?></h5>
                   
             <?php osc_current_web_theme_path('search_list.php') ; ?>
                          

                  
Change the Search Box from categories to Regions with adverts that will return that region page with search results

In your theme folder open inc-search.php

and modify the FORM code as below [NOTICE value = "myhome"] You Must not use the category  search box as it will not return the region and all other link will become useless

<form action="<?php echo osc_base_url(true) ; ?>" method="get" class="search" onsubmit="javascript:return doSearch();">
    <input type="hidden" name="page" value="myhome" />
    <fieldset class="main">
        <input type="text" name="sPattern"  id="query" value="<?php echo osc_esc_html( ( osc_search_pattern() != '' ) ? osc_search_pattern() : $sQuery ); ?>" />
        <select>
         <?php View::newInstance()->_exportVariableToView('list_regions', Search::newInstance()->listRegions('%%%%', '>=', 'region_name ASC') ) ; ?>             <?php if(osc_count_list_regions()>0) {?>
                       
                       
                            <?php while(osc_has_list_regions()) { ?>
                                <option value="<?php echo osc_list_region_name();?>"><?php echo osc_list_region_name();?><em><?php if(osc_list_region_items()>0){ echo ' ('.osc_list_region_items().')';}?></em></option>
                            <?php } ?>
                       
                        <?php } ?>
                  </select>
       <button type="submit"><?php _e('Search', 'modern') ; ?></button>
    </fieldset>
    <div id="search-example"></div>
</form>





finally replace the SEE MORE div code to as below {notice the link added to it]
<p class="see_more_link"><a href="../index.php?page=search&sCity=<?php echo osc_search_city(); ?>&sRegion=<?php echo osc_search_region(); ?>"><strong><?php _e("See all offers", 'modern'); ?> &raquo;</strong></a></p>

Thats it that is how you do it.

If you like this mod and want to thank me you can buy me coffe via paypal.
computerbar@gmail.com
                      
            
See demo on http://singer.pk & http://jamal.pk


UPDATE:

The above instructions are for older Osclass versions.

If you are using new version of OSCLASS read below.

The search.php has been shifted to /oc-includes/osclass/controller

If you have updated to new version
You need to move the myhome.php to that folder from root after the update
and
Edit/update index.php with following
case ('myhome'):   //myhome
                            require_once(osc_lib_path() . 'osclass/controller/myhome.php') ;
                            $do = new CWebMylocal() ;
                            $do->doModel() ;
        break;


If new user with new version of OSCLASS where the Search.php is not on ROOT but in controller folder

1) Edit Index.php
2) Make a copy of Search.php in controller folder and name it myhome.php and edit it as above.
3) Create new new page name it as myhome
4) Make a copy of your main.php in theme folder and name it myhome.php and edit catgories/city/region links as above.

DONE
 
      
 


« Last Edit: August 23, 2013, 03:32:30 pm by computerbar »

trains58554

  • Osclass contributor
  • Hero Member
  • *****
  • Posts: 3642
  • osCanyon, the class of Osclass
Re: How to make City and Regions specific main pages
« Reply #1 on: March 09, 2012, 04:33:09 am »

corebot

  • Newbie
  • *
  • Posts: 31
Re: How to make City and Regions specific main pages
« Reply #2 on: March 09, 2012, 09:42:26 am »
Let me know if you figure this out pls. I am in great need of this feature as well but not a guru when it comes to PHP.


computerbar

  • Tutor
  • Sr. Member
  • *
  • Posts: 279
Re: How to make City and Regions specific main pages
« Reply #3 on: March 28, 2012, 02:05:40 am »
Thanks jay but I still could not figure the following code out
$mSearch = Search::newInstance();
$mSearch->addRegion($region);
$aItems = $mSearch->doSearch();
View::newInstance()->exportVariableToView('items', $aItems);



Thanks
« Last Edit: April 10, 2012, 05:27:08 pm by computerbar »

computerbar

  • Tutor
  • Sr. Member
  • *
  • Posts: 279
Re: How to make City and Regions specific main pages
« Reply #4 on: April 04, 2012, 09:29:45 pm »
I think am half way there.
I see the same code in your solution to related ads but I think my query is different.

I just need for the categories/subcategories to show count of items in the city in the search url i.e sCity="" or say osc_search_city()
Please look at the
demo@ //jamal.pk/index.php?page=myhome&sCity=Islamabad
at the moment there are 9 ads in this city but categories are showing all items count.


Also how to show the region name by searching the sCity in the search url? osc_search_region() or similar are not returning anything. only osc_item_region show name if the city has any ads already as in example above.

Thanks

computerbar

  • Tutor
  • Sr. Member
  • *
  • Posts: 279
Re: [SOLVED] How to make City and Regions specific main pages
« Reply #5 on: April 09, 2012, 11:05:18 pm »
Everything sorted now.
I have made the changes as I described above and removed the item count from the categories.

Now you can see on my site that I have specific pages for every region and city whenever suer click on city or region it takes them myhome.php and you can see it is pretty good now.


Ok now I can sleep ;) and can start work on another tiny plugin..



mmcsus

  • Hero Member
  • *****
  • Posts: 704
  • Open Source
Re: [SOLVED] How to make City and Regions specific main pages
« Reply #6 on: May 09, 2012, 02:51:56 am »
Everything sorted now.
I have made the changes as I described above and removed the item count from the categories.

Now you can see on my site that I have specific pages for every region and city whenever suer click on city or region it takes them myhome.php and you can see it is pretty good now.


Ok now I can sleep ;) and can start work on another tiny plugin..


Can you tell me how you solved your problem, I would like to do the same.

negotiator

  • Newbie
  • *
  • Posts: 48
  • Creating Opportunities
Re: [SOLVED] How to make City and Regions specific main pages
« Reply #7 on: May 09, 2012, 09:18:55 pm »
Hi Computerbar


Quote
Everything sorted now.
will you please share your code with us,,,
Quote
Now you can see on my site
what's your site address?

will highly appreciate your efforts

-Kawaljeet

BuySellAndSwap

  • Sr. Member
  • ****
  • Posts: 389
Re: [SOLVED] How to make City and Regions specific main pages
« Reply #8 on: July 10, 2012, 11:47:54 pm »
Hi computerbar

Please could you help me to do this also?

Thank you

Alexandr

  • Full Member
  • ***
  • Posts: 126
Re: [SOLVED] How to make City and Regions specific main pages
« Reply #9 on: July 15, 2012, 01:46:22 pm »
looks great

zioweb

  • Full Member
  • ***
  • Posts: 120
Re: [SOLVED] How to make City and Regions specific main pages
« Reply #10 on: July 15, 2012, 03:02:16 pm »
how did you solve it?

telecomseva

  • Newbie
  • *
  • Posts: 32
Re: [SOLVED] How to make City and Regions specific main pages
« Reply #11 on: July 31, 2012, 08:02:32 am »
hi computerbar,

could you share your code or help us to do so.

thanks

eli

  • Newbie
  • *
  • Posts: 8
Re: [SOLVED] How to make City and Regions specific main pages
« Reply #12 on: October 15, 2012, 08:55:31 pm »
BUMPING
Hi computerbar and CONEJO, could you please post the code to this problem, I think many of us would appreciate it,
Thanks

computerbar

  • Tutor
  • Sr. Member
  • *
  • Posts: 279
Re: [SOLVED] How to make City and Regions specific main pages
« Reply #13 on: November 09, 2012, 03:15:19 am »
Hi guys I am back nearly..

Sorry I was not feeling well and had two surgeries in the past 6 months and have just got a clean bill from my doctor however I still need some rest...

Thank you for all those who sent pm about how to make city/region specific pages so there you go. Please check the first post for tutorial...

BuySellAndSwap

  • Sr. Member
  • ****
  • Posts: 389
Re: [TUTORIAL] How to make City and Regions specific main pages
« Reply #14 on: November 10, 2012, 02:34:17 am »
Hi

Is there a way to change th ecode on the twitter menu for regions too?

I have started to change the site at www.placeformotors.co.uk you can see a region page at http://placeformotors.co.uk/index.php?page=myhome&sRegion=East+Yorkshire

Thanks for a great tutorial the only thing that i've noticed is the problem with the menu and also is there a way for the search box on my page to automactilly select the city region its on?

Thank you