Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7640107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:35:29+00:00 2026-05-31T08:35:29+00:00

I would like to create a function for the common navigation links on my

  • 0

I would like to create a function for the common navigation links on my website. I thought I could create a php function and call it but I don’t know how to set it up.

This is what I have:

<div class="left_side">
   <ul>
      <li><a href="page1.php">First Page</a></li>
      <li><a href="page2.php">Second Page</a></li>
      <li><a href="page3.php">Third Page</a></li>
   </ul>
</div>
<div class="right_side">
   <!-- contents of this page -->
</div>

Since the links on the left_side are the same for every page, how do I create a php function so that it can be called from several locations?

Ie. I would like it to look something like:

html:

<?php left_side() ?>
<div class="right_side">
   <!-- content of this page -->
</div>
php:
function left_side()
{
echo 
<div class="left_side">
   echo   
   <ul>
      echo        
      <li><a href="page1.php">First Page</a></li>
      echo        
      <li><a href="page2.php">Second Page</a></li>
      echo        
      <li><a href="page3.php">Third Page</a></li>
      echo    
   </ul>
   echo 
</div>
}
Most of the server code is in php.  So it would have to look something like this:
<?php
   session_start()
   require_once("php.php"); // the above php code with the left_side() function
   function showPage()
   {
        include("html.html"); // the above html code
   }
   ?>

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:35:30+00:00Added an answer on May 31, 2026 at 8:35 am

    Put your function in a file called function.php like this:

    <?php
        function left_side()
        {
             echo <div class="left_side">        
             echo   <ul>
    
             echo        <li><a href="page1.php">First Page</a></li>
             echo        <li><a href="page2.php">Second Page</a></li>
             echo        <li><a href="page3.php">Third Page</a></li>
             echo    </ul>
             echo </div>
        }
    ?>
    

    Then on each page, do this at the top somewhere:

    <?php require_once('/path/to/function.php'); ?>
    

    You can then use it with

     <?php left_side() ?>
    

    Generally, require() is better than include() because you will want it to throw an error if the file is missing (it will break your site not to have the HTML output). Also, require_once() is better than require() because the function only needs to be read one time by the webserver. If you start to include other files e.g. a standard header and footer in your page, which also call function.php, then require_once() will not run on those subsequent pages, leading to a slight performance gain.

    Having said that, if you are just outputting HTML, you don’t necessarily need a function wrapper at all. Just use echo statements in function.php (you can also just use HTML without echo) and use include() to have the stuff outputted every time you call it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know how to create a php function that can be
I would like to create a function that will return list of type that
I would like to create a function that checks if a numeric value passed
I would like to create an auto increment function that allows me to maintain
I would like to create some sort of function where you pass in a
I'm trying to use the header() function to create a redirect. I would like
Does such function exist? I created my own but would like to use an
I would like to create a custom check box that functions just like a
Iam quite new to functions in SQL and I would like to create a
I have question concerning a function I created. I would like to show the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.