简体   繁体   English

自定义wordpress页面(使用插件)

[英]Custom wordpress page (using plugin)

I want to create a custom page that has tournament brackets instead of the usual content. 我想创建一个自定义页面,其中包含锦标赛括号,而不是通常的内容。 I have read some of the Wordpress documentation and found how plugins work and how I add admin pages to administer the page. 我已经阅读了一些Wordpress文档,了解了插件的工作原理以及如何添加管理页面来管理页面。

My question is: What is needed to create the page itself (and have it listed on the site)? 我的问题是:创建页面本身需要什么(并在网站上列出)? Do I need to create a custom template that has the majority of the work in it, do I need to have the plugin create the page or where do I start? 我是否需要创建一个包含大部分工作的自定义模板,我是否需要让插件创建页面或从哪里开始?

Also, how do template pages and plugins interoperate? 另外,模板页面和插件如何互操作? Does WP provide me a reference variable to the plugin or do I have to load it "manually"? WP是否为插件提供了参考变量,还是我必须“手动”加载它?

Thanks 谢谢

EDIT: I think I'll reformulate my question. 编辑:我想我会重新提出我的问题。 While the answers have been helpful, they aren't exactly what I've been looking for. 虽然答案很有帮助,但它们并不是我一直在寻找的。

Basically, I want a page where I have some module / code / whatever that controls whatever goes on there. 基本上,我想要一个页面,我有一些模块/代码/控制在那里发生的任何事情。 This means I can't just setup a page since then I can only fill in text. 这意味着我不能只设置页面,因为那时我只能填写文本。 I need a page where I can decide what happens when I go to that page, what is written, submits, etc. I am fairly fluent in PHP, just not Wordpress :) 我需要一个页面,我可以决定当我去那个页面时会发生什么,写什么,提交等等。我相当流利的PHP,只是不是Wordpress :)

The second part is the admin, where I need a page (or several) to control some of the administration stuff of said page. 第二部分是管理员,我需要一个页面(或几个)来控制所述页面的一些管理内容。

I hope this helps with the clarification. 我希望这有助于澄清。

So far answers I've seen are overtly complex. 到目前为止,我看到的答案显然过于复杂。 What you should do is simply this: 你应该做的只是这样:

  1. In WP, create a new page; 在WP中,创建一个新页面; title it "example" - note the slug it generates. 标题为“例子” - 注意它产生的slu .. It should be "example" as well, mimicking the title. 它应该是“例子”,模仿标题。
  2. Create a file in your active theme called page-example.php - mirroring that slug. 在活动主题中创建一个名为page-example.php的文件 - 镜像该slug。
  3. Sandwich your custom PHP with barebones HTML code in page-example.php: 在page-example.php中使用准系统HTML代码将自定义PHP三明治:

<?php get_header(); ?>

<!-- your custom php code goes here --> <! - 你的自定义PHP代码在这里 - >

<?php get_footer(); ?>

Depending on your page, you may need to recreate a few div elements, and possibly toss in a get_sidebar() 根据您的页面,您可能需要重新创建一些div元素,并可能在get_sidebar()中抛出

once a plugin is activated, you can use it from any new page. 一旦激活插件,您就可以从任何新页面使用它。

If I were you, I would encapsulate the logic to show the info for the tournament bracket in a plugin. 如果我是你,我会封装逻辑以在插件中显示锦标赛支架的信息。 Then I would create a template page specific for the page you need. 然后我会创建一个特定于您需要的页面的模板页面。

You can create a new page with a custom template just the same way you create any page, and choosing a custom template on WordPress' menu. 您可以使用自定义模板创建新页面,就像创建任何页面一样,并在WordPress菜单上选择自定义模板。 If you followed the standard page template system in WordPress, the template will appear in the "templates" menu. 如果您按照WordPress中的标准页面模板系统,模板将出现在“模板”菜单中。

: This is **an answer I wrote about cloning CrunchBase over on WordPress Answers (which won't be public for another 18 hours or so). :这是我写的关于在WordPress Answers上克隆CrunchBase的答案(不会再公开18个小时左右)。 It's not written with your question exactly in mind but should be so close that I don't think I need to modify it for you to understand how to apply it. 它不是用你的问题写的,但是应该非常接近我认为我不需要修改它以便你理解如何应用它。

Use Custom Post Type and Custom Taxonomies 使用自定义帖子类型和自定义分类

What you want to look at are Custom Post Types and Custom Taxonomies [see this answer I gave on a very similar subject]. 您要查看的是自定义帖子类型自定义分类 [请参阅我在非常相似的主题上给出的答案 ]。

Example Code for your Company's Post Type and Taxonomies 贵公司的邮政类型和分类的示例代码

With WordPress 3.0 you can create a company custom post type and then one or more custom taxonomies that apply to the company such as category, funding and status. 使用WordPress 3.0,您可以创建company自定义帖子类型,然后创建适用于公司的一个或多个自定义分类,例如类别,资金和状态。 To bootstrap your efforts here's code you can drop in to your theme's functions.php file to get your started: 要在这里引导您的工作代码,您可以访问主题的functions.php文件来启动您的工作:

register_post_type('company',
    array(
        'label'           => __('Companies'),
        'public'          => true,
        'show_ui'         => true,
        'query_var'       => 'company',
        'rewrite'         => array('slug' => 'companies'),
        'hierarchical'    => true,
        'supports'        => array(
            'title',
            'page-attributes',
            'excerpts',
            'thumbnail',
            'custom-fields',
            'editor',
            ),
        )
);

register_taxonomy('company-category', 'company', array(
    'hierarchical'    => true,
    'label'           => __('Categories'),
    'query_var'       => 'company-category',
    'rewrite'         => array('slug' => 'categories' ),
    )
);

register_taxonomy('company-status', 'company', array(
    'hierarchical'    => true,
    'label'           => __('Status'),
    'query_var'       => 'company-status',
    'rewrite'         => array('slug' => 'status' ),
    )
);

register_taxonomy('company-funding', 'company', array(
    'hierarchical'    => true,
    'label'           => __('Funding'),
    'query_var'       => 'company-funding',
    'rewrite'         => array('slug' => 'funding' ),
    )
);

Other Post Types you might want: 您可能需要的其他帖子类型:

If you really want to clone CrunchBase you'd be wanting to create custom post types for each of these (though I'm guess you want something similar but for a different market?): 如果你真的想要克隆CrunchBase,你会想要为每一个创建自定义帖子类型(虽然我猜你想要一些类似的但是针对不同的市场?):

  • People
  • Financial Organizations 金融组织
  • Service Providers 服务供应商
  • Funding Rounds 资金回合
  • Acquisitions 收购

Company Listing Page 公司列表页面

For your company's listing page (like this one on CrunchBase) I'd probably create a WordPress " Page " called " Companies " ( imagine that! ) and then use a post list shortcode plugin like List Pages Shortcode (if you use that one you will need to make a one-line modification to support Custom Post Types like I show here .) 对于贵公司的列表页面(就像CrunchBase上的这个 )我可能会创建一个名为“ 公司 ”的WordPress“ 页面 ”( 想象一下! )然后使用列表页面短代码插件列表插件(如果你使用那个将需要进行单行修改以支持我在此处显示的自定义帖子类型。)

With that plugin and modification you can add the following text to your " Companies " Page and it will list out all the companies in a bulleted list on that page which you can style with CSS: 通过该插件和修改,您可以将以下文本添加到“ 公司 ”页面,它将列出该页面上项目符号列表中的所有公司,您可以使用CSS设置样式:

[list-pages post_type="company"]

Company Specific Layouts 公司特定布局

Then for a custom layout for each company you can make a copy of the theme template file single.php and name it single-company.php and make whatever modifications you want to the layout there. 然后,对于每个公司的自定义布局,您可以制作主题模板文件single.php的副本,并将其命名为single-company.php并对其进行任何修改。

User Company Submissions 用户公司提交的内容

And if you want to let people submit companies consider using Gravity Forms ( not an affiliate link; US$39 per site license and worth every penny.) 如果你想让人们提交公司考虑使用Gravity Forms不是联盟链接;每个站点许可证价值39美元,值得每一分钱。)

If you need more... 如果你需要更多......

There's more I'm sure but that will get you most of the basic functionality you need. 还有更多我确定,但这将为您提供所需的大部分基本功能。 If you need more, ask another question here on WordPress Answers! 如果您需要更多,请在WordPress Answers上提出另一个问题!

Hope this helped. 希望这有帮助。

-Mike -麦克风

Depending on your exact needs, a plugin might be overkill unless your wanting to provide it for consumption on the net as well. 根据您的确切需求,插件可能有点过分,除非您想在网上提供它。 It would definitely be a little more useful as far as separating the login from the template goes, but for personal use it might end up being more work in order to do something that could be handled just as easily by built in functions. 就登录与模板分离而言,这肯定会更有用,但对于个人使用而言,为了做一些可以通过内置函数轻松处理的事情,最终可能会有更多的工作。

Something like this is exactly what the newer "Custom Post Types" in Wordpress 3.0+ are built for. 像这样的东西正是Wordpress 3.0+中较新的“自定义帖子类型”的构建。 Using the new functions you can pretty easily build custom submit forms, and these type of submissions are kept out of the main loop by default, so that content is already separated away from normal blog posts. 使用新功能,您可以非常轻松地构建自定义提交表单,默认情况下,这些类型的提交保留在主循环之外,因此内容已经与普通博客帖子分开。 You can add your specific functions into the default functions.php wordpress uses, or separate it out and just include it manually without having to worry about all the hooks and action calls a "plugin" generally requires. 您可以将您的特定功能添加到默认的functions.php wordpress使用,或将其分开并手动包含它,而不必担心“插件”通常需要的所有挂钩和操作调用。

Using a mix of custom post types and templated pages should be just as useful for you as a full blown plugin, and require less overall Wordpress knowledge to implement. 使用自定义帖子类型和模板化页面的混合对于您来说应该像完整的插件一样有用,并且需要较少的整体Wordpress知识来实现​​。 I highly suggest checking out what Custom Post Types have to offer, the following links should be useful in getting you started: 我强烈建议您查看自定义帖子类型提供的内容,以下链接应该对您有所帮助:

http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress
http://new2wp.com/pro/wordpress-custom-post-types-and-taxonomies-done-right/ http://new2wp.com/pro/wordpress-custom-post-types-and-taxonomies-done-right/
http://kovshenin.com/archives/custom-post-types-in-wordpress-3-0/ http://kovshenin.com/archives/custom-post-types-in-wordpress-3-0/
http://kovshenin.com/archives/extending-custom-post-types-in-wordpress-3-0/ http://kovshenin.com/archives/extending-custom-post-types-in-wordpress-3-0/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM