WordPress.org

Ready to get started?Download WordPress

Forums

Impossible to add my functions (12 posts)

  1. csseur3
    Member
    Posted 4 years ago #

    Hello,

    i try to put
    <?php if ( is_page('277')) { include(TEMPLATEPATH . '/php/fichier.php'); } ?>

    but nothing is show (and no errors).

    why?

  2. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    Where exactly on your server is fichier.php? If it's not in wp-content/themes/current_theme_name/php, it won't be included.

    Perhaps you meant to use include(ABSPATH. '/php/fichier.php');?

  3. csseur3
    Member
    Posted 4 years ago #

    yes, my file is in wp-content/themes/current_theme_name/php :)

  4. csseur3
    Member
    Posted 4 years ago #

    So,
    - when i put the functions in functions.php: it's works
    - when i put the functions in fichier.php and include it (with conditional tag or not): doesn't work

    i have a problem in my php config?

    bye

  5. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    More likely in your standalone file. Perhaps you're relying on post variables?

  6. csseur3
    Member
    Posted 4 years ago #

    Re,

    this is my content of fichier.php:

    <?php
    
    // NOMBRE GULLS REGIONS
    $nombre_gulls_alsace = get_posts(array(
            'category__in' => array(60,61),
            'showposts' => -1,
    ));
    $nombre_gulls_aquitaine = get_posts(array(
            'category__in' => array(21,29,36,42,57),
            'showposts' => -1,
    ));
    $nombre_gulls_auvergne = get_posts(array(
            'category__in' => array(107,108,39,56),
            'showposts' => -1,
    ));
    $nombre_gulls_bourgogne = get_posts(array(
            'category__in' => array(18,111,64,82),
            'showposts' => -1,
    ));
    $nombre_gulls_bretagne = get_posts(array(
            'category__in' => array(19,25,31,50),
            'showposts' => -1,
    ));
    $nombre_gulls_centre = get_posts(array(
            'category__in' => array(17,114,32,33,37,40),
            'showposts' => -1,
    ));
    $nombre_gulls_champagne = get_posts(array(
            'category__in' => array(10,99,47,100),
            'showposts' => -1,
    ));
    $nombre_gulls_corse = get_posts(array(
            'category__in' => array(115),
            'showposts' => -1,
    ));
    $nombre_gulls_franche = get_posts(array(
            'category__in' => array(22,35,63,83),
            'showposts' => -1,
    ));
    $nombre_gulls_idf = get_posts(array(
            'category__in' => array(68,70,71,84,85,86,87,88),
            'showposts' => -1,
    ));
    $nombre_gulls_languedoc = get_posts(array(
            'category__in' => array(11,26,30,43,59),
            'showposts' => -1,
    ));
    $nombre_gulls_limousin = get_posts(array(
            'category__in' => array(121,20,80),
            'showposts' => -1,
    ));
    $nombre_gulls_lorraine = get_posts(array(
            'category__in' => array(49,102,51,81),
            'showposts' => -1,
    ));
    $nombre_gulls_midi = get_posts(array(
            'category__in' => array(124,12,27,28,41,58,74,75),
            'showposts' => -1,
    ));
    $nombre_gulls_npc = get_posts(array(
            'category__in' => array(52,55),
            'showposts' => -1,
    ));
    $nombre_gulls_bnormandie = get_posts(array(
            'category__in' => array(14,45,54),
            'showposts' => -1,
    ));
    $nombre_gulls_hnormandie = get_posts(array(
            'category__in' => array(24,69),
            'showposts' => -1,
    ));
    $nombre_gulls_loire = get_posts(array(
            'category__in' => array(46,44,48,65,78),
            'showposts' => -1,
    ));
    $nombre_gulls_picardie = get_posts(array(
            'category__in' => array(4,53,73),
            'showposts' => -1,
    ));
    $nombre_gulls_poitou = get_posts(array(
            'category__in' => array(15,16,72,79),
            'showposts' => -1,
    ));
    $nombre_gulls_paca = get_posts(array(
            'category__in' => array(129,6,7,13,76,77),
            'showposts' => -1,
    ));
    $nombre_gulls_rhalpes = get_posts(array(
            'category__in' => array(130,8,23,34,38,62,66,67),
            'showposts' => -1,
    ));
    
    ?>
  7. Mark / t31os
    Moderator
    Posted 4 years ago #

    Confirm the path...
    echo TEMPLATEPATH.'/php/fichier.php';

    You should see the path printed to the screen, if it's correct then the inclusion is working, that's why you don't get an error...

    You could also test by doing something like adding this into fichier.php..
    $blah = 'some random text';

    Then where you have your include, after the include place the following..
    echo $blah;

    If you see the message, the include works...

  8. csseur3
    Member
    Posted 4 years ago #

    echo TEMPLATEPATH.'/php/fichier.php'; : works
    $blah = 'some random text'; don't work :/

  9. Mark / t31os
    Moderator
    Posted 4 years ago #

    So the random text was placed in the include, then you echo'ed it out in the other file after the include line and it didn't work...

    Then that suggests the include path is wrong.. though you said "works"... though i'm not sure if you're implying the path just "looks right" or whether you confirmed it is by other means..

    I'm going to sidetrack for a moment and just point out something i noticed in your include...

    'showposts' => -1,

    Last item in an array should not have a comma..

    'showposts' => -1

    If your include was working it likely would have given an error about this...

    Try..
    include(bloginfo('template_directory').'/php/fichier.php')

    In any case, if an include does fail (because it can't find the file) PHP should produce an error, if one isn't shown the include likely did succeed..

    I'm confused as to why you have this problem, i've used includes in template files without a problem.

  10. csseur3
    Member
    Posted 4 years ago #

    I'm confused too because when i put the entire directory (/home/toto/wp-content/themes/default/php/fichier.php), there is no errors and don't works :/

    I test includes in a other part of my website (no wordpress) and it's works.

    I test with require for my wordpress includes: don't works (with no error).

    My functions are good because they work good when they are in functions.php

  11. csseur3
    Member
    Posted 4 years ago #

    I just try to put my functions in functions.php with conditional tag and don't works :/

    It is impossible to use conditional tags in functions.php ?

    bye

  12. Mark / t31os
    Moderator
    Posted 4 years ago #

    I'm using..
    <?php include( TEMPLATEPATH . '/tabs.php'); ?>

    in my sidebar.php file, without any problem...

    What kind of conditional tags do you want to use, my editor is always open so it'll only take me 2 seconds to type in a line of code then hit refresh on the browser tab.. give me something to try and i'll try it... :)

    I've just done a basic test for you though, placed this in my functions file..

    function test() {
    	if(is_home()) echo 'this is the home page';
    	if(is_category()) echo 'this is a category page';
    }

    Then in the header file..

    <?php test(); ?>

    Result was the home page showed the home message, and a category page showed the cat message...

    Any custom htaccess rules? Could be something there, htaccess rules can re-write paths in some cases...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.