0

I am developing a wordpress website on the thematic framework. In my child theme i have made a full width page template called resources.php

In this page template i have written custom php code which displays various custom fields related to posts of a particular category.

For Example :

<div class="download">
<ul id="portfolio" class="port">
<?php query_posts(array ( 'category_name' => 'research'   ,  'posts_per_page' => '-1' , 'order'=>'ASC')  ); ?>
<?php while (have_posts()) : the_post(); ?>
<li class="<?php foreach((get_the_category()) as $category) { echo $category->category_nicename; echo" ";} ?> resourcelist">
<span class="doctitle"><?php the_field('document_title') ;?> <span class="date"><?php the_field('document_date'); ?></span>  <span class="categry"><?php foreach((get_the_tags()) as $tag) { echo $tag->name; echo" "; } ?></span></span>
<span class="docdes"><?php the_field('document_description') ;?></span>
<span class="docpath"><a title="download" target="_blank" href="<?php the_field('document_path'); ?>">
<img border="0" src="test.png">
</a> </span>


            </li>
            <?php endwhile; ?>
    </ul>

</div>

Now what i want to do is restrict this page to only users who have registered . I have a plugin which takes care of this for eg: page restrict

What page restrict does is it replaces whatever gets called via the page's wisiwyg editor the_content() with the message "you need to login".

The page gets blocked however my php code does execute as its a part of the page template.

I am trying to find out a way to add all my php code to the_content(); so that the output also gets replaced with the message.

I came across this article which gave me the following code.

        <?php
        function demo_function( $content ) {

            $someHtml = '<div class="someClass">';
            $someHtml .= 'some text or code goes here';
            $someHtml .= '</div>';

            $filteredcontent = $someHtml . $content;

            return $filteredcontent;
        }
        add_filter( 'the_content', 'demo_function' );
//the loop goes here        
the_content();
    ?>

What this code does is that it adds the above HTML within the_content(); So, the next time i block the page, even the above content gets blocked. I exactly want that to happen but with my php code not this HTML.

I am really close to cracking this but because of the above syntax appends the html to the variable, I cant append so many lines of my php code via that method.

Please help me. If you have any questions feel free to ask.

2
  • 1
    what's your question exactly? put what you want to output within the content filter function.
    – Milo
    Commented Aug 7, 2012 at 14:42
  • i want to add my PHP code in the_content .. you are right. Commented Aug 8, 2012 at 4:27

1 Answer 1

1

i´m not sure to understand your question, but why not use this logic in your function?

if ( is_user_logged_in() ) {
    echo 'Welcome, registered user!';
    do your stuff PHP and inject in content...
} else {
    return standard content or block it;
}

and maybe additional test to limit with current_user_can( $capability ), and so on...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.