问题描述
我正在创建一个不是博客的网站,并且正在使用wordpress进行CMS-简而言之,我什至没有使用wordpress循环。
I am creating a website which is not a blog, and I am using wordpress for my CMS - in short I am not even using the wordpress loop.
网站将显示来自其他人的API等的图形和数据,但我被困在执行此操作的正确方法上,我发现的所有文档都是针对博客或非常模糊的。
The website will display graphs and data from someone else's API and such but I am stuck on what seems to be the right way to do this, and all the documentation I find is for blogs or very very vague.
我希望能够仅使用导入语句而不是自定义模板来创建页面-因为那些似乎仅用于文本,而不是我打算抛在后面的庞大的php,ajax,mysql后端这些页面。
I want to be able to create pages, using just an import statement not a custom template - since those seem to be for text only, and not the huge php, ajax, mysql backend I plan to slap behind these pages.
例如:
// index.php
<?php get_header(); ?>
// Some file, like index_content.php imported into here
<?php get_custom_page_content(); ?>
<?php get_footer(); ?>
// about.php
<?php get_header(); ?>
// Some file, like about_content.php imported into here
<?php get_custom_page_content(); ?>
<?php get_footer(); ?>
似乎很矛盾,因为如果我只是创建一个新的 .php
文件,就像我在下面解释的那样,这一起不利于CMS。我什至没有登录管理面板就可以自己编辑它们,因为如果不直接从菜单项或任何其他内容进行链接,我看不到要为我管理这些文件。我为什么不然后只包含所有内容并完全摆脱Wordpress。我必须在这里丢失一些东西。
It seems very conflicting because if I just make a new .php
file like I explain below, it detracts from the CMS all together. I just edit them myself without even logging into the admin panel, since I see nothing to manage those files for me without directly linking from my menu items or whatever. Why wouldn't I then just @include everything and get rid of Wordpress completely. I must be missing something here.
长短不一,我不知道该如何组织它,从我的研究尝试中,我不知道我是什么。寻找答案。
The long and short of it is, I have no idea how to structure this and from my attempts to research, no idea what I am looking for to answer this.
如何创建上述方案,还是像创建新的 .php一样简单? / code>每个命名页面的文件,
@包括
我想要什么?
How do I go about creating the above scenario, or is it as simple as just creating a new
.php
file for each named page and @including
what I want?
我不
I don't want to get into bad practices.
推荐答案
1)。您可以使用WordPress默认。您将拥有文件
page-index.php
和 page-about.php
,它们将作为模板出现在属性元框。
1) You can use WordPress default Page Templates. You'll have the files
page-index.php
and page-about.php
and they will appear as templates in the attributes meta box.
2)或您可以依赖自定义元字段和框,像默认属性一样制作自己的个人元框。这是通过
add_meta_box
, get_post_meta
和 update_post_meta
完成的。在WordPress问答中查看。
但是,长话短说,即使知道如何使用它们,我还是更喜欢使用来处理,因为它是一个维护良好且功能丰富的插件。
2) Or you can rely in custom meta fields and boxes, making your own personal meta box just like the default Attributes. This is done with
add_meta_box
, get_post_meta
and update_post_meta
. Check the following results in WordPress Answers.
But, long story short, even knowing how to use those, I prefer to use Advanced Custom Fields to handle that, as it's a well maintained and feature rich plugin.
有了适当的自定义元框,只需从预先配置的下拉列表(
索引
,约
)并在您的 page.php
主题文件中使用:
With a custom meta box in place, simply choose from a pre-configured dropdown list (
index
, about
) and in your page.php
theme file use:
global $post;
$include = get_post_meta( $post->ID, 'include_file', true );
get_template_part( 'content', $include );
include_file
是包含以下内容的自定义字段下拉选择。您可以使用 update_post_meta
或在使用ACF创建的字段中自行处理。
include_file
is the custom field that contains the dropdown selection. And you handle it yourself with update_post_meta
or in a field created with ACF.
是捆绑的WP函数,在此示例中文件
example.com/wp-content/themes/YOUR-THEME/content-index.php
或 example.com/wp-content/主题/YOUR-THEME/content-about.php
。
方法1很简单。方法2可以微调更多的细节。可以将两者结合使用。
Method 1 is straight forward. Method 2 enables much more details to be fine-tuned. A combination of both can be used.
这篇关于WordPress自定义页面还是其他?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!