Recent Topics

1 Jul 29, 2005 08:24    

I want my blog to show the first 2 posts and then have an ad or picture or some sort of static content display, and then after it displays have the rest of the posts resume displaying.
like this:

post1
post2
ad
post3
post4
post 5

I know I have to somehow modify the looping that pulls the posts from the database but I don't know how to do it. (I'm trying to learn PHP as we speak but it may take me awhile since it's in my spare time)

If this has been answered please give me a link (I couldn't find it searching/don't know what to search for, maybe?)

If there isn't a link I would appreciate any help or sollutions you can provide.

3 Jul 30, 2005 23:22

Thanks for the link, Personman, I tried what you said ( excluding the ++ incrementor for now) and it put a string of text between every post.

I think you're on the right path and now we need to write some sort of loop that takes the MainList item, and increments it a set number of times, then displays the ad code, and then after the ad code has been proven true once, it goes back to the MainList code to continue displaying.

Easy. Yeah right!

I'll try hammering away at it and see if I can figure anything out. I might even get lucky!

Comments and sollutions are still welcome!

4 Jul 30, 2005 23:25

This is the code and what I changed and where I put the code. BTW I had to put the ads file in the custom directory to make it work just to clear it up incase there is any confusion.

<!-- =================================== START OF MAIN AREA =================================== -->

<?php // ------------------------------------ START OF POSTS ----------------------------------------
if( isset($MainList) ) $MainList->display_if_empty(); // Display message if no post

if( isset($MainList) ) while( $Item = $MainList->get_item() )
{
$MainList->date_if_changed();
?>
<div class="bPost" lang="<?php $Item->lang() ?>">

<?php
locale_temp_switch( $Item->locale ); // Temporarily switch to post locale
$Item->anchor(); // Anchor for permalinks to refer to
?>
<div class="bSmallHead">
<a href="<?php $Item->permalink() ?>" title="<?php echo T_('Permanent link to full entry') ?>"><img src="img/icon_minipost.gif" alt="Permalink" width="12" height="9" class="middle" /></a>
<?php
$Item->issue_time();
echo ', ', T_('Categories'), ': ';
$Item->categories();
echo ', ';
$Item->wordcount();
echo ' ', T_('words'), ' &nbsp; ';
locale_flag( $Item->locale, 'h10px' );
?>
</div>
<h3 class="bTitle"><?php $Item->title(); ?></h3>
<div class="bText">
<?php $Item->content(); ?>
<?php link_pages() ?>
</div>
<div class="bSmallPrint">
<a href="<?php $Item->permalink() ?>" title="<?php echo T_('Permanent link to full entry') ?>" class="permalink_right"><img src="img/chain_link.gif" alt="<?php echo T_('Permalink') ?>" width="14" height="14" border="0" class="middle" /></a>

<?php $Item->feedback_link( 'comments' ) // Link to comments ?>
<?php $Item->feedback_link( 'trackbacks', ' &bull; ' ) // Link to trackbacks ?>
<?php $Item->feedback_link( 'pingbacks', ' &bull; ' ) // Link to trackbacks ?>

<?php $Item->edit_link( ' &bull; ' ) // Link to backoffice for editing ?>

<?php $Item->trackback_rdf() // trackback autodiscovery information ?>
</div>
<?php // ------------- START OF INCLUDE FOR COMMENTS, TRACKBACK, PINGBACK, ETC. -------------
$disp_comments = 1; // Display the comments if requested
$disp_comment_form = 1; // Display the comments form if comments requested
$disp_trackbacks = 1; // Display the trackbacks if requested

$disp_trackback_url = 1; // Display the trackbal URL if trackbacks requested
$disp_pingbacks = 1; // Display the pingbacks if requested
require( dirname(__FILE__).'/_feedback.php' );
// ---------------- END OF INCLUDE FOR COMMENTS, TRACKBACK, PINGBACK, ETC. ----------------

locale_restore_previous(); // Restore previous locale (Blog locale)
?>

</div>
<?php

// ----------------------------------- THIS IS WHAT I CHANGED --------------------------------------------------------------------------------------------------------------------------------------------------

if (!isset($after_post) ) {$after_post = 1;} // set it to one the first time
$adfile = 'ads/afterpost' . $after_post . '.php';
include($adfile); // increase by one for the next time

// then the loop ends

// -------------------------------- END OF CHANGE ------------------------------------------------------------------------------------------------------------------------------------
}

// ---------------------------------- END OF POSTS ------------------------------------ ?>

5 Jul 31, 2005 04:03

Can you give your url? I'd like to see this in action. And what is it that you want it to do next? If you want to have your ads not show up after every post then the ++ line is key.

6 Aug 04, 2005 19:27

I redid what you said and added the ++ incrementor and you're right it is key, but now I need to change it so I can set it to only run a certain number of times.

Here's my URl http://bigface.hostmatrix.org/

I get errors after the other posts, and the ad shows up after the first post and not the second. I think this is all just a matter of tweaking it a bit.

7 Aug 04, 2005 19:50

You need an if statement to say "insert this stuff only if the counter is a certain value". Here's what I would do:

Right before the posts loop starts set a counter to 0 and define your insertable stuff path:

<?php // START POSTS
$insert_stuff = 0; // here's the counter
$adfile = 'ads/afterpost' . $after_post . '.php'; // and here's the path
if( isset($MainList) ) $MainList->display_if_empty(); // Display message if no post
if( isset($MainList) ) while( $Item = $MainList->get_item() ) {

Now after each post executes increment the counter then check if you've got the right number of posts displayed. If so insert your stuff. My files are heavily hacked, but this should get you in the ballpark:

locale_restore_previous(); // Restore previous locale (Blog locale)
?>

</div>
<?php 
$insert_stuff = $insert_stuff+1; // increment your counter
if( $insert_stuff == 2 ) { // ask if the counter is the right number
	include($adfile); // insert your groovy stuff
	} // close your if statement
} ?> // THIS WAS ALREADY THERE - IT ENDS THE POSTS LOOP

<p class="center"><strong>
<?php posts_nav_link(); ?>

Or something like that ;) I might have the wrong location for the "increment and if" but it's probably pretty close. Oh and I don't do ++ because somewhere back in the past it didn't behave the way I expected but NN+1 worked correctly.

8 Aug 04, 2005 20:33

Thanks! I'll try that Edb.

BTW in a less elegant way I fixed the problem (though it is not practical for long blogs) by just adding 4 blank adfiles to the ads directory. Since B2E already sets the number of posts displayed to 5 (or the number you choose) After the fith post it stops the loop by itself so the four blank files display as nothing and the counter for $after_post stops anyway.

Not the best solution but it works for now.

I'm going to try Edb's sollution next just because it would be more expandable.

9 Aug 04, 2005 20:53

I'm dancing a jig right now! :D

It worked guys!

The only thing that I had to add to Edb's hack was a value for the $after_post variable and it works every time! (my file was called afterpost2.php so I just put a 2 in the path line) With a bit more code you could make a form that would change this so you could add whatever content you needed. I don't need that right now but it would be relatively simple. (the fatal words :) )

Here's what it looks like alltogether.

<?php // ------------------------------------ START OF POSTS ----------------------------------------
	
$insert_stuff = 0; // here's the counter 
$adfile = 'ads/afterpost' . 2 . '.php'; // you could change the 2 to a variable to specify different files

// NORMAL STUFF DISPLAYED NEXT

if( isset($MainList) ) $MainList->display_if_empty(); // Display message if no post

	if( isset($MainList) ) while( $Item = $MainList->get_item() )
	{


		$MainList->date_if_changed();

	?>
	<div class="bPost" lang="<?php $Item->lang() ?>">




		<?php
			locale_temp_switch( $Item->locale ); // Temporarily switch to post locale
			$Item->anchor(); // Anchor for permalinks to refer to
		?>
		<div class="bSmallHead">
		<a href="<?php $Item->permalink() ?>" title="<?php echo T_('Permanent link to full entry') ?>"><img src="img/icon_minipost.gif" alt="Permalink" width="12" height="9" class="middle" /></a>
		<?php
			$Item->issue_time();
			echo ', ', T_('Categories'), ': ';
			$Item->categories();
			echo ', ';
			$Item->wordcount();
			echo ' ', T_('words'), ' &nbsp; ';
			locale_flag( $Item->locale, 'h10px' );
		?>
		</div>
		<h3 class="bTitle"><?php $Item->title(); ?></h3>
		<div class="bText">
			<?php $Item->content(); ?>
			<?php link_pages() ?>
		</div>
		<div class="bSmallPrint">
			<a href="<?php $Item->permalink() ?>" title="<?php echo T_('Permanent link to full entry') ?>" class="permalink_right"><img src="img/chain_link.gif" alt="<?php echo T_('Permalink') ?>" width="14" height="14" border="0" class="middle" /></a>

			<?php $Item->feedback_link( 'comments' ) // Link to comments ?>
			<?php $Item->feedback_link( 'trackbacks', ' &bull; ' ) // Link to trackbacks ?>
			<?php $Item->feedback_link( 'pingbacks', ' &bull; ' ) // Link to trackbacks ?>

			<?php $Item->edit_link( ' &bull; ' ) // Link to backoffice for editing ?>

			<?php $Item->trackback_rdf() // trackback autodiscovery information ?>
		</div>
			<?php // ------------- START OF INCLUDE FOR COMMENTS, TRACKBACK, PINGBACK, ETC. -------------
			$disp_comments = 1;					// Display the comments if requested
			$disp_comment_form = 1;			// Display the comments form if comments requested
			$disp_trackbacks = 1;				// Display the trackbacks if requested

			$disp_trackback_url = 1;		// Display the trackbal URL if trackbacks requested
			$disp_pingbacks = 1;				// Display the pingbacks if requested
			require( dirname(__FILE__).'/_feedback.php' );
			// ---------------- END OF INCLUDE FOR COMMENTS, TRACKBACK, PINGBACK, ETC. ----------------

			locale_restore_previous();	// Restore previous locale (Blog locale)
			?>


	</div>
<?php 

// END NORMAL STUFF

$insert_stuff = $insert_stuff+1; // increment your counter 
if( $insert_stuff == 2 ) { // ask if the counter is the right number
   include($adfile); // insert your groovy stuff
   } // increase by one for the next time
// then the loop ends 
}

// ---------------------------------- END OF POSTS ------------------------------------ ?>


Form is loading...