简体   繁体   English

向WordPress页面添加内容

[英]Adding content to wordpress page

So, i finally got my css and js scripts to load on WP 所以,我终于让我的css和js脚本加载到WP

Now there is but one thing i need to get done. 现在,我只需要完成一件事。

i have my own theme, including header.php, footer.php, page.php 我有自己的主题,包括header.php,footer.php,page.php

header.php and footer.php is working just fine, loading scripts and showing properly, but now i need to add all the other content. header.php和footer.php可以正常工作,加载脚本并正确显示,但是现在我需要添加所有其他内容。

my page.php is currently: 我的page.php当前是:

<?php /* Template Name: CustomPageT1 */ ?>

<?php get_header(); ?>

<?php the_content(); ?>

<?php get_footer(); ?>

I would need to somehow add html content to pages, i have about 20 ready made .php pages which needs to be transfered to WP. 我需要以某种方式将html内容添加到页面,我大约有20个现成的.php页面需要转移到WP。

Soooo how do i go about making new page (pages -> add new) and using page template while getting the html content to show up? Soooo我该如何制作新页面(页面->添加新页面)并使用页面模板同时显示html内容?

I've tried to just make new page and in text mode add up all the html into page, but it only shows empty page with header and footer, so the problem is most likely the page.php and i have no idea how to get it to work. 我试图制作新页面,并在文本模式下将所有html加到页面中,但是它只显示带有页眉和页脚的空页面,因此问题很可能是page.php,我不知道如何获取它起作用。

You are on the good way. 您情况很好。 While developing a custom theme from scratch is a great challenge it's not too hard. 从头开始开发自定义主题是一个巨大的挑战,但这并不难。

I could recommend to take it easy and follow this tutorial I found really helpful some time ago, I learned a lot there: 我可以建议您放轻松一点,并按照前段时间发现的真正有用的本教程学习。

Developing a WordPress Theme from Scratch 从头开始开发WordPress主题

You must have the official source documentation always in your mind: 您必须始终牢记官方源文件:

Theme Development 主题开发

Do some reading and you will see that making themes is really fun and gratifying :) 阅读一些内容,您会发现制作主题真的很有趣,也很令人满意:)

EDIT: I would recommend picking a good starter theme or framework and work using child themes . 编辑:我建议选择一个好的入门主题或框架,并使用子主题进行工作。 You have plenty of them to pick. 您有很多可供选择。

You can do look like this: 您可以这样做:

<?php /* Template Name: CustomPageT1 */ ?>

<?php get_header(); ?>

<?php   
    while ( have_posts() ) : the_post(); 
        the_content();
    endwhile; 
?>
<?php get_footer(); ?>
  1. To get started adding a new page to your WordPress site, find the Pages menu in the WordPress Dashboard Navigation menu. 要开始向您的WordPress网站添加新页面,请在WordPress仪表板导航菜单中找到“页面”菜单。 Click Add new. 单击添加新。

The WordPress page editor looks nearly identical to the post editor, except for a few different boxes located on the right side of the screen. WordPress页面编辑器看起来与帖子编辑器几乎相同,除了位于屏幕右侧的几个不同的框。

  1. Add the title of the page, like About. 添加页面标题,例如关于。 Note: If you have pretty permalinks set up, the title of your page will also be the URL slug. 注意:如果您设置了漂亮的永久链接,则页面标题也将是URL slug。

  2. Next, add some content. 接下来,添加一些内容。

  3. The Publish section of the page editor is exactly the same as for writing posts. 页面编辑器的“发布”部分与撰写帖子完全相同。 When you're ready to publish, you can either publish immediately, save this or a draft, or schedule the page to be published later. 准备发布时,可以立即发布,保存此文本或草稿,也可以安排页面稍后发布。

  4. The Page Attributes section applies a parent page and template to your new page. “页面属性”部分将父页面和模板应用于您的新页面。 For the Parent section, you can arrange your pages into hierarchies. 对于“父级”部分,您可以将页面排列为层次结构。 For example, you could create this new page with additional pages under it. 例如,您可以在此新页面下创建其他页面。 There are no limits to how many levels you can nest pages. 可以嵌套页面的级别没有限制。

  5. Some WordPress themes have custom page templates, so the next Template section allows you to apply a template to your new page. 某些WordPress主题具有自定义页面模板,因此下一个“模板”部分允许您将模板应用于新页面。

  6. The Order box allows you to order your page numerically. “订购”框使您可以按数字顺序订购页面。 Pages are usually ordered alphabetically, but you can choose your own order by entering a number in this field. 页面通常按字母顺序排序,但是您可以通过在此字段中输入数字来选择自己的顺序。

  7. Preview the page one last time, then click Publish. 上次预览页面,然后单击“发布”。 You've added a new page to your WordPress site. 您已将新页面添加到WordPress网站。

This is how your your index.php should look like : 这就是您的index.php的样子:

<?php
 get_header();?>

<div class="YourContainer">

 <div class="Whatever">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  <div class="ContentSectionDiv">

   <?php the_content();?>

  </div>
  <?php endwhile; ?>
  <?php else: ?>
<?php endif; ?>
 </div>
</div>


 <?php get_footer();?>
you can make also a custom loop
 <?php
 $arg = array("post_type" => "services",
                "posts_per_page" => 9,
                "order_by" => "date",
                "order" => "ASC",

            );

            $services = new WP_Query($arg);
            if ($services->have_posts()):;

            while ($services->have_posts()):$services->the_post();
                the_content();             
               endwhile;
            endif;
            ?>

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

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