WordPress.org

Ready to get started?Download WordPress

Forums

PHP include is not working in page (19 posts)

  1. shaijuelayidath
    Member
    Posted 1 year ago #

    I have created a JQuery Slider page (slider.php) it is having a library and a javascript function. When I am include it in the header.php of wordpress it is working well. But when I include it in the wordpress page through dashboard it is not working. But I can successfully include other external php files here. What is the problem...?

  2. wpsecuritylock
    Member
    Posted 1 year ago #

    You cannot write to "include" in a page or post. You would want to create a shortcode or use a plugin to do that.

  3. shaijuelayidath
    Member
    Posted 1 year ago #

    I was tring this after installed a plug in (PHP-Execution). By this plugin I included an external file with a form, it is fantastically worked. But this is only not working

    My file name is slider.php, I used the following code to insert my slider file.

    <?php include ("wp-content/themes/twentyeleven/slider.php");?>

    The same above code is working with the header and footer. This is not working when I am puting it in the page through dashboard, that is the problem...

  4. wpsecuritylock
    Member
    Posted 1 year ago #

    This is a guess, but try putting the full path to the file

    <?php include ("http://yourdomain.com/wp-content/themes/twentyeleven/slider.php");?>

  5. This is a guess, but try putting the full path to the file

    <?php include ("http://yourdomain.com/wp-content/themes/twentyeleven/slider.php");?>

    You can not use urls as php includes unless that is turned on your php.ini which by the way is VERY INSECURE!

    If you need to include a php file use get_template_part(). . Or create a shortcode.

    Trying to use a plugin that allows php execution probably not a good idea unless you have a very good understanding of the programming language.

  6. shaijuelayidath
    Member
    Posted 1 year ago #

    thanks for suggestion...
    i heard lot about shortcode but i did'nt understand it, because i am very new to javascript and php. Which is the method of 'shortcode' i have to put instead of the php include

    My include code again below:
    <?php include ("wp-content/themes/twentyeleven/slider.php");?>

  7. wpsecuritylock
    Member
    Posted 1 year ago #

    I agree with Chris!

    I don't use any plugins that embed php code in post, pages or widgets.

    Probably the easiest is to use short codes.

  8. shaijuelayidath
    Member
    Posted 1 year ago #

    i started to read about shortcode and feel it is much developer oriented one. Is the shortcode is vary as per the purpose, or is it has a general code for implementation...whatever i'll refer about it. But now can you help me to write a shortcode for include an external file in a wordpress page through dashboard.

  9. This should work depending on the code in slider.php.

    add_shortcode( 'myslider', 'slider_sc_handler' );
    function slider_sc_handler() {
    		ob_start ();
    		include_once( get_stylesheet_directory() .'/slider.php' );
    		$content = ob_get_clean();
    		return $content;
    }

    Now just add [myslider] to the content.

  10. shaijuelayidath
    Member
    Posted 1 year ago #

    When I use this shortcode should I uninstall the plugins

  11. Why would you? Just add that shortcode function to your themes functions.php file.

  12. shaijuelayidath
    Member
    Posted 1 year ago #

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

    The code i used in 'slider.php' is given below :

    ------------------------- slider.php -----------------------------

    <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/wp-content/themes/twentyeleven/js/jquery-1.2.6.min.js"></script>
    <script type="text/javascript">
    /***
        Simple jQuery Slideshow Script
        Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
    ***/
    function slideSwitch() {
        var $active = $('#slideshow IMG.active');
        if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
        // use this to pull the images in the order they appear in the markup
        var $next =  $active.next().length ? $active.next()
            : $('#slideshow IMG:first');
        // uncomment the 3 lines below to pull the images in random order
        // var $sibs  = $active.siblings();
        // var rndNum = Math.floor(Math.random() * $sibs.length );
        // var $next  = $( $sibs[ rndNum ] );
        $active.addClass('last-active');
        $next.css({opacity: 0.0})
            .addClass('active')
            .animate({opacity: 1.0}, 1000, function() {
                $active.removeClass('active last-active');
            });
    }
    $(function() {
        setInterval( "slideSwitch()", 2000 );
    });
    </script>
    
    <div id="slidersection">
    <div id="slideshow">
        <img src="wp-content/themes/twentyeleven/images/transition1.jpg" alt="Slideshow Image 3" style="opacity: 1; " class="">
        <img src="wp-content/themes/twentyeleven/images/transition2.jpg" alt="Slideshow Image 3" style="opacity: 1; " class="">
        <img src="wp-content/themes/twentyeleven/images/transition3.jpg" alt="Slideshow Image 3" style="opacity: 1; " class="">
        <img src="wp-content/themes/twentyeleven/images/transition4.jpg" alt="Slideshow Image 4" style="opacity: 1; " class="">
        <img src="wp-content/themes/twentyeleven/images/transition5.jpg" alt="Slideshow Image 5" style="opacity: 1; " class="active">
    
    </div></div>

    -------------------------------------------------------------------

    Now i put the code you given at last of the 'functions.php'
    -------------------------------------------------------------

    add_shortcode( 'myslider', 'slider_sc_handler' );
    function slider_sc_handler() {
    		ob_start ();
    		include_once( get_stylesheet_directory() .'/slider.php' );
    		$content = ob_get_clean();
    		return $content;
    }

    --------------------------------------------------------------
    then i added [myslider] in my page..but shows the text as it is..
    is it required to set my path before the file name..or is any specific place to add the shortcode in functions.php

  13. shaijuelayidath, you really need to learn to use the code button...

    http://codex.wordpress.org/Forum_Welcome#Posting_Code

  14. shaijuelayidath
    Member
    Posted 1 year ago #

    thank you for suggestion

  15. shaijuelayidath
    Member
    Posted 1 year ago #

    Hi Chris Olbekson,

    Thank youuu very very much...it works....the code you given me rocked...it is fineeee....
    It was my experiment to convince the possibilites of 'wordpress'
    to one of my friend for a small project.
    You really helped and inspired me instantly even if
    my question is below average.
    I visited you excellent site also.
    You perfectly done the job of a consultant and a
    real worthfull person here.
    For my future doubts can i ask to you,
    only as per your convenience...

  16. Prabhak
    Member
    Posted 1 year ago #

    Hello Everyone, :)

    The reason I'm posting in this thread is because I noticed some really helpful people solve Shai's problem.

    The strangest thing; I migrated my wordpress from an old domain finger monkey wire and then uploaded it to my new domain http://www.athenatechs.com

    Now when I visit the site the browser tab displays says Finger Monkey Wire while the url is athenatechs.com

    I've used search and replace in the migrated database to replace the finger monkey wire url with athenatechs and have been through all the theme files including header and index.php

    This is a huge mystery to me anyone faced this phenomenon before?

  17. shaijuelayidath
    Member
    Posted 1 year ago #

    You can change your site titles in 'Settings' menu of the Dashboard.

    1. Go to 'Settings'
    2. In 'Settings' -->Generall Settings
    3. In 'General Settings :
    You can change your title of the Website in 'Site Title' tab and Additional Tag line in 'Tagline' tab

  18. Prabhak
    Member
    Posted 1 year ago #

    Hi Shai's,

    You bet I did that in general settings and even went into the database and checked the wordpress options in the entries for home website url etc they all say athenatechs.com

    Weird huh? Could it be that I've found a bug in wordpress that in unfixable? :)

  19. fonglh
    Member
    Posted 1 year ago #

    It's probably not a WordPress bug, it's more likely a poorly written theme with a hardcoded title. Try looking in header.php of your theme.

    Also, you should start your own topic.

Topic Closed

This topic has been closed to new replies.

About this Topic