简体   繁体   English

在Wordpress的页面模板中设置动态文本

[英]Set dynamic text within page templates in wordpress

I am quite new to creating websites with WordPress so I might ask a question which is quite straightforward but I could not find any suitable tutorials/answers to guide me. 我刚开始使用WordPress创建网站,所以我可能会问一个很简单的问题,但找不到任何合适的教程/答案来指导我。

I want to create dynamic text elements which I can edit within Wordpress. 我想创建可以在Wordpress中编辑的动态文本元素。 I have created a full website in HTML, CSS, and Javascript and I converted it to Wordpress pages. 我已经创建了一个完整的HTML,CSS和Javascript网站,并将其转换为Wordpress页面。

Let's have a look for example to my about page: about.php 让我们来看一下我的About页面: about.php

<?php
    get_header();
    // Template Name: About
?>
<div class="row fullwidth">
    <div class="col-md-6 col-sm-6 about-section-right">
        <h2>Titel example</h2>
        <p>A very long text.....</p>
        <p>Another very long text</p>
        <a href="contact" class="btn">Contact <i class="fa fa-chevron-circle-right" aria-hidden="true"></i></a>
    </div>

</div>
<?php
    get_footer();
?>

Now I want to be able to edit the title ( <h2> ) and text ( <p> ) and hyperlink ( <a> ) text in Wordpress. 现在,我希望能够在Wordpress中编辑标题( <h2> )和文本( <p> )以及超链接( <a> )文本。 So that I can change the title etc. 这样我可以更改标题等。

I tried to use Advance custom fields by calling: the_field() or by using a shortcode but the text did not show up on my page. 我试图通过调用the_field()或使用简码来使用高级自定义字段,但是文本未显示在页面上。

So my question is: is Advanced custom fields the best way to do this because I can not make it work and are there other ways of achieving editing text within Wordpress. 所以我的问题是:高级自定义字段是执行此操作的最佳方法,因为我无法使其工作,并且还有其他方法可以在Wordpress中实现编辑文本。

For pages just use the WordPress loop: https://codex.wordpress.org/The_Loop 对于页面,只需使用WordPress循环即可: https : //codex.wordpress.org/The_Loop

    <?php
        get_header();

if(have_posts()):
while(have_posts()): the_post();
    ?>
    <div class="row fullwidth">
        <div class="col-md-6 col-sm-6 about-section-right">
            <?php the_content(); ?>
        </div>

    </div>
    <?php
endwhile;
endif;

        get_footer();
    ?>

You create a page "About" in the backend in "Pages" and here you go. 您在“页面”的后端创建页面“关于”,然后就可以开始了。 All contents within the_content(); the_content();所有内容the_content(); are created by the WYSIWYG editor of the page. 由页面的WYSIWYG编辑器创建。

Custom fields are for adding any custom or specific information to a post or page. 自定义字段用于将任何自定义或特定信息添加到帖子或页面。

Most probably you do not need an extra template file for your about page and you can use a page.php file for all pages. 最有可能您不需要关于页面的额外模板文件,并且可以对所有页面使用page.php文件。

You can conditionally include data depending on custom fields and/or the page you are on. 您可以根据自定义字段和/或所在页面有条件地包括数据。

Read more about custom fields here: https://codex.wordpress.org/Custom_Fields 在此处阅读有关自定义字段的更多信息: https : //codex.wordpress.org/Custom_Fields

... and about conditional tags here: https://codex.wordpress.org/Conditional_Tags ...以及此处的条件标签: https//codex.wordpress.org/Conditional_Tags

It will help you understanding it. 它将帮助您理解它。

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

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