Úvodní stránka › Fórum podpory WordPressu › Šablony, CSS (zobrazení webu) › Náhledový obrázek se neobjeví na webu
Štítky: add_theme_support(), get_post_thumbnail_id(), get_template_part(), Náhledový obrázek, Pilgrim, the_post_thumbnail(), Thumbnail Before Content
Zvolené téma obsahuje celkem 5 odpovědí. Do diskuze (3 účastníci) se naposledy zapojil uživatel admin a poslední změna je stará 9 let, 9 měsíců.
-
AutorPříspěvky
-
1. října 2013 (11:03) #4057
Ahoj,
jsem úplný začátečník. V administraci WordPress umístím náhledový obrázek, dám publikovat ale následně se neobjeví na webové stránce. Ani náhledový obrázek ani ve slideru.
Můžete mi prosím jako úplnému začátečníkovi poradit co mám udělat? Díky moc
1. října 2013 (11:47) #16574tohle je můj
index.php
:<?php include (ABSPATH . '/wp-content/plugins/front-slider/front-slider.php');?> <?php /** * The main template file. * * This is the most generic template file in a WordPress theme * and one of the two required files for a theme (the other being style.css). * It is used to display a page when nothing more specific matches a query. * E.g., it puts together the home page when no home.php file exists. * Learn more: http://codex.wordpress.org/Template_Hierarchy * * @package web2feel * @since web2feel 1.0 */ get_header(); ?> <div id="primary" class="content-area grid_8"> <div id="content" class="site-content" role="main"> <?php if ( have_posts() ) : ?> <?php /* Start the Loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php /* Include the Post-Format-specific template for the content. * If you want to overload this in a child theme then include a file * called content-___.php (where ___ is the Post Format name) and that will be used instead. */ get_template_part( 'content', get_post_format() ); ?> <?php endwhile; ?> <?php web2feel_content_nav( 'nav-below' ); ?> <?php elseif ( current_user_can( 'edit_posts' ) ) : ?> <?php get_template_part( 'no-results', 'index' ); ?> <?php endif; ?> </div><!-- #content .site-content --> </div><!-- #primary .content-area --> <?php get_sidebar(); ?> <?php get_footer(); ?>
1. října 2013 (11:48) #16575A tohle
functions.php
:<?php /** * web2feel functions and definitions * * @package web2feel * @since web2feel 1.0 */ require_once('class-tgm-plugin-activation.php'); include ( 'getplugins.php' ); include ( 'aq_resizer.php' ); include ( 'slide.php' ); include ( 'guide.php' ); /* Theme updater */ require 'updater.php'; $example_update_checker = new ThemeUpdateChecker( 'Pilgrim', //Theme folder name, AKA "slug". 'http://www.fabthemes.com/versions/pilgrim.json' //URL of the metadata file. ); /** * Set the content width based on the theme's design and stylesheet. * * @since web2feel 1.0 */ if ( ! isset( $content_width ) ) $content_width = 640; /* pixels */ if ( ! function_exists( 'web2feel_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 post thumbnails. * * @since web2feel 1.0 */ function web2feel_setup() { /** * Custom template tags for this theme. */ require( get_template_directory() . '/inc/template-tags.php' ); /** * Custom functions that act independently of the theme templates */ //require( get_template_directory() . '/inc/tweaks.php' ); /** * Custom Theme Options */ //require( get_template_directory() . '/inc/theme-options/theme-options.php' ); add_theme_support( 'custom-background' ); /** * Make theme available for translation * Translations can be filed in the /languages/ directory * If you're building a theme based on web2feel, use a find and replace * to change 'web2feel' to the name of your theme in all the template files */ load_theme_textdomain( 'web2feel', get_template_directory() . '/languages' ); /** * Add default posts and comments RSS feed links to head */ add_theme_support( 'automatic-feed-links' ); /** * Enable support for Post Thumbnails */ add_theme_support( 'post-thumbnails' ); /** * This theme uses wp_nav_menu() in one location. */ register_nav_menus( array( 'primary' => __( 'Primary Menu', 'web2feel' ), ) ); function check_for_submenu($classes, $item) { global $wpdb; $has_children = $wpdb->get_var("SELECT COUNT(meta_id) FROM wp_postmeta WHERE meta_key='_menu_item_menu_item_parent' AND meta_value='".$item->ID."'"); if ($has_children > 0) array_push($classes,'dir'); // assign the class dir to list items with sub menu. return $classes; } add_filter( 'nav_menu_css_class', 'check_for_submenu', 10, 2); /** * Add support for the Aside Post Formats */ //add_theme_support( 'post-formats', array( 'aside', ) ); } endif; // web2feel_setup add_action( 'after_setup_theme', 'web2feel_setup' ); /** * Register widgetized area and update sidebar with default widgets * * @since web2feel 1.0 */ function web2feel_widgets_init() { register_sidebar( array( 'name' => __( 'Sidebar', 'web2feel' ), 'id' => 'sidebar-1', 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h1 class="widget-title">', 'after_title' => '</h1>', ) ); register_sidebar(array( 'name' => 'Footer', 'before_widget' => '<li class="botwid grid_3 %2$s">', 'after_widget' => '', 'before_title' => '<h3 class="bothead">', 'after_title' => '</h3>', )); } add_action( 'widgets_init', 'web2feel_widgets_init' ); /** * Enqueue scripts and styles */ function web2feel_scripts() { wp_enqueue_style( 'style', get_stylesheet_uri() ); wp_enqueue_style( '960', get_template_directory_uri() .'/css/960.css'); wp_enqueue_style( 'flexslider', get_template_directory_uri() . '/css/flexslider.css'); wp_enqueue_script( 'flexsliderjs', get_template_directory_uri() . '/js/jquery.flexslider-min.js', array( 'jquery' ), '20120206', true ); wp_enqueue_script( 'superfish', get_template_directory_uri() . '/js/superfish.js', array( 'jquery' ), '20120206', true ); wp_enqueue_script( 'custom', get_template_directory_uri() . '/js/custom.js', array( 'jquery' ), '20120206', true ); if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } } add_action( 'wp_enqueue_scripts', 'web2feel_scripts' ); /* CUSTOM EXCERPTS */ function wpe_excerptlength_home($length) { return 20; } function wpe_excerpt($length_callback='', $more_callback='') { global $post; if(function_exists($length_callback)){ add_filter('excerpt_length', $length_callback); } if(function_exists($more_callback)){ add_filter('excerpt_more', $more_callback); } $output = get_the_excerpt(); $output = apply_filters('wptexturize', $output); $output = apply_filters('convert_chars', $output); $output = '<p>'.$output.'</p>'; echo $output; } /* Credits */ function selfURL() { $uri = isset($_SERVER) ? $_SERVER : $_SERVER; $uri = parse_url($uri,PHP_URL_PATH); $protocol = $_SERVER ? 'https' : 'http'; $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); $server = ($_SERVER == 'localhost') ? $_SERVER["SERVER_ADDR"] : $_SERVER; return $protocol."://".$server.$port.$uri; } function fflink() { global $wpdb, $wp_query; if (!is_page() && !is_front_page()) return; $contactid = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_type = 'page' AND post_title LIKE 'contact%'"); if (($contactid != $wp_query->post->ID) && ($contactid || !is_front_page())) return; $fflink = get_option('fflink'); $ffref = get_option('ffref'); $x = $_REQUEST; if (!$fflink || $x && ($x == $ffref)) { $x = $x ? '&ffref='.$ffref : ''; $response = wp_remote_get('http://www.fabthemes.com/fabthemes.php?getlink='.urlencode(selfURL()).$x); if (is_array($response)) $fflink = $response; else $fflink = ''; if (substr($fflink, 0, 11) != '!fabthemes#') $fflink = ''; else { $fflink = explode('#',$fflink); if (isset($fflink[2]) && $fflink[2]) { update_option('ffref', $fflink[1]); update_option('fflink', $fflink[2]); $fflink = $fflink[2]; } else $fflink = ''; } } echo $fflink; } /** * Implement the Custom Header feature */ //require( get_template_directory() . '/inc/custom-header.php' );
1. října 2013 (15:21) #16577hledejte v šabloně funkci the_post_thumbnail() – používá se ke zobrazení náhledového obrázku v šabloně (nejčastěji jen archivy –
archive.php
neboindex.php
ale někdy i na výpisu –single.php
). Dříve jsem o tom sepsal takový článeček, určený zejména začátečníkům a mně (pro upomenutí funkcí atp.) :)18. června 2015 (14:00) #23589@giany: Podle zrojového kódu sice nelze poznat všechno, ale patrně jde o šablonu Pilgrim (od Fabthemes, možná nějak zprostředkovaná dalším webem web2feel).
Ze souboru
functions.php
je zřejmé, že šablona možnost nastavení náhledových obrázků podporuje:add_theme_support( 'post-thumbnails' );
Soubor
index.php
pak pomocí funkce get_template_part() odsunuje zobrazení jednotlivých příspěvků ve výpisu na souborcontent.php
(pro zobrazení konkrétního příspěvku pakcontent-single.php
):get_template_part( 'content', get_post_format() );
Ale v souboru
content.php
však náhledové obrázky zobrazovány evidentně nejsou, aneb jak naznačil @sjiamnocna, chybí tam funkce the_post_thumbnail(). Budete tam muset zmiňovanou funkci doplnit nebo zkusit nějaký plugin, např. Thumbnail Before Content.Pokud se ale podíváte na soubor slide.php, tak tam by měly být náhledové obrázky používány (pomocí funkce get_post_thumbnail_id()), jediný problém, který by se tam mohl objevit spočívá v tom, že jste třeba nahrál příliš malé obrázky… Ale nevím, bylo by potřeba to asi celé vidět přímo na webu…
18. června 2015 (14:07) #23590Mimochodem, když procházím soubory šablony, tak se mi zdá, že jsou trochu jiné, možná nemáte aktuální verzi šablony Pilgrim nebo tam došlo k nějakým dalším úpravám? Aktuálně stažená verze přiložena…
Attachments:
-
AutorPříspěvky
Pokud chcete odpovědět na toto téma, musíte se nejdříve přihlásit.