【问题标题】:wordpress custom post template not workingwordpress 自定义帖子模板不起作用
【发布时间】:2013-11-10 21:57:54
【问题描述】:

我在 wordpress 仪表板中创建了另一个菜单,它的功能类似于帖子菜单,我想将自定义模板应用于我创建的那个菜单。示例,菜单名为“TEchnologies Page”,在我的编辑器中,我创建了一个 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>      

【问题讨论】:

  • 所以您注册了一个自定义帖子类型,然后您在页面上循环该帖子类型。如果你不设计它,它看起来不会有什么不同。把它放在你的 .css -> .technologies {border: 10px solid red;}
  • 我的问题是,wordpress 无法识别我创建的模板,它无法识别此文件 technologies.php..这可能是什么问题?..
  • 在页面编辑器右侧的页面模板部分中,技术页面模板是否是选项之一?
  • @loQ - 是的,但内容没有改变,它应该有图片上传功能..
  • 您是否制作了页面,然后选择了正确的模板?或者这将是一个像杂志或博客文章一样循环的“技术”列表?在这种情况下,您需要一个“archive-technology.php”。你能改写你的问题,说出你真正想要的并使用正确的词吗?那会澄清的。同样,要明确一点:您注册了一个帖子类型(这会在管理面板中添加一个菜单项) - 然后您从该帖子类型循环 the image 和 the title 和 the content。

标签: php wordpress


【解决方案1】:

仅仅technologies.php 本身不足以让 WordPress 自动识别。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-25
    • 2017-11-20
    相关资源
    最近更新 更多