如何链接多个页面,以及如何将插件添加到新的自定义WordPress主题

时间:2020-07-07 21:10:44

标签: php html wordpress

我已经为正在工作的网站创建了自己的WordPress自定义主题。这是我第一次从头开始构建主题!我遇到困难1:将几个页面链接到fron页面或主页。例如,假设我要链接“我们是谁”,页面+“联系我们”,页面等。如何让WordPress了解每个页面都是不同的,并链接到它?这是我到目前为止所做的: 在page.php中,我放置了以下代码:

    <?php get_header(); ?>
<div class="container">
<?php 
    if (have_post()) {
        while(have_post()) {
            the_post();
                get_template_part( 'template-parts/content', 'page');
        }}
    ?>
</div>
<?php get_footer();  ?> 

我还创建了一个content-page.php,在其中放置了HTML代码。 (我用HTML和CSS代码来构建整个过程,就像从头开始构建网站一样。)

我还想知道使用插件时如何将其连接到要添加的页面。例如,如果我要为“联系我们”之类的页面安装WpForms之类的表单,该如何链接呢? 如果我的问题需要更多详细信息,请告诉我

1 个答案:

答案 0 :(得分:0)

如果我理解正确的话... 您是否希望能够显示(链接)几个页面到您的主页? 例如: [这里的首页内容] [在此处连接页面内容] [在此处模糊页面]

如果是,则需要将页面内容拉入主页。

类似的东西:

    <?php
$postid = 0 /*Need to get page id, that's the key */;

//Pull in the page data
$featured_page = get_post($postid);

$thumbnail = get_the_post_thumbnail( $featured_page->ID );

//Only show the excerpt in this case
$content = apply_filters( 'the_content', $featured_page->post_excerpt );

?>

<article id="post-<?php echo $featured_page->ID ?>">
    <header class="entry-header">
    <h1><?php echo $featured_page->post_title ?></h1>
    </header>
    <div class="entry-content">
    <div class="thumbnail">
      <?php echo $thumbnail; ?>
    </div>
    <div>
      <?php echo $content; ?>
    </div>
    </div>

重要!您需要从某处获取页面ID。您可以对其进行硬编码,但是如果有所更改,这是有风险的。您可以设置一个Customizer选项,该选项允许用户选择要使用的页面。

https://codex.wordpress.org/Theme_Customization_API

关于联系表格等。我建议将其作为简码放在页面上,然后显示整页,而不是摘录。

我将此代码用于自己构建的主题。如果您需要更多帮助,请告诉我,我可以告诉您在哪里可以找到它。