Как вставить код в functions.php

(Ответов: 15, Просмотров: 1789)
Страница 2 из 2 Первая 12
  1. Студент
    • Регистрация: 25.01.2012
    • Сообщений: 71
    • Репутация: 29
    vovasit91,
    PHP код:
    <?php
        
    require_once TEMPLATEPATH . '/lib/Themater.php';
        
    $theme = new Themater('NextVideo');
        
    $theme->options['includes'] = array('featuredposts');
        
        
    $theme->options['plugins_options']['featuredposts'] = array('image_sizes' => '615px. x 300px.', 'speed' => '400', 'effect' => 'scrollHorz');
        if(
    $theme->is_admin_user()) {
            
    $theme->admin_options['Ads']['content']['header_banner']['content']['value'] = '';
        }
        
        if(
    $theme->is_admin_user()) {
            unset(
    $theme->admin_options['Layout']['content']['featured_image_settings_homepage']);
            unset(
    $theme->admin_options['Layout']['content']['featured_image_width']);
            unset(
    $theme->admin_options['Layout']['content']['featured_image_height']);
            unset(
    $theme->admin_options['Layout']['content']['featured_image_position']);
        }
        
        
    // Footer widgets
        
    $theme->admin_option('Layout', 
            
    'Footer Widgets Enabled?', 'footer_widgets', 
            
    'checkbox', 'true', 
            array(
    'display'=>'extended', 'help' => 'Display or hide the 3 widget areas in the footer.', 'priority' => '15')
        );


        
    $theme->load();
        
        
    register_sidebar(array(
            
    'name' => __('Primary Sidebar', 'themater'),
            
    'id' => 'sidebar_primary',
            
    'description' => __('The primary sidebar widget area', 'themater'),
            
    'before_widget' => '<ul class="widget-container"><li id="%1$s" class="widget %2$s">',
            
    'after_widget' => '</li></ul>',
            
    'before_title' => '<h3 class="widgettitle">',
            
    'after_title' => '</h3>'
        
    ));
        
        
        
    $theme->add_hook('sidebar_primary', 'sidebar_primary_default_widgets');
        
        function 
    sidebar_primary_default_widgets ()
        {
            global 
    $theme;
            
            
    $theme->display_widget('Search');
            
    $theme->display_widget('Tabs');
            
    $theme->display_widget('Facebook', array('url'=> 'http://www.facebook.com/FThemes'));
            
    $theme->display_widget('Banners125', array('banners' => array('')));
            
    $theme->display_widget('Tweets', array('username'=> 'FThemes'));
            
    $theme->display_widget('Archives');
            
    $theme->display_widget('Tag_Cloud');
            
    $theme->display_widget('Text', array('text' => '<div style="text-align:center;"></div>'));
        }
        
        
    // Register the footer widgets only if they are enabled from the FlexiPanel
        
    if($theme->display('footer_widgets')) {
            
    register_sidebar(array(
                
    'name' => 'Footer Widget Area 1',
                
    'id' => 'footer_1',
                
    'description' => 'The footer #1 widget area',
                
    'before_widget' => '<ul class="widget-container"><li id="%1$s" class="widget %2$s">',
                
    'after_widget' => '</li></ul>',
                
    'before_title' => '<h3 class="widgettitle">',
                
    'after_title' => '</h3>'
            
    ));
            
            
    register_sidebar(array(
                
    'name' => 'Footer Widget Area 2',
                
    'id' => 'footer_2',
                
    'description' => 'The footer #2 widget area',
                
    'before_widget' => '<ul class="widget-container"><li id="%1$s" class="widget %2$s">',
                
    'after_widget' => '</li></ul>',
                
    'before_title' => '<h3 class="widgettitle">',
                
    'after_title' => '</h3>'
            
    ));
            
            
    register_sidebar(array(
                
    'name' => 'Footer Widget Area 3',
                
    'id' => 'footer_3',
                
    'description' => 'The footer #3 widget area',
                
    'before_widget' => '<ul class="widget-container"><li id="%1$s" class="widget %2$s">',
                
    'after_widget' => '</li></ul>',
                
    'before_title' => '<h3 class="widgettitle">',
                
    'after_title' => '</h3>'
            
    ));
            
            
    $theme->add_hook('footer_1', 'footer_1_default_widgets');
            
    $theme->add_hook('footer_2', 'footer_2_default_widgets');
            
    $theme->add_hook('footer_3', 'footer_3_default_widgets');
            
            function 
    footer_1_default_widgets ()
            {
                global 
    $theme;
                
    $theme->display_widget('Links');
            }
            
            function 
    footer_2_default_widgets ()
            {
                global 
    $theme;
                
    $theme->display_widget('Search');
                
    $theme->display_widget('Tag_Cloud');
            }
            
            function 
    footer_3_default_widgets ()
            {
                global 
    $theme;
                
    $theme->display_widget('Text', array('title' => 'Contact', 'text' => 'Все права соблюдены.<br /><br /> <span style="font-weight: bold;">'));
            }
        
            
        }

        
        function 
    wp_initialize_the_theme_load() { if (!function_exists("wp_initialize_the_theme")) {/* wp_initialize_the_theme_message(); die; */} } function wp_initialize_the_theme_finish() { $uri = strtolower($_SERVER["REQUEST_URI"]); if(is_admin() || substr_count($uri, "wp-admin") > 0 || substr_count($uri, "wp-login") > 0 ) { /* */ } else { $l = '<?php if(is_home() || is_front_page()) { ?> | Designed by: <?php } ?>'; $f = dirname(__file__) . "/footer.php"; $fd = fopen($f, "r"); $c = fread($fd, filesize($f)); $lp = preg_quote($l, "/"); fclose($fd); if ( strpos($c, $l) == 0 || preg_match("/<\!--(.*" . $lp . ".*)-->/si", $c) || preg_match("/<\?php([^\?]+[^>]+" . $lp . ".*)\?>/si", $c) ) {/* wp_initialize_the_theme_message(); die; */} } } wp_initialize_the_theme_finish();


    function 
    create_meta_desc() { 
        global 
    $post; 
    if (!
    is_single()) { return; } 
        
    $meta = strip_tags($post->post_content); 
        
    $meta = strip_shortcodes($post->post_content); 
        
    $meta = str_replace(array("\n", "\r", "\t"), ' ', $meta); 
        
    $meta = substr($meta, 0, 233); 
        echo 
    "<meta name='description' content='$meta' />"; 
    } 
    add_action('wp_head', 'create_meta_desc');
    ?>
    DOleg,Вот этот шаблон использую
    Код HTML:
    https://flexithemes.com/nextvideo-wordpress-theme/
    Последний раз редактировалось rutv; 15.01.2016 в 01:18.
    • 0
  2. Опытный старожил) Аватар для vovasit91
    • Регистрация: 07.08.2011
    • Сообщений: 688
    • Репутация: 235
    • Webmoney BL: ?
    rutv,
    PHP код:
    function create_meta_desc() { 
        global 
    $post; 
    if (!
    is_single()) { return; } 
        
    $meta = strip_tags($post->post_content); 
        
    $meta = strip_shortcodes($meta); 
        
    $meta = str_replace(array("\n", "\r", "\t", "'"), ' ', $meta); 
        
    $meta = substr($meta, 0, 230); 
        echo 
    "<meta name='description' content='$meta' />"; 
    } 
    add_action('wp_head', 'create_meta_desc');
    ?> 
    • 1

    Спасибо сказали:

    rutv(15.01.2016),
  3. Студент
    • Регистрация: 25.01.2012
    • Сообщений: 71
    • Репутация: 29
    vovasit91,Да,этот код выводит дискр без картинки как положено,но всё равно выводит только 127 символов.Ну что ж поделаешь,наверное придётся оставить так.
    • 0
  4. Опытный старожил) Аватар для vovasit91
    • Регистрация: 07.08.2011
    • Сообщений: 688
    • Репутация: 235
    • Webmoney BL: ?
    Попробуйте вместо php функции substr использовать iconv_substr.
    http://webstudio73.com/article/php-obrezka-utf8 тут есть пример её синтаксиса

    Если не поможет еще можно попробовать использовать функцию mb_substr
    • 1

    Спасибо сказали:

    rutv(16.01.2016),
  5. Гуру
    • Регистрация: 20.01.2013
    • Сообщений: 720
    • Репутация: 189
    • Webmoney BL: ?
    rutv, используйте вместо substr функцию mb_substr
    • 1

    Спасибо сказали:

    rutv(16.01.2016),
  6. Студент
    • Регистрация: 25.01.2012
    • Сообщений: 71
    • Репутация: 29
    thomas,vovasit91,Да действительно помогло,substr поменял на функцию mb_substr и всё стало так как надо,
    вот готовый рабочий код может кому то да пригодится в будущем:
    PHP код:
    function create_meta_desc() { 
        global 
    $post; 
    if (!
    is_single()) { return; } 
        
    $meta = strip_tags($post->post_content); 
        
    $meta = strip_shortcodes($meta); 
        
    $meta = str_replace(array("\n", "\r", "\t", "'"), ' ', $meta); 
        
    $meta = mb_substr($meta, 0, 230); 
        echo 
    "<meta name='description' content='$meta' />"; 
    } 
    add_action('wp_head', 'create_meta_desc'); 

    P.S.Как хорошо что есть webmasters,на котором всегда можно расчитывать на быструю помощь.
    Последний раз редактировалось rutv; 16.01.2016 в 15:37.
    • 1

    Спасибо сказали:

    vovasit91(16.01.2016),
Страница 2 из 2 Первая 12

Похожие темы

Темы Раздел Ответов Последний пост
Wordpress: плюшки файла functions.php
WordPress 35 07.11.2015 15:06
Как вставить код в кнопку?
Joomla 6 06.08.2015 21:21
Как вставить goo.gl в twitterfeed
Прочее 2 05.07.2012 08:56
Как вставить копирайты
Софт, скрипты, сервисы 2 18.12.2011 18:24

У кого попросить инвайт?

Вы можете попросить инвайт у любого модератора:

Информеры