Перейти к содержанию
View in the app

A better way to browse. Learn more.

Форум VAOZ.RU

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Ajax подгрузка custom в нужный блок

Featured Replies

Опубликовано

Реализуем подгрузку новостей по custom через ajax, что позволит увеличить скорость загрузки страницы сайта.

1. В /engine/ajax/ создайте файл с названием custom.php в него вставьте этот код:

<?php
// by PunPun.name Back-End разработчик и SEO оптимизатор
@error_reporting ( E_ALL ^ E_WARNING ^ E_NOTICE );
@ini_set ( 'display_errors', true );
@ini_set ( 'html_errors', false );
@ini_set ( 'error_reporting', E_ALL ^ E_WARNING ^ E_NOTICE );

define( 'DATALIFEENGINE', true );
define( 'ROOT_DIR', substr( dirname(  __FILE__ ), 0, -12 ) );
define( 'ENGINE_DIR', ROOT_DIR . '/engine' );

include ENGINE_DIR . '/data/config.php';
require_once ENGINE_DIR . '/classes/mysql.php';
require_once ENGINE_DIR . '/data/dbconfig.php';
require_once ENGINE_DIR . '/modules/functions.php';
require_once ENGINE_DIR . '/classes/templates.class.php';

dle_session();

require_once ENGINE_DIR . '/modules/sitelogin.php';
require_once ROOT_DIR . '/language/' . $config['langs'] . '/website.lng';
@header( "Content-type: text/html; charset=" . $config['charset'] );

if(!$is_logged) $member_id['user_group'] = 5;

//################# Определение групп пользователей
$user_group = get_vars( "usergroup" );
if( ! $user_group ) {
    $user_group = array ();
    $db->query( "SELECT * FROM " . USERPREFIX . "_usergroups ORDER BY id ASC" );
    while ( $row = $db->get_row() ) {
        $user_group[$row['id']] = array ();
        foreach ( $row as $key => $value ) $user_group[$row['id']][$key] = stripslashes($value);
    }
    set_vars( "usergroup", $user_group );
    $db->free();
}
//################# Определение категорий и их параметры
$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 );
    }
    set_vars( "category", $cat_info );
    $db->free();
}
define( 'TEMPLATE_DIR', ROOT_DIR . '/templates/'.$config['skin']);
$custom = isset($_POST["castom"]) && is_scalar($_POST["castom"]) ? trim(strip_tags(stripslashes($_POST["castom"]))) : false;
if($custom==false) return;
if( strpos( $custom, "custom" ) !== false ) {
    $custom = "{".$custom."}";
    $custom = preg_replace_callback( "#\\{custom(.+?)\\}#i", "custom_print", $custom );
    if($custom !="") echo $custom;
}
?>

2. В табах на переключателях вставлять:

data-ajaxc="custom id='1' template='shortstory'"

- где внутри параметры custom без фигурных скобок и вместо двойных кавичек - одинарные.
3. Там где должен выводится контент вставить:

data-trigercajax="set"


4. Перед тегом

</body>

вставить:
 

<script>
    $(function($){
        $("body").on("click", "[data-ajaxc]", function(){
            var $castom = $(this).attr("data-ajaxc");
            $.post(dle_root+"engine/ajax/custom.php", {castom:$castom}, function(data){
                $("[data-trigercajax]").html(data);
            });
        })
    });
</script>

Пример конструкции:
 

<span data-ajaxc="custom id='1' template='shortstory'">Таб 0</span>
<span data-ajaxc="custom id='2' template='shortstory'">Таб 1</span>
<span data-ajaxc="custom id='3' template='shortstory'">Таб 2</span>
<div data-trigercajax="set">{custom id="1" template="shortstory"}</div>

Для публикации сообщений создайте учётную запись или авторизуйтесь

Рейтинг@Mail.ru Яндекс.Метрика

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.