Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Montezuma Theme (http://forum.bytesforall.com/forumdisplay.php?f=53)
-   -   [SOLVED] Ads after first post (http://forum.bytesforall.com/showthread.php?t=20489)

hakonorri Jun 11, 2013 02:51 PM

[SOLVED] Ads after first post
 
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?

CrouchingBruin Jun 11, 2013 03:41 PM

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.

juggledad Jun 11, 2013 03:41 PM

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

hakonorri Jun 11, 2013 11:17 PM

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>-->


CrouchingBruin Jun 12, 2013 01:28 AM

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.

jerryc Jun 12, 2013 08:10 AM

Quote:

Originally Posted by CrouchingBruin (Post 101498)
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


CrouchingBruin Jun 12, 2013 08:31 AM

Quote:

Originally Posted by jerryc (Post 101505)
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 ;)).

hakonorri Jun 12, 2013 10:58 AM

Thanks CrouchingBruin, your jquery Code worked perfectly.


All times are GMT -6. The time now is 05:28 PM.

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