如题,wordpress设置文章自定义来源,图就懒的去截了,参考本站即可。
本站所用主题自带功能,相关代码如下。
使用的时候,添加自定义栏目from_site_name和from_site_url
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <div class="single"> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <h1><?php the_title(); ?></h1> <div class="meta singlemeta"> <span><?php the_time('Y-m-d H:i'); ?></span> <span>作者: <?php the_author_posts_link(); ?></span> <span>来源: <?php if ( get_post_meta($post->ID, 'from_site_name', true) && get_post_meta($post->ID, 'from_site_url', true) ) { ?> <a href="<?php echo get_post_meta($post->ID, "from_site_url", true); ?>" target="_blank"><?php echo get_post_meta($post->ID, "from_site_name", true); ?></a> <?php } elseif ( get_post_meta($post->ID, 'from_site_name', true) && get_post_meta($post->ID, 'from_site_url', false) ) {?> <a href="#" target="_blank"><?php echo get_post_meta($post->ID, "from_site_name", true); ?></a> <?php } elseif ( get_post_meta($post->ID, 'from_site_name', false) && get_post_meta($post->ID, 'from_site_url', true) ) {?> <a href="<?php echo get_post_meta($post->ID, "from_site_url", true); ?>" target="_blank">网络</a> <?php } else {?> <a href="<?php bloginfo('siteurl');?>/">本站</a></a> <?php } ?> </span> <span>浏览: <?php if(function_exists('the_views')) { the_views(); } ?></span> <span class="cmts"><a href="#addcomment">我要评论</a></a><?php comments_popup_link('', '(1条)', '(%条)'); ?></span> <span>字号: <a href="javascript:void(0)" class="mfbig">大</a> <a href="javascript:void(0)" class="mfmid">中</a> <a href="javascript:void(0)" class="mfsml mfcurrent">小</a> </span> <?php edit_post_link('编辑本文', '', ''); ?> </div> <!-- PostContent begin --> <div class="entry"> <?php if ( get_option('wpyou_if_excerpt') == '0' ) { ?> <p class="summary"><strong>摘要</strong>: <?php echo wpyou_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 130,"..."); ?></p> <?php } ?> <div class="entrycontent"> <!-- SingleAd begin --> |
会员登录关闭
注册会员关闭