最后我解决了这个问题。下面是下载按钮的代码。将此代码放入您的post循环中,它将显示一个下载按钮。
<form action="<?php echo esc_url( home_url( \'/your_redirected_page_slug\' ) ); ?>" method="GET" id="form1">
<?php global $post;
//$post_slug=$post->post_name;
?>
<input id="myButton" type="submit" name="a" value="Download" class="single-download-button" />
<input type="hidden" name="appk" id="mkval" value="<?php echo get_the_ID(); ?>" />
</form>
当有人点击该按钮时,它将重定向到下载页面。然后将下面的代码放到该页:
<?php
$id = $_GET[\'appk\']; // get form data
$popularpost = new WP_Query( array(\'post_type\' => \'your_cusom_post_name\',
\'posts_per_page\' => 9,
// \'meta_key\' => \'wpb_post_views_count\',
//\'orderby\' => \'meta_value_num\',
\'order\' => \'DESC\',
\'p\' => $id,
) );
while ( $popularpost->have_posts() ) : $popularpost->the_post();
$id = get_the_ID();
?>
<!-- Your Code Function here -->
<?php
endwhile;
// Reset Post Data
wp_reset_postdata();
?>
就这样。。。。。。享受