Support » Plugins » Hacks » Adding Content to Blank Pages Automatically

  • Hey all. I have been using WordPress for a couple months now and am almost finished with my first project. I wrote a couple php pages to use in my custom theme as plugins and they work great. However, I have a small need that I feel should be easy to do. Basically, I have my TOC and child pages. In between them are category pages, which are not used and are blank. I would like to put a children list on each of these blank pages, for which I have already written the php. However, the ultimate goal is that anyone can edit or add posts without knowing any code at all. To accomplish this, I was wondering if anyone knows how to automatically include my php code if the content is blank. I can certainly just include my php code on each of these pages, but again, that is not ideal. I know there are plugins such as some toc plugins that allow substitution for a comment or something within the post content so I feel this should be possible, I just cannot find any plugins or documentation on accomplishing this. Thank you in advance for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter brianduffey

    (@brianduffey)

    Never mind, I figured it out. In case someone else finds this post in the future, here is the code I used to create my plugin:

    <?php // hook required to populate blank page
    add_filter('the_content', 'mrc_category'); // check each page for content
    
    // Executes before each page is displayed.
    function mrc_category( $content ) {
    
    	// check if the page is blank
    	if (get_the_content() == '') {
    	$content="<!-- Begin Content -->\n\n" . eval(require 'C:\website\docs\wp-content\plugins\mrc-toc\subpages.php') . "\n\n<!-- End Content -->";
    }
    
    	return $content;
    } ?>

    Where subpages.php is my php code I wrote to list the children. Hope this helps someone!

    good. thx
    i will try it out for something similar i had in mind

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding Content to Blank Pages Automatically’ is closed to new replies.