Advertisement:

Author Topic: [Solved] How To Link Header Custom Page(s) To Custom Item Category:Osclasswizard  (Read 791 times)

Blessedmua

  • Newbie
  • *
  • Posts: 8
Hi Osclass Professionals,

I am new to OSClass, so I need help on how to link or redirect  a page(s) in the header(eg: For Sale / For Rent) to a main category (eg: Properties for Sale and or Properties For Rent)

I will be glad is I can get a step by step guide plssss.

Regards.
« Last Edit: September 04, 2018, 11:51:32 pm by Blessedmua »

Blessedmua

  • Newbie
  • *
  • Posts: 8
Re: Osclasswizard: How To Link Header Custom Page(s) To Custom Item Category
« Reply #1 on: September 03, 2018, 12:17:42 pm »
Hi guys i am still waiting for your assistance and guide as am new to osclass and coding. :)

Have searched the entire forum for days and still have not seen a solution. Pls help.

Aficionado

  • Guest
Re: Osclasswizard: How To Link Header Custom Page(s) To Custom Item Category
« Reply #2 on: September 03, 2018, 06:53:28 pm »
Support is mainly here by volunteers, in their spare time.

There is no guarantee when or if you get some reply. So please wait and don't bump the topics.

If somebody knows, he will help you out.

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Osclasswizard: How To Link Header Custom Page(s) To Custom Item Category
« Reply #3 on: September 03, 2018, 10:45:39 pm »
Hello,

EDITED BOTH SOLUTIONS, NO SYNTAX ERROR ANYMORE.

If I understood correctly, you want links in your header that lead to categories in the search.
You have two options:
  • Add them yourself by editing header.php, an example of code to add would be '<a href="<?php echo osc_search_url(array('sCategory' => 'Category ID')); ?>">Category Name</a>'
  • Take the slug you have at the custom page you created and make a file in your theme folder. If the slug is "for-rent", the file name will be "page-for-rent.php". In that file add the following code <?php osc_redirect_to(osc_search_url(array('sCategory' => 'Category ID'))); ?>

In both codes replace 'Category ID' with the ID of the category you want to redirect to.

Regards.
« Last Edit: September 04, 2018, 11:50:19 pm by patrickFromCroatia »

Blessedmua

  • Newbie
  • *
  • Posts: 8
Re: Osclasswizard: How To Link Header Custom Page(s) To Custom Item Category
« Reply #4 on: September 03, 2018, 11:07:24 pm »
Hello,

If I understood correctly, you want links in your header that lead to categories in the search.
You have two options:
  • Add them yourself by editing header.php, an example of code to add would be '<a href="<?php echo osc_search_url('sCategory' => 'Category ID'); ?>">Category Name</a>'
  • Take the slug you have at the custom page you created and make a file in your theme folder. If the slug is "for-rent", the file name will be "page-for-rent.php". In that file add the following code <?php osc_redirect_to(osc_search_url('sCategory' => 'Category ID')); ?>

In both codes replace 'Category ID' with the ID of the category you want to redirect to.

Regards.

Thank sir. I shall give it a trial immediately, however, pls clarify to be how or where to get the category Id as advised bearing in mind that the category I am referring to here is a custom category that I included myself: “For Sale” and “ For Rent” to be precise. Thanking you in anticipation.

Regards.

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Osclasswizard: How To Link Header Custom Page(s) To Custom Item Category
« Reply #5 on: September 04, 2018, 12:25:13 am »
You are welcome. I have made a quick code so we don't mess with the database and inspect element tools. Paste the code I will provide at the bottom of your functions.php, but before "?>". Then open your website and you should see a list of categories with their ID's in the footer. The code is tested with Osclasswizards.

Code: [Select]
function cs_category_ids_footer() {
    $categories = Category::newInstance()->listAll();
    foreach($categories as $key => $category) {
        echo ' <strong>Name:</strong> ';
        echo $category['s_name'];
        echo ' <strong>ID:</strong> ';
        echo $category['pk_i_id'];
        echo '<br>';
    }
}
osc_add_hook('footer', 'cs_category_ids_footer');

Regards.

Blessedmua

  • Newbie
  • *
  • Posts: 8
Re: Osclasswizard: How To Link Header Custom Page(s) To Custom Item Category
« Reply #6 on: September 04, 2018, 12:45:34 am »
You are welcome. I have made a quick code so we don't mess with the database and inspect element tools. Paste the code I will provide at the bottom of your functions.php, but before "?>". Then open your website and you should see a list of categories with their ID's in the footer. The code is tested with Osclasswizards.

Code: [Select]
function cs_category_ids_footer() {
    $categories = Category::newInstance()->listAll();
    foreach($categories as $key => $category) {
        echo ' <strong>Name:</strong> ';
        echo $category['s_name'];
        echo ' <strong>ID:</strong> ';
        echo $category['pk_i_id'];
        echo '<br>';
    }
}
osc_add_hook('footer', 'cs_category_ids_footer');

Regards.

Thank you my hero!
Your code works excellently well and it distinctly displayed all categories and their IDs. am really grateful.

However, like Oliver twist; I want to ask for one more last help  :)

I tried to add the codes accordingly as advised but it seems like I didn't insert it in the right position. Am a novice in coding...won't mind if you guide me on exactly where to add the codes in header.php and the php file in the theme folder, just like you did me with the "Show Category Id" codes.

Thanks in anticipation once more.
 

« Last Edit: September 04, 2018, 01:19:45 am by Blessedmua »

Blessedmua

  • Newbie
  • *
  • Posts: 8
Re: Osclasswizard: How To Link Header Custom Page(s) To Custom Item Category
« Reply #7 on: September 04, 2018, 01:35:38 am »
@ patrickFromCroatia

I did as instructed; added code in the php file(page-for-sale.php) in the theme folder but got syntax error...find attached.

what did I not do right??

for the header.php code, I don't know exactly where to add the code.

please help.
« Last Edit: September 04, 2018, 01:40:21 am by Blessedmua »

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Osclasswizard: How To Link Header Custom Page(s) To Custom Item Category
« Reply #8 on: September 04, 2018, 01:40:11 am »
@ patrickFromCroatia

I did as instructed; added the php file in the theme folder but got syntax error...find attached.

what did I not do right??

for the header.php code, I don't know exactly where to add the code.

please help.


There were 2 options, I think you thought you need to do both of them, use only one, I recommend the first one.
You can do this without creating pages and adding the files.

Open header.php, go to line 100 (<ul class="links">) and paste under this under it '<li><a href="<?php echo osc_search_url(array('sCategory' => 1)); ?>">Name</a></li>'.
You can copy that code as many times as you want, changing the ID and name.

Regards.

Blessedmua

  • Newbie
  • *
  • Posts: 8
Re: Osclasswizard: How To Link Header Custom Page(s) To Custom Item Category
« Reply #9 on: September 04, 2018, 02:09:44 am »
@ patrickfromcroatia

the code on my line 100 in header.php is different from yours, and your code: <li><a href="<?php echo osc_search_url(array('sCategory' => 1)); ?>">Name</a></li>'. appeared missing in my header page as well.

please see below my header code and see what went wrong and possibly how to remedy it:

Code: [Select]
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="<?php echo str_replace('_''-'osc_current_user_locale()); ?>">
<head>
<?php osc_current_web_theme_path('common/head.php') ; ?>
</head>

<body <?php osclasswizards_body_class(); ?>>
<header id="header">
  <div class="top_links">
    <div class="container">
      <div class="language">
        <?php ?>
        <?php if ( osc_count_web_enabled_locales() > 1) { ?>
        <?php osc_goto_first_locale(); ?>
        <strong>
        <?php _e('Language:'OSCLASSWIZARDS_THEME_FOLDER); ?>
        </strong> <span>
        <?php $local osc_get_current_user_locale(); echo $local['s_name']; ?>
        <i class="fa fa-caret-down"></i></span>
        <ul>
          <?php $i 0;  ?>
          <?php while ( osc_has_web_enabled_locales() ) { ?>
          <li><a <?php if(osc_locale_code() == osc_current_user_locale() ) echo "class=active"?> id="<?php echo osc_locale_code(); ?>" href="<?php echo osc_change_language_url osc_locale_code() ); ?>"><?php echo osc_locale_name(); ?></a></li>
          <?php if( $i == ) { echo ""; } ?>
          <?php $i++; ?>
          <?php ?>
        </ul>
        <?php ?>
      </div>
      <?php if(osclasswizards_welcome_message()){ ?>
      <p class="welcome-message"><?php echo osclasswizards_welcome_message(); ?></p>
      <?php ?>
      <ul>
        <?php if( osc_is_static_page() || osc_is_contact_page() ){ ?>
        <li class="search"><a class="ico-search icons" data-bclass-toggle="display-search"></a></li>
        <li class="cat"><a class="ico-menu icons" data-bclass-toggle="display-cat"></a></li>
        <?php ?>
        <?php if( osc_users_enabled() ) { ?>
        <?php if( osc_is_web_user_logged_in() ) { ?>
        <li class="first logged"> <span><?php echo sprintf(__('Hi %s'OSCLASSWIZARDS_THEME_FOLDER), osc_logged_user_name() . '!'); ?> </span> &#10072; <strong><a href="<?php echo osc_user_dashboard_url(); ?>">
          <?php _e('My account'OSCLASSWIZARDS_THEME_FOLDER); ?>
          </a></strong> &#10072; <a href="<?php echo osc_user_logout_url(); ?>">
          <?php _e('Logout'OSCLASSWIZARDS_THEME_FOLDER); ?>
          </a> </li>
        <?php } else { ?>
        <li><a id="login_open" href="<?php echo osc_user_login_url(); ?>">
          <?php _e('Login'OSCLASSWIZARDS_THEME_FOLDER) ; ?>
          </a></li>
        <?php if(osc_user_registration_enabled()) { ?>
        <li><a href="<?php echo osc_register_account_url() ; ?>">
          <?php _e('Register for a free account'OSCLASSWIZARDS_THEME_FOLDER); ?>
          </a></li>
        <?php }; ?>
        <?php ?>
        <?php ?>
      </ul>
    </div>
  </div>
  <div class="main_header" id="main_header">
    <div class="container">
      <div id="logo"> <?php echo logo_header(); ?> <span id="description"><?php echo osc_page_description(); ?></span> </div>
      <h2 class="pull-right toggle"><i class="fa fa-align-justify"></i></h2>
      <ul class="links">
        <?php
        osc_reset_static_pages
();
        while( 
osc_has_static_pages() ) { ?>

        <li> <a href="<?php echo osc_static_page_url(); ?>"><?php echo osc_static_page_title(); ?></a> </li>
        <?php
        
}
osc_reset_static_pages();
        
?>

        <li> <a href="<?php echo osc_contact_url(); ?>">
          <?php _e('Contact'OSCLASSWIZARDS_THEME_FOLDER); ?>
          </a> </li>
      </ul>
      <div class="publish">
        <?php if( osc_users_enabled() || ( !osc_users_enabled() && !osc_reg_user_post() )) { ?>
        <a class="btn btn-success" href="<?php echo osc_item_post_url_in_category() ; ?>">
        <?php _e('advertise your ad for free'OSCLASSWIZARDS_THEME_FOLDER);?>
        </a>
        <?php ?>
      </div>
    </div>
  </div>
  <?php 
if( 
osc_is_home_page() ) {
if(osc_get_preference('show_banner''osclasswizards_theme')=='1'){
echo '<div id="header_map">';
if(homepage_image()) { 
echo homepage_image(); 
} else {

echo '<img src="'.osc_current_web_theme_url('images/banner.jpg').'" />';


echo '</div>';
}
?>

  <div class="banner_none" id="form_vh_map">
    <form action="<?php echo osc_base_url(true); ?>" id="main_search" method="get" class="search nocsrf" >
      <div class="container">
        <input type="hidden" name="page" value="search"/>
        <div class="main-search">
          <div class="form-filters">
            <div class="row">
              <?php $showCountry  = (osc_get_preference('show_search_country''osclasswizards_theme') == '1') ? true false?>
              <div class="col-md-<?php echo ($showCountry)? '3' '4'?>">
                <div class="cell">
                  <input type="text" name="sPattern" id="query" class="input-text" value="" placeholder="<?php echo osc_esc_html(__(osc_get_preference('keyword_placeholder''osclasswizards_theme'), OSCLASSWIZARDS_THEME_FOLDER)); ?>" />
                </div>
              </div>
              <div class="col-md-2">


                <?php  if ( osc_count_categories() ) { ?>
                <div class="cell selector">
                  <?php osc_categories_select('sCategory'nullosc_esc_html(__('Select Property Type'OSCLASSWIZARDS_THEME_FOLDER))) ; ?>
                </div>
                <?php  ?>
              </div>
              <?php if($showCountry) { ?>
              <div class="col-md-2">
                <div class="cell selector">
                  <?php osclasswizards_countries_select('sCountry''sCountry'__('Select a Country'OSCLASSWIZARDS_THEME_FOLDER));?>
                </div>
              </div>
              <?php ?>
              <div class="col-md-2">
                <div class="cell selector">
                  <?php osclasswizards_regions_select('sRegion''sRegion'__('Select a State/District'OSCLASSWIZARDS_THEME_FOLDER)) ; ?>
                </div>
              </div>
              <div class="col-md-2">
                <div class="cell selector">
                  <?php osclasswizards_cities_select('sCity''sCity'__('Select a City/Town'OSCLASSWIZARDS_THEME_FOLDER)) ; ?>
                </div>
              </div>
              <div class="col-md-<?php echo ($showCountry)? '1' '2'?>">
                <div class="cell reset-padding">
                  <button  class="btn btn-success btn_search"><i class="fa fa-search"></i> <span <?php echo ($showCountry)? '' 'class="showLabel"'?>><?php echo osc_esc_html(__("Search"OSCLASSWIZARDS_THEME_FOLDER));?></span> </button>
                </div>
              </div>
            </div>
          </div>
          <div id="message-seach"></div>
        </div>
      </div>
    </form>
  </div>
  <?php


?>

                  <?php osc_run_hook('responsive_slider'); ?>
  <?php osc_show_widgets('header'); ?>
</header>
<div class="wrapper-flash">
  <?php
        $breadcrumb 
osc_breadcrumb('&raquo;'falseget_breadcrumb_lang());
        if( 
$breadcrumb !== '') { ?>

  <div class="breadcrumb">
    <div class="container"> <?php echo $breadcrumb?> </div>
  </div>
  <?php
        
}
    
?>

  <?php osc_show_flash_message(); ?>
</div>
<?php osc_run_hook('before-content'); ?>
<div class="wrapper" id="content">
<div class="container">
<?php if( osc_get_preference('header-728x90''osclasswizards_theme') !=""){ ?>
<div class="ads_header ads-headers"> <?php echo osc_get_preference('header-728x90''osclasswizards_theme'); ?> </div>
<?php ?>
<div id="main">

Thanks for your efforts thus far.

regards.
« Last Edit: September 04, 2018, 02:38:10 am by Blessedmua »

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Osclasswizard: How To Link Header Custom Page(s) To Custom Item Category
« Reply #10 on: September 04, 2018, 12:13:39 pm »
You need to paste that "<li><a href..." code under <ul class="links"> and replace 'Category ID' with your ID.

Regards.

Blessedmua

  • Newbie
  • *
  • Posts: 8
Re: Osclasswizard: How To Link Header Custom Page(s) To Custom Item Category
« Reply #11 on: September 04, 2018, 11:33:06 pm »
You need to paste that "<li><a href..." code under <ul class="links"> and replace 'Category ID' with your ID.

Regards.
Thank you pretty much sir.

I finally got it right and suddenly a new page link appeared on my header with..."For Sale and For Rent" even though I had already created those two links before o my header, since I now have double of the above links I had to deactivate my initially created links from my Oc-admin page and it's all working fine now>

You are my gem ;D

Pls how do I mark this topic as solved??
« Last Edit: September 04, 2018, 11:36:37 pm by Blessedmua »

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Osclasswizard: How To Link Header Custom Page(s) To Custom Item Category
« Reply #12 on: September 04, 2018, 11:49:35 pm »
You are welcome! ;)
You can change the title of the topic by editing the first post.

Regards.