dedecms会员登录前和登录后显示不同价格的办法



注意:此方法也适用与其他字段,做好自己的设置即可

1、在<head>中加入

<script src="{dede:global.cfg_cmsurl/}/include/dedeajax2.js" type="text/javascript" ></script>
<script language="javascript">
function CheckLogin_c(){
var taget_obj = document.getElementById('_userlogin_c');  
 var req = document.getElementById('hid').value;
 myajax = new DedeAjax(taget_obj,false,fal	se,'','','');
 myajax.SendGet2("{dede:global.cfg_cmspath/}/member/ajax_loginsta_c.php?val="+req);
 DedeXHTTP = null;
}
</script> 


2、在模板中

<span id="_userlogin_c">
购买链接(未登录时候显示):{dede:field.url1/}<br />
市场价格(未登录时候显示):{dede:field.jiage1/}<br />
</span>
<input type="hidden" value="{dede:field.aid/}" id="hid" />
<script language="javascript" type="text/javascript">CheckLogin_c();</script>


3、在\member新建一个文件ajax_loginsta_c.php

<?php
/**
 * @version        $Id: ajax_loginsta.php 1 8:38 2010年7月9日Z tianya $
 * @package        DedeCMS.Member
 * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
 * @license        http://help.dedecms.com/usersguide/license.html
 * @link           http://www.dedecms.com
 */
require_once(dirname(__FILE__)."/config.php");
AjaxHead();
if($myurl == '') exit('');

$uid  = $cfg_ml->M_LoginID;

!$cfg_ml->fields['face'] && $face = ($cfg_ml->fields['sex'] == '女')? 'dfgirl' : 'dfboy';
$facepic = empty($face)? $cfg_ml->fields['face'] : $GLOBALS['cfg_memberurl'].'/templets/images/'.$face.'.png';
?>

<?php
$rank=$cfg_ml->M_Rank;
$row = $dsql->GetOne(" Select * From `dede_addon19` where `aid`=$val ");
?>


购买链接(已登录):<?php  echo $row['url2'];?><br />
本店价格:<?php  echo $row['jiage2'];?><br />