Announcement

Collapse
No announcement yet.

Stopping 'php include' adding acatalog...

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

    Stopping 'php include' adding acatalog...

    I want to include some latest Wordpress Blog Posts on the home page of a site. I do not want the home page to be .php

    Therefore I have created a simple php page in the blog folder (wpress) called 'hereiam.php' containing the following code:

    Code:
    <meta charset="utf-8">
    <?php require('wp-blog-header.php');
    
     /*if you are getting 404 errors uncomment the next 2 lines*/
        //status_header(200);
        //nocache_headers();
     
    ?>
    <?php
    $posts = get_posts('numberposts=20&order=DESC&orderby=post_date');
    foreach ($posts as $post) : setup_postdata( $post ); ?>
    <h5 class="blogh5"><?php the_time('l, F j, Y'); ?></h5>
    <a href="<?php the_permalink(); ?>"><h4><?php the_title(); ?></h4></a>  
            <p class="product-image"><?php the_post_thumbnail( $size, $attr ); ?></p>
            <?php the_excerpt(); ?>
            <p></p>
            <a href="<?php the_permalink(); ?>"><p>Read More...</p></a>
    <?php
    endforeach;
    ?>
    And it works nicely displaying the recent posts and their featured images.

    However if I put this in the home page:

    Code:
    	<actinic:block php="true">
    		include '/wpress/hereiam.php';
    	</actinic:block>
    Sellerdeck adds 'acatalog' and I get this:
    Code:
    Warning: include(/wpress/hereiam.php): failed to open stream: No such file or directory in main on line 2 Warning: include(): Failed opening 'acatalog//wpress/hereiam.php' for inclusion (include_path='.;C:\php\pear') in main on line 2
    I know how to get round this with js using apostrophes and + but I don't know how to do the same sort of thing with php.

    Please can anyone help?

    Thank you

    Jonathan
    Jonathan Chappell
    Website Designer
    SellerDeck Website Designer
    Actinic to SellerDeck upgrades
    Graphicz Limited - www.graphicz.co.uk

    #2
    I know how to get round this with js using apostrophes and +
    Do the same thing but note that PHP uses a period "." as the concatenation operator instead of JavaScript's "+".
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      Code:
      	<actinic:block php="true">
      		include 'wpress'.'/'.'hereiam'.'.'.'php';
      	</actinic:block>
      generates
      Code:
       Warning: include(wpress/hereiam.php): failed to open stream: No such file or directory in main on line 2 Warning: include(): Failed opening 'acatalog/wpress/hereiam.php' for inclusion (include_path='.;C:\php\pear') in main on line 2
      plain php file in the site root with only the following
      Code:
      <?php
      include 'wpress'.'/'.'hereiam'.'.'.'php';
      ?>
      includes the file correctky
      Jonathan Chappell
      Website Designer
      SellerDeck Website Designer
      Actinic to SellerDeck upgrades
      Graphicz Limited - www.graphicz.co.uk

      Comment


        #4
        I do not want the home page to be .php
        It looks like you don't want the home page to be .php and you don't want the include processed by SD's built in PHP. But it looks like you do want PHP to run from your server when the page is presented to your customers.

        Use an IFRAME on the home page and set the src to the full http://pathtomyphpfile.php.

        SD won't munge anything if is starts with http: / https:
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment


          #5
          OK. This works. Add after INNERLAYOUT.
          Code:
          <actinic:block php="true">
          $url = "http://www.graphicz.solutions/wpsd/wpress/hereiam.php";
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          $data = curl_exec($ch);
          curl_close($ch);
          echo $data;
          </actinic:block>
          I have modified the code for the file in the word[press folder so that it styles the posts as three across fragments:
          Code:
          <meta charset="utf-8">
          <style>.blogh5 {font-size:16px;}</style>	
          <?php require('wp-blog-header.php');
          
           /*if you are getting 404 errors uncomment the next 2 lines*/
              //status_header(200);
              //nocache_headers();
           
          ?>
          <?php $myindex = 0; ?>
          <div class="fragment-list threeColumns">
          <?php
          $posts = get_posts('numberposts=6&order=DESC&orderby=post_date');
          foreach ($posts as $post) : setup_postdata( $post ); ?>
          <div class="fullWidthSection">
          <h5 class="blogh5"><?php the_time('l, F j, Y'); ?></h5>
          <a href="<?php the_permalink(); ?>"><h4><?php the_title(); ?></h4></a>  
                  <p class="product-image set-left"><?php the_post_thumbnail( $size, $attr ); ?></p>
                  <?php the_excerpt(); ?>
                  <p></p>
                  <a href="<?php the_permalink(); ?>"><p>Read More...</p></a>
          </div>
          <?php
          if (++$myindex >= 3)
          {
          $myindex = 0;
          echo '</div><div class="fragment-list threeColumns">';
          }
          ?>
          <?php
          endforeach;
          ?>
          </div>
          Note:
          If the Wordpress posts change, the Sellerdeck home page needs re-uploading to load the changes.

          URL: http://www.graphicz.solutions/wpsd/

          Reference and acknowledgement: https://stackoverflow.com/questions/...ts-not-working
          Last edited by graphicz; 14-Mar-2018, 04:46 PM. Reason: Does not have to exclude preview mode
          Jonathan Chappell
          Website Designer
          SellerDeck Website Designer
          Actinic to SellerDeck upgrades
          Graphicz Limited - www.graphicz.co.uk

          Comment


            #6
            When using https://

            When using https:// Curl needs to be told directly where the certificate is otherwise the remote file will not load.

            Go to https://curl.haxx.se/docs/caextract.html and save the latest cacert.pem to your PC.

            You then have to tell Curl the path to the file, thus:

            Code:
            <actinic:block php="true">
            $url = "https://www.graphicz.solutions/wpsd/wpress/hereiam.php";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_CAINFO, 'C:\ProgramData\SellerDeck\SellerDeck 2016\Sites\wpsd\SiteHTML\cacert.pem');
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $data = curl_exec($ch);
            curl_close($ch);
            echo $data;
            </actinic:block>
            (NB: graphicz.solutions does not have an SSL so the above is for illustrative purposes)

            I was also wrong about preview mode, the blog extracts load offline, I have corrected the post above.
            Jonathan Chappell
            Website Designer
            SellerDeck Website Designer
            Actinic to SellerDeck upgrades
            Graphicz Limited - www.graphicz.co.uk

            Comment


              #7
              Dealing with Wordpress's utf8 encoding

              With the code I have written above any utf8 characters will appear weirdly in Sellerdeck's iso-8859-1 encoding, eg:
              Code:
               I’ve instead of I've
              Add this line before echo $data;
              Code:
              $data = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $data);
              So the whole expression looks like this:

              Code:
              <actinic:block php="true">
              $url = "https://www.graphicz.solutions/wpsd/wpress/hereiam.php";
              $ch = curl_init();
              curl_setopt($ch, CURLOPT_CAINFO, 'C:\ProgramData\SellerDeck\SellerDeck 2016\Sites\wpsd\SiteHTML\cacert.pem');
              curl_setopt($ch, CURLOPT_URL, $url);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
              $data = curl_exec($ch);
              curl_close($ch);
              $data = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $data);
              echo $data;
              </actinic:block>
              Jonathan Chappell
              Website Designer
              SellerDeck Website Designer
              Actinic to SellerDeck upgrades
              Graphicz Limited - www.graphicz.co.uk

              Comment


                #8
                PHP has a function utf8_decode that does this.
                Norman - www.drillpine.biz
                Edinburgh, U K / Bitez, Turkey

                Comment


                  #9
                  Another way:

                  Code:
                  <actinic:block php="true">
                  $url = "https://www.graphicz.solutions/wpsd/wpress/hereiam.php";
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_CAINFO, 'C:\ProgramData\SellerDeck\SellerDeck 2016\Sites\wpsd\SiteHTML\cacert.pem');
                  curl_setopt($ch, CURLOPT_URL, $url);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                  $data = curl_exec($ch);
                  curl_close($ch);
                  $find = array('“', '’', '…', '—', '–', '‘', 'é', 'Â', '•', 'Ëœ', 'â€'); // en dash
                  $replace = array('“', '’', '…', '—', '–', '‘', 'é', '', '•', '˜', '”');
                  $data = str_replace($find, $replace, $data);
                  echo $data;
                  </actinic:block>
                  Jonathan Chappell
                  Website Designer
                  SellerDeck Website Designer
                  Actinic to SellerDeck upgrades
                  Graphicz Limited - www.graphicz.co.uk

                  Comment

                  Working...
                  X