简体   繁体   English

Php 包括“file.php + 链接”

[英]Php include 'file.php + link'

Is it possible to use "php include" that calls the first link existing in another.php file.是否可以使用“php include”来调用另一个.php 文件中存在的第一个链接。

Here below how my files are structured.下面是我的文件的结构。 What I trying to do is to click PROJECT which will open the file project-one.html我想要做的是单击项目,这将打开文件 project-one.html

I guess:first-child does not work in the HTML file...我猜:第一个孩子在 HTML 文件中不起作用......

in the HTML file I have:在 HTML 文件中,我有:

<ul>
<li><?php include 'menu.php:first-child';?>PROJECT</li>
</ul>

in the PHP file I have:在 PHP 文件中,我有:

<ul>
<li><a href="project-one.html">P1</a></li>
<li><a href="project-two.html">P2</a></li>
</ul>

If you want to have a file that centralises the link creation, you could do like so:如果你想要一个集中链接创建的文件,你可以这样做:

index.php <- you need this file to be PHP (regular HTML files won't run include and php functions and code) index.php <-你需要这个文件是PHP (常规HTML文件不会运行include和 ZE1BFD762321E496C3 函数和代码)

<?php
include 'linkgenerator.php';
?>

<ul>
<li><?php renderlink(1); ?></li>
</ul>

linkgenerator.php链接发生器.php

<?php
function renderlink($linknumber) {
    if ($linknumber == 1) {
        echo "<a href="project-one.html">P1</a>";
    } else if ($linknumber == 2) {
        echo "<a href="project-two.html">P2</a>";
    } 
}

A proper implementation would involve more advanced concepts, but if you are learning this is a good starting point to understand the principles.正确的实现将涉及更高级的概念,但如果您正在学习,这是理解这些原则的一个很好的起点。

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

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