Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If page_content() != '' echo ... possible? (conditional by content)
#1
I'm searching again for a php code to use in a template file.
I want to check if the content is empty (no content).
Example:
Code:
<?php if (page_content() != '') { ?>
        <section class="cssborder and more">
            <?php get_page_content(); ?>
        </section>    
<?php } ?>
Have tried "get_page_content()", "return_page_content()" and "page_content()" and "getPageContent()".
Thank you for helping again...

EDIT: I think I got it: "returnPageContent(return_page_slug())" is doing the job in v3.1. Maybe it would be helpful to add all the return outputs (if they are short/simple) for the main Template Tags in the Wiki?
Advanced HTML5 & CSS3 coder. Simple JS & PHP hacker (not enough for new function coding). Build one webpage with GS (late 2012). Focusing on Theme customizing/Template files. Experience with WP.
Reply
#2
Add the below function to admin/inc/theme_functions.php or theme/yourtheme/functions.php.
It does not matter which one you add it too.
Code:
function return_page_content() {
    global $content;
    exec_action('content-top');
    $content = strip_decode($content);
    $content = exec_filter('content',$content);
    return $content;
        /* un-comment below if you replace the get_page_content() function in your template files */
    //exec_action('content-bottom');
}

Then you can use it to return the content instead of echo it.

Or

You can do the below in your template files:
Code:
<?php
    global $content;
    if($content != '')
    {
        get_page_content();
    }
?>
Reply
#3
Thank you mikeh! Until now I have no functions.php and prefer to continue with template.php only. But it is nice to have your code here in case I need to use functions.php.
Advanced HTML5 & CSS3 coder. Simple JS & PHP hacker (not enough for new function coding). Build one webpage with GS (late 2012). Focusing on Theme customizing/Template files. Experience with WP.
Reply
#4
ChriS Wrote:Thank you mikeh! Until now I have no functions.php and prefer to continue with template.php only. But it is nice to have your code here in case I need to use functions.php.

I revised my post. You do not have to use that function if you do not want to. You can stay within your template file.
Reply
#5
Thanks for the new piece of code. I have edited my first post at the same time as your first post here. I mean I'm using
Code:
<?php if (returnPageContent(return_page_slug()) != '') { ?>
        <div class="style">
        <?php get_page_content(); ?>
        </div>
<?php } ?>

Does this code have some disadvantage in comparison to yours (I need to output the styling div)?
Advanced HTML5 & CSS3 coder. Simple JS & PHP hacker (not enough for new function coding). Build one webpage with GS (late 2012). Focusing on Theme customizing/Template files. Experience with WP.
Reply




Users browsing this thread: 1 Guest(s)