WordPress.org

Ready to get started?Download WordPress

Forums

MaGiKS Proper PHP Include (8 posts)

  1. kjlock75
    Member
    Posted 3 years ago #

    Hey everyone,

    I uploaded my first free public plugin today 'woot' 'woot' <-- just kidding I don't actually say 'woot' 'woot'

    Anyway, just wanted to share it with y'all.. enjoy

    http://wordpress.org/extend/plugins/magiks-proper-php-include/

  2. patrickbryant
    Member
    Posted 3 years ago #

    Love it. It's exactly what I was looking for. Thank You for your time.

    I have a support question. The PHP code that I am running is building excerpts of past blog entries. When I use the code that I would generally include in a template it seems to create a feedback loop. Displaying the content I want, but then also displaying the full blog entry for each post not just the excerpts?

    Is there a way to "close out" the php code used in the file?

  3. kjlock75
    Member
    Posted 3 years ago #

    Hello.. glad you find it useful...

    I apologize, but can you try to rephrase your question or show an example because I'm not 100% sure what you mean...

  4. patrickbryant
    Member
    Posted 3 years ago #

    On a page on my site:
    http://www.gototeam.com/testphp/

    I am using the plugin (Thanks Again) to call 5 blog excerpts. Which is code I use on my site often, but not in the plugin.

    When used on the test page the code shows the excerpts, but then also shows all the selected posts in full format.

    Here is the only code on the page:
    [m_include_file filepath="/gttphp/test.php"]

    And, here is the php that's in test.php:

    <?php if (is_single() || is_page() ) : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <?php endwhile; endif; elseif(is_home()) : ?>
    <?php endif; ?>
    
    <?php if (have_posts()) { ?>
    
    		<h3><?php _e('Recent Video Posts from Nashville','Mimbo'); ?></h3>
     <?php
    	$postCount = 0;
    	$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	query_posts( 'paged=&post_per_page=-1&tag=Nashville' . get_query_var('tag') );
    	while (have_posts()) { the_post();
    		if( $postcount == 0 ) {
    		//GETS LATEST OR STICKY POST
    	?>
    
        <div id="lead" class="clearfloat">
    
    			<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
    <?php echo get_post_image (get_the_id(), '', '', '' .get_bloginfo('template_url') .'/scripts/timthumb.php?zc=1&w=260&h=275&src='); ?></a>
    
    	<div id="lead-text">
        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
        <?php the_title(); ?></a></h2>
    
        <p class="date"><?php the_time('n/d/y'); ?> &bull; </p>
    	<?php the_excerpt(); ?>
    	</div>
    	</div><!--END LEAD/STICKY POST-->
    
    		<div id="more-posts">
    
    		<?php
    		}
    		elseif( $postcount > 0 && $postcount <= 4 ) {
    		//GETS NEXT FOUR EXCERPTS
    		?>
    			<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
    <?php echo get_post_image (get_the_id(), '', '', '' .get_bloginfo('template_url') .'/scripts/timthumb.php?zc=1&w=105&h=85&src='); ?></a>
    
    		<div class="clearfloat recent-excerpts">
    
    <h4><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> <span class="commentcount">(<?php comments_popup_link('0', '1', '%'); ?>)</span></h4>
    
    <p class="date"><?php the_time('n/d/y'); ?> &bull; </p>
    			<?php the_excerpt(); ?>
    		</div>
    
    <?php //GETS NEXT HEADLINES
    		}
    		else {
    			ob_start();
    			echo '<li><a href="';
    			the_permalink();
    			echo '">';
    			the_title();
    			echo '</a></li>';
    			$links[] = ob_get_contents();
    			ob_end_clean();
    		}
    		$postcount ++;
    		}
    	}
    	else {
    ?>
    
    <?php } ?>
    			</div>
    
    <?php
    	if(count($links)): ?>
    	<?php endif; ?>

    THANKS FOR LOOKING AT THIS.

  5. kjlock75
    Member
    Posted 3 years ago #

    I see...

    Well.. the way it works is... it essentially replaces the_content() with that code.. so... if you were to open up single.php (or page.php) and did that replace manually and had a peek at the code, you can see that there'd be a loop within a loop.. which is likely why it is generating undesirable results.

    What I would do.. is make a copy of single.php and do the manual replace of the_content until I got it working... then just use "manually replaced" code in my php file... it'll likely be different (but similar) for different themes, what code should be "shaved" off the top and bottom of your code.

    Hope that makes sense.

  6. patrickbryant
    Member
    Posted 3 years ago #

    You helped me tremendously!! Thank You. I was able to play with the code and find the combination that worked. Thanks Again!

  7. sdot1
    Member
    Posted 3 years ago #

    Great plugin, this will help me out a lot, once I get it working.

    I'm pretty knew to wordpress (not PHP though).
    Ok, here's what's going on. I think i've followed your directions pretty good. I created a simple "hello world" script, called it hello.php and placed it in the root of the "wp-content/themes" folder. Then I went into my visual editor and entered this exact line.

    [m_include_file filepath="/wp-content/themes/hello.php"]

    also tried this

    [m_include_file filepath="/themes/hello.php"].

    neither way yielded any results.

    Please tell me what I'm doing wrong.

    WP 3.1
    WAMP

  8. kjlock75
    Member
    Posted 3 years ago #

    Hi sdot1.. your php file should be placed in your current theme folder... such as: /wp-content/themes/{your-theme-name}/

    then when 'including' it you would just use the file name (with a leading slash..

    like: [m_include_file filepath="/hello.php"]

    Let me know if that works for ya...

Topic Closed

This topic has been closed to new replies.

About this Topic