• WPOso

    (@wordpress-oso)


    Suppose I create a custom PHP file with the following path:

    wp-content/themes/twentyfifteen-child/custom.php

    Is there a way I can include this file by default on every post?

    I asked about this earlier and was advised to use the Custom Field and Shotcode features, but I checked them out, and they’re far too confusing, and there are very few helpful examples.

    So I’d like to bypass that option and just use the same system I use on my non-WordPress sites.

    Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • What does your file contain?

    Thread Starter WPOso

    (@wordpress-oso)

    It will probably have a series of echo values and PHP switches. For example…

    $CountyIntro = 'If you live in '.$MyCounty.', we want to hear from you.'

    Then I could paste $CountryIntro into a post and use str_replace(‘$CountyIntro’, $CountyIntro, $Article)

    Or I could create a switch based on URL’s:

    switch($MyURL)
    {
     case 'adams-country':
     echo $CountyIntro;
     break;
     default:
     break;
    }

    The file could also feature includes to additional include files as needed.

    Where on the page do you want these to display?

    Thread Starter WPOso

    (@wordpress-oso)

    That will vary. On the county pages, the post content will probably consist entirely of a block of text defined in an include.

    In other cases, I may make posts that look like this…

    This is an article about a species of antelope, the impala.
    $Info
    Impala are popular symbols.

    $Info could then be replaced by something I want to display on all antelope pages.

    In other cases, there might be a block of text that I want to display at the end of every article. It’s really all over the map.

    EDIT:

    It would probably make sense to include TWO files, one before my post content and the other at the end.

    The first could be used to 1) display images or content that I want to display before my post and 2) define PHP variables that I want to echo in the body of my post. The second would then display items I want to display at the end of the post, such as links to related articles.

    Thread Starter WPOso

    (@wordpress-oso)

    Thanks.

    You’re welcome.

    If this resolves the matter, please mark the post as resolved. Look on the right hand side of the page for a dropdown list where you can select Resolved and a button where you can Update the status – look at the top portion of the page.

    Bob

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Including Custom File’ is closed to new replies.