wordpress自定义帖子模板不工作

时间:2013-10-31 02:15:58

标签: php wordpress

我在wordpress仪表板中创建了另一个菜单,它的功能类似于帖子菜单,我想将自定义模板应用到我创建的菜单中。示例,菜单被称为“TEchnologies页面”,在我的编辑器中我创建了一个technologies.php页面,它初始化了我要在我的技术模板上显示的内容,我已经将新的菜单类别注册到functions.php,但问题是wordpress无法识别我为该菜单创建的模板,当我打开内容类型时,它仍然具有正常的外观..

我有这段代码;

的functions.php

  // category
  function TechnologiesRegister() {
     $labels = array(
    'name' => _x('Technologies', 'post type general name'),
    'singular_name' => _x('Technologies', 'post type singular name'),
    'add_new' => _x('Add New Technologies', 'portfolio item'),
    'add_new_item' => __('Add New Technologies'),
    'edit_item' => __('Edit Technologies'),
    'new_item' => __('New Technologies'),
    'view_item' => __('View Technologies'),
    'search_items' => __('Search Technologies'),
    'not_found' => __('Nothing found'),
    'not_found_in_trash' => __('Nothing found in Trash'),
    'parent_item_colon' => ''
);

$args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'query_var' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => null,
    'supports' => array('title', 'editor', 'thumbnail'),
    'rewrite' => true,
    'show_in_nav_menus' => false,
);
   register_post_type('technologies', $args);
 }
    add_action('init', 'TechnologiesRegister');
 // end category

technologies.php

   <?php
     /* Template Name: Technologies Page*/
   ?>

    <?php get_header(); ?>
  <head>
       <style type="text/css">.social-wrap {margin-top: 79px !important;}</style> 
      </head>
    <div class="container technologies">
        <div class="row">

           <?php
             $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
             $args = array('post_type' => 'technologies', 'paged' => $paged, 'posts_per_page' => 500);
     query_posts($args);
    while (have_posts()) : the_post();
        ?>     
        <div class="span3 technologies-icon">
            <?php
            $attachment_id = get_field('image');
            $size = "full";
            $image = wp_get_attachment_image_src($attachment_id, $size);
            ?>
            <img src="<?php echo $image[0]; ?>" class="pull-right" />                
        </div>
        <div class="span9 technologies-desc">
            <h4><?php the_title(); ?></h4>
            <?php the_content(); ?>
        </div>
    <?php endwhile; ?> 

</div>      

1 个答案:

答案 0 :(得分:1)

单凭technologies.php本身并不足以让WordPress自动识别。

您需要根据WordPress codex重命名主题文件archive-technologies.php(for循环)或single-technologies.php(针对单个帖子)。