I
I
Ivan2020-02-08 15:47:58
PHP
Ivan, 2020-02-08 15:47:58

How to implement city selection on the site and display the desired content in DLE categories?

I'm trying to create in dle cms the ability to select a city with the display of the content of this city, which I did:
1. created an additional table in the database following the example of the existing one for categories (category) and named it city ; 2. added the city
field to the post table ; 3. filled in the fields city - id of cities from the city table in the test news; that's all there was to it. I tried to edit the engine/init.php file, a piece of code responsible for categories, edited it, added a copy of it but with settings for city


$cat_info = get_vars ( "category" );

if (!is_array ( $cat_info )) {
  $cat_info = array ();

  $db->query ( "SELECT * FROM " . PREFIX . "_category ORDER BY posi ASC" );
  while ( $row = $db->get_row () ) {

    $cat_info[$row['id']] = array ();

    foreach ( $row as $key => $value ) {
      $cat_info[$row['id']][$key] = stripslashes ( $value );
    }
    
    $cat_info[$row['id']]['newscount'] = 0;

  }
  set_vars ( "category", $cat_info );
  $db->free ();
}


.htaccess rules, but in the end I got something working but not completely, at most I managed to open the address of the city, for example, site.ru/moscow/ and see the title, description, breadcrumbs for Moscow, but the categories are displayed based on id cities.
Those. if the city of Moscow has 7 in the city - id database, then the site for the city of Moscow will display news from the category with id 7, and all existing news - categories but with Moscow news should be displayed.

In .htaccess rules line


RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)/page/([0-9]+)(/?)+$ index.php?do=cat&category=$1&cstart=$2 [L]
RewriteRule ^([^.]+)/?$ index.php?do=cat&category=$1 [L]


also added their counterparts.

I'm doing something wrong and I understand it, but I don't understand what ...
Help me figure it out, please.

I need to select the city of Moscow - site.ru/moscow/ to display a page with the usual list of news and categories, but with news for the city of Moscow.

Categories in the form site.ru/moscow/category
site.ru/moscow/category2 etc.

Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question