Contact Form 7 显示提交成功,并返回当前页面URL

1.需要先为按钮指定ID如“submit”,如果页面有多个表单按钮,那就需要定义多个ID

<a href="#" id="submit" onclick="document.getElementById('click').submit();return false;">
				<div class="yuyue-NOW" id="bottomBnt"><i>开始计算</i></div>
			</a>

 

2.DOM到按钮ID,使用javascript事件来跳转

<script type="text/javascript">
		document.getElementById( "submit" ).addEventListener( "click", function () {
			var url;
//将当前页面的URL,赋值给url变量
			url = window.location.href; 
			alert( "提交成功" );
			//跳转到当前页面URL
			location = url;
		} );
	</script>

 

Contact Form 7 Javascript 代替 html sumit做按钮

案例代码:

<head>
        <meta charset="utf-8">
        <title>注册</title>
        <link rel="stylesheet" type="text/css" href="css/reg.css" />

        //以下定义哪个id 的 form使用 javascript代替
		<script type="text/javascript">
            function submit(){
               $("#click").submit();
            }
        </script>

</head>



//定义 form的ID为click
<form action="loginControl" method="post" id="click">
     <p>
        用户名:<input type="text" name="username" id="username" value="" />
     </p>
            //定义a 为submit
     <a href="#" onclick="document.getElementById('click').submit();return false;">注册</a>
</form>

复制代码

 

wordpress调用目录页

调用目录页:

<ul class="mproductpic">
	<?php if ($posts_perpage) { ?>
	<?php $postsperpage = $posts_perpage; ?>
	<?php } else { ?>
    <?php $postsperpage =6; ?>
    <?php } ?>
    <?php
						$categoryID=$cat;
						
						$wp_query = new WP_Query('cat=' . $categoryID. 'orderby=date&order=desc&posts_per_page='.$postsperpage.'&paged='.$paged); ?>
    <?php while (have_posts()) : the_post(); ?>
		
			
			<li>
				<a href=<?php the_permalink() ?> title="<?php the_title(); ?>"><?php if(function_exists('wp_thumbnails_for_homepage')) { wp_thumbnails_for_homepage(); } ?></a>

				<h2 class="mproductpicbt">
					<?php the_title(); ?>
				</h2>
			</li>
	    <?php endwhile; ?>
			<div class="clearfix"></div>
		</ul>

 

wordpress 获取相关文章两种方法 标签tag 和 目录category

1.使用当前文章tag获取:

<ul class="aboutCon">
<?php
global $post;
$post_tags = wp_get_post_tags($post->ID);
if ($post_tags) {
  foreach ($post_tags as $tag) {
    // 获取标签列表
    $tag_list[] .= $tag->term_id;
  }
 
  // 随机获取标签列表中的一个标签
  $post_tag = $tag_list[ mt_rand(0, count($tag_list) - 1) ];
 
  // 该方法使用 query_posts() 函数来调用相关文章,以下是参数列表
  $args = array(
        'tag__in' => array($post_tag),
        'category__not_in' => array(NULL),  // 不包括的分类ID
        'post__not_in' => array($post->ID),
        'showposts' => 6,                           // 显示相关文章数量
        'caller_get_posts' => 1
    );
  query_posts($args);
 $i=1;
  if (have_posts()) {
    while (have_posts()) {
      the_post(); update_post_caches($posts); ?>
    <li><br /><?php echo $i+".";?><?php the_title(); ?>
				<br /><?php the_excerpt(); ?>
				</li>
<?php
    }
  }
  else {
    echo '<li>* 暂无相关文章</li>';
  }
  wp_reset_query(); 
}
else {
  echo '<li>* 暂无相关文章</li>';
}
?>
				
			</ul>

2.使用目录category获取

<?php
			global $post;
			$cats = wp_get_post_categories( $post->ID );
			if ( $cats ) {
				$args = array(
					'category__in' => array( $cats[ 0 ] ),
					'post__not_in' => array( $post->ID ),
					'showposts' => 6,
					'caller_get_posts' => 1
				);
				query_posts( $args );

				if ( have_posts() ) {
					while ( have_posts() ) {
						the_post();
						update_post_caches( $posts );
						?>

			<li class="tuiJianCon last ">

				<ul class="tuiJianNews">

					<li class="font-24" id="shij">
						<?php the_time('d');?><br/>
						<span>
							<?php the_time('Y-m');?>
						</span>
					</li>
					<li class="newsBt"><a href=<?php the_permalink(); ?> title="<?php the_title(); ?>"><?php the_title(); ?></a>
					</li>
					<li class="newsCon"><a href=<?php the_permalink(); ?> title="">  
	<?php the_excerpt(); ?></a>
					</li>
					<div class="clearfix"></div>
				</ul>
			</li>


			<?php
			}
			} else {
				echo '<li>* 暂无相关文章</li>';
			}
			wp_reset_query();
			}
			else {
				echo '<li>* 暂无相关文章</li>';
			}
			?>

 

wordpress 代码实现分页

分页符调用:

<?php echo paginate_links(array(
    'prev_next'          => 0,
    'before_page_number' => '',
    'mid_size'           => 2,
));?>

分页CSS:

/*分页样式*/
.posts-nav {
	font-size: 14px;
	color:#000000;
	padding: 10px 0;
	margin: 0 auto;
	line-height:23px;text-align:center;
}
.posts-nav .page-numbers {
	border-radius: 3px;
	border: 1px solid rgba(0, 0, 0, 0.15);
	display: inline-block;
	text-align: center;
	width: 30px;
	line-height: 30px;
	margin: 0 5px;
}
.posts-nav .page-numbers.current, .posts-nav .page-numbers:not(.dots):hover {
	background: #1F7508;
	border-color: #1F7508;
	color: #fff;
}
.posts-nav .page-numbers.dots {
	border-color: rgba(0,0,0,0)
}

 

 

wordpress 免插件显示浏览量

在functions.php中放入以下代码:

/*显示文章浏览次数*/
function getPostViews($postID){
$count = get_post_meta($postID,'views', true);
if($count==''){
delete_post_meta($postID,'views');
add_post_meta($postID,'views', '0');
return "0";
}
return $count.'';
}
function setPostViews($postID) {
$count = get_post_meta($postID,'views', true);
if($count==''){
$count = 0;
delete_post_meta($postID,'views');
add_post_meta($postID,'views', '0');
}else{
$count++;
update_post_meta($postID,'views', $count);
}
}

调用代码:

<?php setPostViews(get_the_ID()); echo number_format(getPostViews(get_the_ID())); ?>

 

wordpress 调用指定分类文章不影响后面的the_post

调用代码:

<?php query_posts('cat=3&posts_per_page=4'); while(have_posts()): the_post(); ?>   
  <li>
				<a href=<?php the_permalink() ?> title="<?php the_title(); ?>">
					<?php if(function_exists('wp_thumbnails_for_homepage')) { wp_thumbnails_for_homepage(); } ?>
				</a>
				<h4><?php the_title(); ?></h4>
			</li>
<?php endwhile; wp_reset_query(); ?>