Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress对帖子的评论-function.php hack_Wordpress_Wordpress Theming_Themes - Fatal编程技术网

Wordpress对帖子的评论-function.php hack

Wordpress对帖子的评论-function.php hack,wordpress,wordpress-theming,themes,Wordpress,Wordpress Theming,Themes,我找到了这篇关于如何在我的移动网站上显示我的评论框的文章 这假设我的表前缀是“wp_uu”,而我的前缀是“wp_svkc_u” 第一个问题是如何修改下面的代码以考虑不同的前缀 function enable_comments_for_all(){ global $wpdb; $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET comment_status = 'open'")); // Enable co

我找到了这篇关于如何在我的移动网站上显示我的评论框的文章

这假设我的表前缀是“wp_uu”,而我的前缀是“wp_svkc_u”

第一个问题是如何修改下面的代码以考虑不同的前缀

function enable_comments_for_all(){
    global $wpdb;
    $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET comment_status = 'open'")); // Enable comments
    $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET ping_status = 'open'")); // Enable trackbacks
} enable_comments_for_all();
二,。在我的主题的function.php中,我把它放在哪里,这样当我更新它时它不会抛出错误

    <?php
/**
 * Cenote functions and definitions
 *
 * @link    https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package cenote
 */

if ( ! function_exists( 'cenote_setup' ) ) :
    /**
     * Sets up theme defaults and registers support for various WordPress features.
     *
     * Note that this function is hooked into the after_setup_theme hook, which
     * runs before the init hook. The init hook is too late for some features, such
     * as indicating support for post thumbnails.
     */
    function cenote_setup() {
        /*
         * Make theme available for translation.
         * Translations can be filed in the /languages/ directory.
         * If you're building a theme based on cenote, use a find and replace
         * to change 'cenote' to the name of your theme in all the template files.
         */
        load_theme_textdomain( 'cenote', get_template_directory() . '/languages' );

        // Add default posts and comments RSS feed links to head.
        add_theme_support( 'automatic-feed-links' );

        /*
         * Let WordPress manage the document title.
         * By adding theme support, we declare that this theme does not use a
         * hard-coded <title> tag in the document head, and expect WordPress to
         * provide it for us.
         */
        add_theme_support( 'title-tag' );

        /*
         * Enable support for Post Thumbnails on posts and pages.
         *
         * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
         */
        add_theme_support( 'post-thumbnails' );

        /**
         * Enable support for post formats
         *
         * @link https://developer.wordpress.org/themes/functionality/post-formats/
         */
        add_theme_support( 'post-formats', array( 'gallery', 'link', 'image', 'quote', 'video', 'audio' ) );

        // This theme uses wp_nav_menu() in one location.
        register_nav_menus( array(
            'tg-menu-primary'    => esc_html__( 'Primary', 'cenote' ),
            'tg-menu-header-top' => esc_html__( 'Header Top', 'cenote' ),
        ) );

        /*
         * Switch default core markup for search form, comment form, and comments
         * to output valid HTML5.
         */
        add_theme_support( 'html5', array(
            'search-form',
            'comment-form',
            'comment-list',
            'gallery',
            'caption',
        ) );

        // Set up the WordPress core custom background feature.
        add_theme_support( 'custom-background', apply_filters( 'cenote_custom_background_args', array(
            'default-color' => 'ffffff',
            'default-image' => '',
        ) ) );

        // Add theme support for selective refresh for widgets.
        add_theme_support( 'customize-selective-refresh-widgets' );

        /**
         * Add support for core custom logo.
         *
         * @link https://codex.wordpress.org/Theme_Logo
         */
        add_theme_support( 'custom-logo', array(
            'height'      => 250,
            'width'       => 250,
            'flex-width'  => true,
            'flex-height' => true,
        ) );

        add_editor_style();
    }
endif;
add_action( 'after_setup_theme', 'cenote_setup' );

/**
 * Custom image sizes for theme.
 */
function cenote_image_sizes() {

    // Set default post thumbnail. 16:9.
    set_post_thumbnail_size( 768, 432, true );
    // Large full width image.
    add_image_size( 'cenote-full-width', 1160, 653, true );
    // 3:4.
    add_image_size( 'cenote-post', 600, 400, true );
    // Auto size.
    add_image_size( 'cenote-post-auto', 600, 9999, false );

}
add_action( 'after_setup_theme', 'cenote_image_sizes' );
/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
function cenote_content_width() {
    $GLOBALS['content_width'] = apply_filters( 'cenote_content_width', 640 );
}

add_action( 'after_setup_theme', 'cenote_content_width', 0 );

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function cenote_widgets_init() {
    register_sidebar( array(
        'name'          => esc_html__( 'Sidebar', 'cenote' ),
        'id'            => 'sidebar-1',
        'description'   => esc_html__( 'Add widgets here.', 'cenote' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h2 class="widget-title">',
        'after_title'   => '</h2>',
    ) );

    register_sidebar( array(
        'name'          => esc_html__( 'Footer 1', 'cenote' ),
        'id'            => 'footer-sidebar-1',
        'description'   => esc_html__( 'Add widgets here to show on footer 1.', 'cenote' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h2 class="widget-title">',
        'after_title'   => '</h2>',
    ) );

    register_sidebar( array(
        'name'          => esc_html__( 'Footer 2', 'cenote' ),
        'id'            => 'footer-sidebar-2',
        'description'   => esc_html__( 'Add widgets here to show on footer 2.', 'cenote' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h2 class="widget-title">',
        'after_title'   => '</h2>',
    ) );

    register_sidebar( array(
        'name'          => esc_html__( 'Footer 3', 'cenote' ),
        'id'            => 'footer-sidebar-3',
        'description'   => esc_html__( 'Add widgets here to show on footer 3.', 'cenote' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h2 class="widget-title">',
        'after_title'   => '</h2>',
    ) );

    register_sidebar( array(
        'name'          => esc_html__( 'Footer 4', 'cenote' ),
        'id'            => 'footer-sidebar-4',
        'description'   => esc_html__( 'Add widgets here to show on footer 4.', 'cenote' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h2 class="widget-title">',
        'after_title'   => '</h2>',
    ) );
}

add_action( 'widgets_init', 'cenote_widgets_init' );

/**
 * Enqueue scripts and styles.
 */
function cenote_scripts() {
    $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';

    wp_enqueue_style( 'cenote-style', get_stylesheet_uri() );
    wp_enqueue_style( 'themegrill-icons', get_template_directory_uri() . '/assets/css/themegrill-icons' . $suffix . '.css', '1.0' );

    wp_enqueue_script( 'cenote-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix' . $suffix . '.js', array(), '20151215', true );
    wp_enqueue_script( 'hammer', get_template_directory_uri() . '/assets/js/hammer' . $suffix . '.js', array(), '2.0.8', true );

    // Load Swiper on Gallery post format.
    wp_enqueue_script( 'swiper', get_template_directory_uri() . '/assets/js/swiper' . $suffix . '.js', array(), '4.2.0', true );
    wp_enqueue_style( 'swiper', get_template_directory_uri() . '/assets/css/swiper' . $suffix . '.css', '4.2.0' );

    // Load headroom if sticky header is enabled.
    if ( true === get_theme_mod( 'cenote_header_sticky_option', true ) ) {
        wp_enqueue_script( 'headroom', get_template_directory_uri() . '/assets/js/headroom' . $suffix . '.js', array(), '0.9.4', true );
    }

    // Only load masonry script if enabled.
    if ( ( is_archive() || is_home() ) && 'tg-archive-style--masonry' === get_theme_mod( 'cenote_archive_style', 'tg-archive-style--masonry' ) ) {
        wp_enqueue_script( 'masonry', get_template_directory_uri() . '/assets/js/masonry.pkgd' . $suffix . '.js', array(), '4.2.0', true );
        wp_enqueue_script( 'imagesloaded', get_template_directory_uri() . '/assets/js/imagesloaded.pkgd' . $suffix . '.js', array(), '4.1.4', true );
    }

    wp_enqueue_script( 'cenote-custom', get_template_directory_uri() . '/assets/js/cenote-custom' . $suffix . '.js', array(), '1.0.0', true );

    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
        wp_enqueue_script( 'comment-reply' );
    }
}

add_action( 'wp_enqueue_scripts', 'cenote_scripts' );

/**
 * Implement the Custom Header feature.
 */
require get_template_directory() . '/inc/custom-header.php';

/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/template-tags.php';

/**
 * Functions which enhance the theme by hooking into WordPress.
 */
require get_template_directory() . '/inc/template-functions.php';

/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/customizer.php';

/**
 * Meta boxes.
 */
require get_template_directory() . '/inc/meta-boxes.php';

/**
 * Widget for showing recent post
 */
require get_template_directory() . '/inc/widgets/class-cenote-widget-recent-posts.php';

/**
 * Load Jetpack compatibility file.
 */
if ( defined( 'JETPACK__VERSION' ) ) {
    require get_template_directory() . '/inc/jetpack.php';
}

/**
 * Load WooCommerce compatibility file.
 */
if ( class_exists( 'WooCommerce' ) ) {
    require get_template_directory() . '/inc/woocommerce.php';
}

/**
 * Add Kirki customizer library file
 */
require get_template_directory() . '/inc/kirki/kirki.php';

/**
 * Add Kirki options file
 */
require get_template_directory() . '/inc/customizer/kirki-customizer.php';

/**
 * Add theme css class control file
 */
require get_template_directory() . '/inc/template-css-class.php';

/**
 * Load breadcrumb trail file if enabled.
 */
if ( true === get_theme_mod( 'cenote_breadcrumb', true ) ) {
    require get_template_directory() . '/inc/compatibility/class-breadcrumb-trail.php';
}

/**
 * Load Demo Importer Configs.
 */
if ( class_exists( 'TG_Demo_Importer' ) ) {
    require get_template_directory() . '/inc/demo-config.php';
}

/**
 * Load TGMPA Configs.
 */
require_once get_template_directory() . '/inc/tgm-plugin-activation/class-tgm-plugin-activation.php';
require_once get_template_directory() . '/inc/tgm-plugin-activation/tgmpa-cenote.php';

为什么要费这么大的劲才能启用评论?为什么不选中“管理”部分的复选框来启用它们呢?是否有一些我没有的定制不允许这样做?我已经没有了,但是评论框只显示在PC版本上,而不是手机或平板电脑上,它也只显示在新帖子上,而不是现有的onesAh上,所以,您希望运行此代码,以便在所有以前的帖子上启用注释,并且此代码与移动设备上的注释可见性问题无关?我希望在所有以前的帖子上都使用此代码,因为尽管启用了此代码,但它不会显示。它也没有显示手机,所以我想一举两得。php在加载时运行。我看不出您的代码如何解决在移动设备上看不到的注释。css(bootstrap?)是否可能导致评论无法在手机上显示?此外,从管理面板,您可以批量编辑您的旧文章,以启用评论。