Wordpress Themes - WP Forum at BFA
Click here to register or to donate.
Auto self-registration is not available here - far too many spammers. This forum has many, many backlinks and because of that there is an intense desire among spammers to drop their links here.

Wordpress Themes - WP Forum at BFA » WordPress Themes » Montezuma Theme »

[SOLVED] Ads after first post


  #1  
Old Jun 11, 2013, 02:51 PM
hakonorri
 
12 posts · Feb 2011
Sweden
Hi and thanks for a great theme.
I'm trying to add some ad code between first and second post on my frontage. I tried the same code as Atahualpa uses but it doesn't work.

Code:
<div align="center">
<?php if(!$show_ads){ ?>
ads code
<?php $show_ads = 1; } ?></div>
Any tips?
  #2  
Old Jun 11, 2013, 03:41 PM
CrouchingBruin's Avatar
CrouchingBruin
 
299 posts · Aug 2010
Santa Monica, CA
Where are you trying to insert your code, in the virtual index.php? And how are you determining whether you are between the first and second posts? You are only allowed to put a limited set of PHP code in the virtual PHP pages. In the upper right corner of the virtual page options is a gray tab labeled Limited PHP Code. If you click on it, you'll be able to see what function calls are allowed. One way to possibly get around this is to define a widget area between your posts, but I don't know how you're going to be able to control which posts it shows up after.
__________________
My Montezuma-themed sites: ESHS Girls Basketball Team, Venice Hongwanji Buddhist Temple
Please consider making a donation to BytesForAll for their great themes!
  #3  
Old Jun 11, 2013, 03:41 PM
juggledad's Avatar
juggledad
 
23,682 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
put a 'dynamic sidebar' in the location, add a text widget and install the 'exec php' plugin then add your code to the text widget
  #4  
Old Jun 11, 2013, 11:17 PM
hakonorri
 
12 posts · Feb 2011
Sweden
I created a dynamic sidebar but I don't know where "the location" is? I always get my ad below the last post on the front page. Here is my index.php. Where should it be?
Code:
<!--<div id="container">-->

<?php get_header(); ?>

<div id="main" class="row">

	<div id="content" class="cf col8">
		
        <!--<?php bfa_content_nav( 'multinav1' ); ?> -->
		
		<?php bfa_loop( 'postformat' ); ?>
      
                <?php dynamic_sidebar( 'Ads_firstpost_widget' ); ?> 
		
		<?php bfa_content_nav( 'multinav2' ); ?>
		
	</div>
	
	<div id="widgetarea-one" class="col4">
		<?php dynamic_sidebar( 'Widget Area ONE' ); ?>
	</div>

</div>
	
<?php get_footer(); ?>

<!--</div>-->
  #5  
Old Jun 12, 2013, 01:28 AM
CrouchingBruin's Avatar
CrouchingBruin
 
299 posts · Aug 2010
Santa Monica, CA
Unfortunately, there isn't a function that you can use like in Atahualpa to position something after a certain post. However, it's not that difficult to move it around using jquery.

First, enclose the widget area that you've defined in a DIV, and give it a class called Ads_Widget, like this:

Code:
        <?php bfa_loop( 'postformat' ); ?>

        <div class="Ads_Widget"><?php dynamic_sidebar( 'Ads_firstpost_widget' ); ?></div>
		
        <?php bfa_content_nav( 'multinav2' ); ?>
This will make it easier to select in the jquery code.

Then go to Appearance > Montezuma Options > Head > Insert Code. This section is useful for putting in javascript. If you track your site statistics using something like Google Analytics, for example, this is where you'd put it as well.

In the Bottom field, add this:
Code:
<script>
jQuery(document).ready(function($){

    // Make a copy of the Ads DIV and insert it after the first post
    $(".type-post:first").after($(".Ads_Widget").clone());
  
    // Remove the last ad widget from its current location
    $(".Ads_Widget:last").remove();
    
}); 
</script>
The jQuery ready function executes after the document has been loaded.

There are two lines in the function, both of them commented. The first makes a copy of the ads widget and inserts it after the first post. The second line removes the original (i.e., the last) copy of the widget from the bottom of the page.
__________________
My Montezuma-themed sites: ESHS Girls Basketball Team, Venice Hongwanji Buddhist Temple
Please consider making a donation to BytesForAll for their great themes!

Last edited by CrouchingBruin; Jun 12, 2013 at 08:43 AM.
  #6  
Old Jun 12, 2013, 08:10 AM
jerryc
 
367 posts · Oct 2012
Florida
Quote:
Originally Posted by CrouchingBruin
Unfortunately, there isn't a function that you can use like in Atahualpa to position something after a certain post. However, it's not that difficult to move it around using jquery.
Why couldn't you do something like:

Code:
function to put in x number of posts

ad code

function to put in y number of posts
  #7  
Old Jun 12, 2013, 08:31 AM
CrouchingBruin's Avatar
CrouchingBruin
 
299 posts · Aug 2010
Santa Monica, CA
Quote:
Originally Posted by jerryc
Why couldn't you do something like:

Code:
function to put in x number of posts

ad code

function to put in y number of posts
I don't think there's a function in the Limited PHP Code that outputs a certain number of posts. A PHP function could probably be written; the way it's used above, you'd need a parameter to tell it what post to start at, since you don't want the second call to repeat the same posts as the first call. The jquery code that I posted is pretty easy, though (plus I know jquery a lot better than PHP ).
__________________
My Montezuma-themed sites: ESHS Girls Basketball Team, Venice Hongwanji Buddhist Temple
Please consider making a donation to BytesForAll for their great themes!
  #8  
Old Jun 12, 2013, 10:58 AM
hakonorri
 
12 posts · Feb 2011
Sweden
Thanks CrouchingBruin, your jquery Code worked perfectly.

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Next post and previous post links on top of single post page error susieswe Atahualpa 3 Wordpress theme 2 Jul 15, 2009 02:58 PM


All times are GMT -6. The time now is 03:29 PM.


Powered by vBulletin® Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.