【问题标题】:I can't modify the template i assigned to the Posts page (Wordpress)我无法修改分配给帖子页面的模板 (Wordpress)
【发布时间】:2011-04-07 04:45:00
【问题描述】:

我创建了 2 个文件:home.phpblog.php。第一个设置为我的首页,后一个设置为帖子页面。当我修改home.php 时,我可以看到更改(例如删除侧边栏)。但是当我尝试修改 blog.php 时,没有任何反应。

我是否必须修改其他 .php 文件才能看到博客(帖子页面)页面中的更改?

home.php

<?php
/*
Template Name: Home
*/

get_header(); ?>

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

     <?php if ( is_front_page() ) { ?>
      <h2><?php the_title(); ?></h2>
     <?php } else { ?>
      <h1><?php the_title(); ?></h1>
     <?php } ?>

      <?php the_content(); ?>
      <?php wp_link_pages( array( 'before' => '' . __( 'Pages:', 'twentyten' ), 'after' => '' ) ); ?>
      <?php edit_post_link( __( 'Edit', 'twentyten' ), '', '' ); ?>

    <?php comments_template( '', true ); ?>

<?php endwhile; ?>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

blog.php:

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

     <?php if ( is_front_page() ) { ?>
      <h2><?php the_title(); ?></h2>
     <?php } else { ?>
      <h1><?php the_title(); ?></h1>
     <?php } ?>

      <?php the_content(); ?>
      <?php wp_link_pages( array( 'before' => '' . __( 'Pages:', 'twentyten' ), 'after' => '' ) ); ?>
      <?php edit_post_link( __( 'Edit', 'twentyten' ), '', '' ); ?>

    <?php comments_template( '', true ); ?>

<?php endwhile; ?>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

【问题讨论】:

    标签: wordpress templates


    【解决方案1】:

    这里有几个我认为对你有帮助的链接:

    http://codex.wordpress.org/WordPress_Lessons#Customizing_Templates
    http://codex.wordpress.org/Template_Hierarchy

    我有几个问题:

    1. 为什么两个模板中的代码相同?头版永远不会与单个帖子相同。
    2. 为什么选择使用blog.php 而不是single.php?当你打开一个帖子时,WP 会自动使用 single.php。
    3. 您是否在设置中设置了哪个页面应该是首页?
    4. 如果您正在创建模板,那么您必须在文件顶部有模板名称(在 blog.php 中没有)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-27
      • 1970-01-01
      • 1970-01-01
      • 2013-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多