• difimon

    (@difimon)


    Dear all,

    I have a class in PHP named sample.class.php which I want to include in a wordpress page to exploit its functions. I am using the template twentytwelve and I have installed the plugin exec PHP to write php code into wp pages. I tried to do this until now with bad results:

    – I’ve created a folder called “includes” into this path wordpress/wp-content/twentytwelve and then:

    – I’ve tried to do this in a wordpress page (but doesn’t work)

    <?php require_once('includes/sample.class.php');

    and its error is the following:

    Parse error: syntax error, unexpected ‘<’ in /Applications/XAMPP/xamppfiles/htdocs/wordpress/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 11

    …and also this:

    include(get_bloginfo('twentytwelve').'/wp-content/twentytwelve/sample.class.php');

    Anything works here. Can you explain me what I have to do in order to solve this mistake?

    Thank you in advance.
    Marco

Viewing 9 replies - 1 through 9 (of 9 total)
  • esmi

    (@esmi)

    Do not edit the theme itself. First create a child theme for your changes.

    Thread Starter difimon

    (@difimon)

    I don’t want to change the theme. I have a PHP class which allows me to print some text from another website (extract info from linkedin). I don’t want to repeat all the code in the page, I just want to inlclude the class and use the functions.

    Moderator bcworkz

    (@bcworkz)

    We consider even minor file edits, or even messing with theme folder structure as changing the theme. It does not matter whether your changes are visible or not, it’s that all files are not exactly as they were published anymore.

    You need to make a child theme, it’s quite easy. Then you don’t have to worry about re-entering your changes every time WP updates.

    As far as the syntax error, it seems there is some lack of coordination between the included file’s content and where you are including it. An included file is exactly equivalent to if you had pasted the file’s content right where you put the include line (except for the file’s initial <?php)

    Once you create a child theme, including the file in your child’s functions.php should get you very close to what you need.

    Thread Starter difimon

    (@difimon)

    OK thank you so much for the reply. I will make a child theme. After that, you suggest to copy paste my php class into the functions php? Could I also take it in another file or in another folder?

    Moderator bcworkz

    (@bcworkz)

    No, sorry. I was trying to explain further and just made it more confusing. Yes, separate file please! Only the include statement goes in functions.php.

    Thread Starter difimon

    (@difimon)

    Ok. Thank you so much. Let’s asssume that I am working for my “website prototype” on localhost and after I am able to integrate that php class into wp, I will work on another website which is already online. So, isn’t a waste of time do a child theme for that site (on localhost) that I will throw away when I finish my tests? If it is, could you kindly explain just the right include syntax, where to put my php class to let it works and (if case) what plugin I need to install.

    Hope you can help me ??
    Thank another time,

    Marco

    esmi

    (@esmi)

    You would place your php class in your child theme’s functions.php file and use the child theme on the live site. If the other site is using a different theme, you need to create child for that theme too, place your php class in the new child theme’s functions.php file, upload that child theme to the other site and activate it.

    <?php include (https://enestinc/domain (‘TEMPLATEPATH’). ‘/astroupdateds.php’); ?>

    Not Working

    Moderator bcworkz

    (@bcworkz)

    @masudanwar – do not specify a HTTP protocol when using include statements. The path you specify should be a local path for your server’s file system.

    FYI, you should not tag onto other’s threads in these forums. If you have more questions, please start a new topic.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Include and use PHP class into a wordpress page’ is closed to new replies.