Announcement

Collapse
No announcement yet.

Adding Content (include) to Topic Page

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding Content (include) to Topic Page

    I need to add some content to each Topic page on my forum board using <?php include 'random-content.php';?>
    Searching through it would appear that display_Topics would be where I would want it to go (I think) I thought I would try using a Hook but I'm not able to select that template. Can you advise me the best way to include the random-content.php on the Topic page (just once per topic)
    Thanks.


  • #2
    I don't think it's possible to add to the display_Topics template after reading other comments.

    Does anyone know whether it's possible to include a php file within the default template. I would assume using a Hook. But should the code be in HTML or PHP?
    i.e would it be <?php include 'random-content.php';?>

    Thanks.

    Comment


    • #3
      You would probably want to use a PHP module on the topic page. Use output buffering, assign your content to a variable and then print that to the screen.
      Translations provided by Google.

      Wayne Luke
      The Rabid Badger - a vBulletin Cloud customization and demonstration site.
      vBulletin 5 Documentation - Updated every Friday. Report issues here.
      vBulletin 5 API - Full / Mobile
      I am not currently available for vB Messenger Chats.

      Comment


      • #4
        Hi Wayne, I wouldn't really know where to start with PHP module and output buffering (what ever that is) But thanks for the suggestion. Is there no way to include a php file onto my template using a Hook? Thanks.

        Comment


        • #5
          Hi Wayne,
          I've found the PHP module and can add that to the page using edit. How can I find out how to use it?
          Do I just add the PHP code in there and vBulletin will run it i.e.
          <?php include 'random.php';?>
          or
          <!--#config timefmt="%A" --> <!--#echo var="DATE_LOCAL" -->
          Thanks,
          Robin

          Comment


          • #6
            Should just have to add your PHP statements without opening and closing tags.

            For including a file, you may want to use output buffering and flush it all at once at the end of the module.
            Translations provided by Google.

            Wayne Luke
            The Rabid Badger - a vBulletin Cloud customization and demonstration site.
            vBulletin 5 Documentation - Updated every Friday. Report issues here.
            vBulletin 5 API - Full / Mobile
            I am not currently available for vB Messenger Chats.

            Comment


            • #7
              Hi Wayne,

              I've tried just adding the follows:-
              php include 'random.php';
              and it didn't work

              I than tried putting the code from random.php in:-

              ############################################################################
              # Configuration
              ############################################################################
              $FileName = "web-pages.html";
              ############################################################################

              if ( file_exists($FileName) ) {

              // Get content as an array
              $contents = explode(":::",file_get_contents($FileName));

              // Remove last blank entry
              unset($contents[count($contents) - 1]);

              // Randomize the content
              shuffle($contents);

              // Output First Entry
              echo $contents[0];
              }


              and that didn't work for me either.

              Is it far more involved than that?
              Regards,
              Robin

              Comment


              • #8
                try return $contents[0]; instead of echo. (I couldn't get this to work either.)
                However, I ran a test scenario on my test server and got it to work using a static html module and one line of jquery in a template.

                This is the setup I used that worked.
                Both random.php and random.html are in the forum directory
                The php file
                PHP Code:
                <?php
                $FileName 
                "random.html";
                if ( 
                file_exists($FileName) ) {
                $contents explode(":::",file_get_contents($FileName));
                unset(
                $contents[count($contents) - 1]);
                shuffle($contents);
                return 
                $contents[0];
                }
                ?>
                Static HTML module
                Code:
                <div id=random-post></div>
                New template
                Code:
                <script>
                $('#random-post').load('/forum/random.php');
                </script>
                Last edited by Replicant; Sun 13th Sep '15, 11:39am.


                Comment


                • #9
                  Hi,
                  No joy I'm afraid;

                  ############################################################################
                  # Configuration
                  ############################################################################
                  $FileName = "web-pages.html";
                  ############################################################################

                  if ( file_exists($FileName) ) {

                  // Get content as an array
                  $contents = explode(":::",file_get_contents($FileName));

                  // Remove last blank entry
                  unset($contents[count($contents) - 1]);

                  // Randomize the content
                  shuffle($contents);

                  // Output First Entry
                  return $contents[0];
                  }
                  Thanks,
                  Robin

                  Comment


                  • #10
                    Hi,
                    I put this code into file random.php and put that in the forum directory http://www.leisurebuildings.com/help/ :-
                    <?php
                    $FileName
                    = "random.html";
                    if (
                    file_exists($FileName) ) {
                    $contents = explode(":::",file_get_contents($FileName));
                    unset(
                    $contents[count($contents) - 1]);
                    shuffle($contents);
                    return
                    $contents[0];
                    }

                    ?>


                    I added a Static HTML module onto my layout and added code as follows:-

                    <div id=random-post></div>

                    <script>
                    $('#random-post').load('/forum/random.php');
                    </script>

                    I've also put the file with the random text (called random.html) in the same forum directory.

                    Which doesn't work. Does the script have to go in a separate template some where?

                    Thanks.
                    Robin



                    Comment


                    • #11
                      The script needs to be loaded after Jquery. I typically use the hook footer_before_body_end. Create a new template, add the script and associate with the hook in Admincp > manage hooks. I didn't ask if you are on the vb cloud or not. If you are on the cloud, this won't work for you.


                      Comment


                      • #12
                        Hi,
                        Thanks for that. I will give that a go tomorrow. I have my own server so, hopefully, won't be a problem. Thanks for your help.
                        Regards,
                        Robin

                        Comment


                        • #13
                          Hi,

                          I have the Static HTML Module with <div id=random-post></div>

                          I created a template call RandomAdd and entered the script as follows:-

                          <script>
                          $('#random-post').load('/help/random.php'); the directory 'help' is where my forum board is http://www.leisurebuildings.com/help/
                          </script>

                          I went to Manage Hooks and linked the template RandomAdd to the Hook footer_before_body

                          I opened the page and looked at the source and the script is on the page.

                          I don't get any output in the Static HTML Module

                          It appears that the script can't find my random text file called random.html

                          This is the link to where my random text is http://www.leisurebuildings.com/help/random.html
                          the script random.php is in this directory http://www.leisurebuildings.com/help/random.php

                          Just in case my modified style was the problem I have tried the same using a default style with no parent settings to ensure vBulletin is just as it should be.

                          Do you have any idea what I am doing wrong? I do appreciate your help with this and hopefully it's just something simple. Thanks.

                          Regards,
                          Robin
                          Last edited by robinantill; Mon 14th Sep '15, 1:55am.

                          Comment


                          • #14
                            You'll need to add a couple var_dump lines in your PHP to see where it's getting lost. Could just be a typo, missing semi-colon or path issue. You may also try a full file path to your random.html file.


                            Comment


                            • #15
                              Hi,
                              Thanks again. I understand if you can't help any further.

                              I've double checked all of the code and is exactly the same as your example (except the directory is /help/ and not /forum)

                              I don't know how to add a couple of var_dump lines in the PHP or to what values

                              I did try the full path to the random.html file as follows:- /home/wwwleisu/public_html/help/random.html

                              PHP code is now:-

                              <?php
                              $FileName
                              = "
                              /home/wwwleisu/public_html/help/random.html";
                              if (
                              file_exists($FileName) ) {
                              $contents = explode(":::",file_get_contents($FileName));
                              unset(
                              $contents[count($contents) - 1]);
                              shuffle($contents);
                              return
                              $contents[0];
                              }

                              ?>


                              This produces aParse error: syntax error, unexpected '$FileName' (T_VARIABLE) in /home/wwwleisu/public_html/help/random.php on line 1

                              Regards,
                              Robin

                              Comment

                              widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                              Working...
                              X