www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23

Thread: Don't laugh! But this may be a stupid wordpress/php question...

  1. #16
    Join Date
    Feb 2010
    Posts
    86
    Ok, I cringe saying this but...

    Here is what I got for the first option which is not working. It actually seemed like it worked the first time and then stopped:

    PHP Code:
    <? ob_start(); ?>
    This is my test page content.
    <?   
        $page_content 
    ob_get_flush();   
        
    $ipb_txt_file "/myabosolutefilepath.com/footer-export-ipb.txt"
       
    if (!
    is_file($ipb_txt_file)) {     
    file_put_contents(/myabosolutefilepath.com/footer-export-ipb.txt", $page_content);  
    ?>


    For the 2nd option

    PHP Code:
    <? ob_start(); ?>
    This is my test page content.
    <?   
        $page_content 
    ob_get_flush();   
        
    $ipb_txt_file "/myabosolutefilepath.com/footer-export-ipb.txt"
       
    if (isset(
    $_GET['renew_ipb'])) {     
    file_put_contents(/myabosolutefilepath.com/footer-export-ipb.txt", $page_content);  
    ?>
    Then after changing the file I typed the url in my browser http://mysite.com/?renew_ipb which did nothing

    I'm sure I look like a real idiot here but I would appreciate any further help in what I'm doing wrong. Thank you so much!
    Last edited by blue_vision; 07-17-2013 at 09:51 PM.

  2. #17
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,387
    Your file_put_contents() calls are missing an opening quote around the file path-name. (No guarantee that's the only problem, though. )

    PS: I highly recommend that you use <?php opening tags, not <?, in order to keep your code portable (some web hosts may have short_open_tags disabled).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #18
    Join Date
    Feb 2010
    Posts
    86
    Quote Originally Posted by NogDog View Post
    Your file_put_contents() calls are missing an opening quote around the file path-name. (No guarantee that's the only problem, though. )

    PS: I highly recommend that you use <?php opening tags, not <?, in order to keep your code portable (some web hosts may have short_open_tags disabled).
    I updated the opening tags as suggested.

    The opening quote on the path name was just a typo here I think. But playing around I got this to work for the is_file option:

    PHP Code:
    <?php ob_start(); ?>

    or that other thing!

    <?php  
        $page_content 
    ob_get_flush();  
        
    $ipb_txt_file '/home/username/public_html/mydomain.com/wp-content/themes/my-theme/export-ipb.txt'
        if (!
    is_file($ipb_txt_file)) { 
    file_put_contents($ipb_txt_file$page_content); 
    }
    ?>
    But it seems to take 10-15 seconds or so after the file was deleted to regenerate. It just shows errors that the file is missing in the meantime which kinda sucks but is not a deal breaker I suppose since we won't update the file daily or anything.

    I still can't get the version to work which was stated as optimal. I tried this:

    PHP Code:
    <?php ob_start(); ?>

    now what?

    <?php  
        $page_content 
    ob_get_flush();  
        
    $ipb_txt_file '/home/username/public_html/mydomain.com/wp-content/themes/my-theme/export-ipb.txt'
        if (isset(
    $_GET['renew_ipb'])){ 
    file_put_contents($ipb_txt_file$page_content); 
    }
    ?>
    using the url: http://mydomain.com/?renew_ipb

    I'm honestly not to sure if my php coding is wrong or our htaccess rewrites are messing it up. I don't know anything about those but here is what we have in the file:

    Code:
    RewriteEngine off
    <IfModule mod_suphp.c>
    	suPHP_ConfigPath /home/username/public_html/mydomain.com/php.ini
    	<Files php.ini>
    		order allow,deny
    		deny from all
    	</Files>
    </IfModule>
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    Which I didn't do, my developer did for whatever reason so I'd be afraid to have to change that. If it is messing it up maybe there is a way to do a non-index url that isn't being messed with in the htaccess?

    This is our index.php file as well incase it's causing any issue? Not sure if it needs something in it to know about the _GET or isset or whatever.

    Code:
    <?php
    /**
     * Front to the WordPress application. This file doesn't do anything, but loads
     * wp-blog-header.php which does and tells WordPress to load the theme.
     *
     * @package WordPress
     */
    
    /**
     * Tells WordPress to load the WordPress theme and output it.
     *
     * @var bool
     */
    define('WP_USE_THEMES', true);
    
    /** Loads the WordPress Environment and Template */
    require('./wp-blog-header.php');
    As far as the note on "calls" missing. I'm not quite sure what that is. I am no php person, just trying to get this thing to work.

    Thanks for any additional help guys

  4. #19
    Join Date
    Feb 2010
    Posts
    86
    **bump**

    Would really appreciate the help. Thank you so much!

  5. #20
    Join Date
    Jul 2013
    Posts
    29
    In your WP .htaccess in the line
    Code:
    RewriteRule . /index.php [L]
    change [L] to [L,QSA] which means QueryStringAppend and should tell apache to pass get parameters to the script as well.

    In case of checking deleted file, it would be regenerated on request to wordpress, not to ipb, keep this in mind. If your ipb is requested more frequently than wp, of course you will see errors until wp is requested.

  6. #21
    Join Date
    Jul 2013
    Posts
    29
    Also you may call clearstatcache() function before is_file() so that it checked the file on filesystem itself instead of filesystem cache.

  7. #22
    Join Date
    Feb 2010
    Posts
    86
    Ok, deleting the files and refreshing the blog page instead of the forum makes the one option immediate. I was refreshing the forum page waiting for the changes to take effect.

    I couldn't figure out how to include the clearstatcache function but I doubt it's a big deal now that I know to refresh the blog.

    The url isset thing still didn't work even with the htaccess file edited as instructed. Eitherway this is pretty simple as I have it. About the only thing that could be simpler is if the file auto updated the txt file IF the original file was altered so that we didn't have to bother deleting files for them to be regenerated. But it's no biggie doing it this way. At least it's not making a million saves to the file on every refresh like the original way. Especially since we are doing it for 3-4 different areas which was resaving 3-4 different files every time.

    I left one as the original way to resave each time. Reason why is that we have that one randomly showing 4 posts. So on the live blog it shows 4 different posts on each refresh. But if we did the text-file delete option like on the rest of them then it only would show the same 4 posts unless I deleted the file on every single refresh...LOL. But by regenerating the file each time it regenerates those posts at random as instructed so it shows 4 random posts at our forum each time. I'm not sure if there is a better way of doing that without all the resaving of the file but at least this makes it so that it works.

  8. #23
    Join Date
    Feb 2010
    Posts
    86
    Actually I guess the original way still doesn't re-generate the random images until the wordpress page has been refreshed by someone. So refreshing the forum page does nothing.

    Fortunately our blog is visited a fair amount of times making things random enough but in a perfect world i guess I would handle the header card system the same as the others with the delete file regeneration. But then have the txt file contain the randomize code. It can't do that as-is because we would need to run the wordpress environment at the forum to do so but I don't know... at some point I might figure out a way to randomize those 4 posts without the need for the WP loop to do it.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles