wordpress如何在文章底部加入广告代码?
直接在single.php里添加广告代码不就可以了吗?如果想放在footer.php里,可以用if ( is_single() ) { #广告代码 }这样即可以将广告限定在文章页显示。
如果想利用sidebar和widget小工具实现,还可以参考默认皮肤里的实现方法。
大致步骤是:1、在functions.php里添加sidebar注册,函数为register_sidebar,如function twentytwelve_widgets_init(){register_sidebar( array('name' => __( 'Main Sidebar', 'twentytwelve' ),'id' => 'sidebar-1',....}add_action( 'widgets_init', 'twentytwelve_widgets_init' );2、在footer.php里添加if ( is_single() ) { <?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?><?php dynamic_sidebar( 'sidebar-1' ); ?><?php endif; ?>}3、后台皮肤小工具里,添加文本小工具至添加的sidebar中经过以上3步,广告代码即可实现,而且维护起来方便!
wordpress中怎样插入图片式的广告?
把这个代码放入你主题的functions.php 中,不过在这里建议大家最好是放在另一个文件中,这样以后比较好查找和修改。
还有一点就是函数命名要唯一,不然会和其他函数命名一样而报错。
也可以加上if ( !function_exists('my_test') ) {} 来判断是否存在这个方法,如果存在将不会运行。
这样可以避免报错!如下:if(is_user_logged_in()){$current_user = wp_get_current_user();/*** @example Safe usage: $current_user = wp_get_current_user();* if ( !($current_user instanceof WP_User) )* return;*/echo 'Username: ' . $current_user->user_login . '';echo 'User email: ' . $current_user->user_email . '';echo 'User first name: ' . $current_user->user_firstname . '';echo 'User last name: ' . $current_user->user_lastname . '';echo 'User display name: ' . $current_user->display_name . '';echo 'User ID: ' . $current_user->ID . '';}
转载请注明出处51数据库 » wordpress插入广告