Add talking function to WordPress and modify its style
Principles and requirements
-
Speak in the background; -
Show and talk; -
Talk about content pagination
Start adding
1. Register custom article type
//Reprinted from Wang Boyuan's blog //Register and talk about type articles add_action('init', 'my_custom_init'); function my_custom_init() { $labels=array ('name '=>' Tell me ', 'singular_name '=>' Tell me ', 'add_new'=>'Say something', 'add_new_item'=>'Speak up', 'edit_item'=>'Edit it', 'new_item'=>'Tell me more', 'view_item'=>'View and tell', 'search_items'=>'Search and talk', 'not_found'=>'No comment', 'not_found_in_trush'=>'There is no abandoned talk', 'parent_item_colon'=>'', 'menu_name'=>'Tell me'); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'exclude_from_search' =>true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'has_archive' => false, 'hierarchical' => false, 'menu_position' => null, 'supports' => array('editor','author','title', 'custom-fields') ); register_post_type('shuoshuo',$args); } //End
2. Add a talk page template
2.1 Statement page template
<? php /* Template Name: author: yetu url: http://www.azimiao.com */ get_header(); ?>
2.2 Modify Content Query Code
<div class="content"> <link rel="stylesheet" href="//css.azimiao.com/shuoshuo.css" type="text/css"> <div id="article"> <h1><a href="<?php the_permalink() ?> " rel="bookmark"><?php the_title();?></ a></h1> <div class="position">Current position:<a href="<? Php echo get_option ('home ');?>/ ">Home</a>» Talk about</div> <div id="article_content"> <ul class="cbp_tmtimeline"> <? php $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $show_posts = 4; // Number of pages displayed per page $permalink = 'Post name'; // Default, Post name $post_type = 'shuoshuo'; // Know the current URI $req_uri = $_SERVER['REQUEST_URI']; // Permalink set to default if ($permalink == 'Default') { $req_uri = explode('paged=', $req_uri); if ($_GET['paged']) { $uri = $req_uri[0] . ' paged='; } else { $uri = $req_uri[0] . '& paged='; } //Permalink is set to Post name } elseif ($permalink == 'Post name') { if (strpos($req_uri, 'page/') !== false) { $req_uri = explode('page/', $req_uri); $req_uri = $req_uri[0]; } $uri = $req_uri . ' page/'; } //Query //echo 'showposts='.$ show_posts.'&post_type='. $post_type .'&paged='.$paged; $wp_query->query('showposts=' . $show_posts . '&post_type=' . $post_type . '&paged=' . $paged); //count posts in the custom post type $count_posts = wp_count_posts('projects'); while ($wp_query->have_posts()) : $wp_query->the_post();?> <li> <time class="cbp_tmtime"> <span><? php the_time('y-n-j');?></ span> </time> <div class="cbp_tmlabel"> <p><? php the_content();?></ p> </div> </li> <? php endwhile;?> </ul> </div> <? php comments_template();?> </div> </div>
2.3 Pagination
<!-- Paging --> <div class="pagination"> <? php by_pagenavi(); ?> </div>
<? php //Pagination navigation display method //Reprinted from Wang Boyuan's blog function by_pagenavi($before = '', $after = '', $p = 2) { if (is_singular()) return; global $wp_query, $paged; $max_page = $wp_query->max_num_pages; if ($max_page == 1) return; if (empty($paged)) $paged = 1; echo $before; If ($paged>1) by_p_link ($paged - 1, 'Previous','<span class="pg item pg nav item pg prev">',' Previous'); If ($paged>$p+1) by_p_link (1, 'Home', '<span class="pg item">', 1); for ($i = $paged - $p; $ i <= $paged + $p; $i++) { if ($i > 0 && $i <= $max_page) $i == $paged ? print "<span class='pg-item pg-item-current'><span class='current'>{$i}</span></span>" : by_p_link($i, '', '<span class="pg-item">', $i); } If ($paged<$max_page - $p) by_p_link ($max_page, 'last page', '<span class="pg item">...</span><span class="pg item">', $max_page); If ($paged<$max_page) by_p_link ($paged+1, 'Next Page', '<span class="pg item pg nav item pg text">', 'Next Page'); echo $after; } function by_p_link($i, $title = '', $linktype = '', $prevnext = '') { If ($title=='') $title="Browse page {$i}"; if ($linktype == '') { $linktext = $i; } else { $linktext = $linktype; } echo "{$linktext}<a style = 'border-bottom:1px solid #eaeaea ! important;' href='", esc_html(get_pagenum_link($i)), "' title='{$title}' class='navbutton'>{$prevnext}</a></span>"; } ?>
/* Paging Navigation Style Reprinted from Wang Boyuan's blog */ div.pagination { padding: 0px; margin: 25px 0 40px; text-align: center; font-size: 15px; line-height: 17px; position: relative; } .pagination .pg-filler-1 { width: 35%; } .pagination .pg-filler-2 { width: 40%; } .pagination .pg-item a, .pagination .pg-item .current, .pagination .pg-dots, .pagination .pg-item .disabled { display: inline-block; color: #666; padding: 9px 13px; border-radius: 3px; -webkit-border-radius: 3px; -moz-border-radius: 3px; text-decoration: none; margin: 0 1px; min-width: 10px; } .pagination .pg-item a { -webkit-transition: background 0.2s linear; -moz-transition: background 0.2s linear; -ms-transition: background 0.2s linear; -o-transition: background 0.2s linear; transition: background 0.2s linear; -webkit-backface-visibility: hidden; -moz-backface-visibility: hidden; } .pagination .pg-next { position: absolute; right: 20px; } .pagination .pg-prev { position: absolute; left: 20px; } .pg-nav-item { text-transform: uppercase; } .pagination .pg-item .current, .pagination .pg-item a:hover { background: #ff5e52; color: #fff; } div.pagination span.current, div.pagination a { padding: 0px; text-decoration: none; } div.pagination a.navbutton { margin: 0 2px; border: 1px solid #eaeaea; }
Usage and effect
Friendly Reminder
References
Comment
Comment area
0F I want to change to wp 🙁 0F I can really peck and grind 🙂 0F Too long, don't look 23333 0F It's good to see~Take it away. It's good to post some brief complaints on the talk page 0F 0F Lazy cancer attack, too lazy to add functions 0F EMmm, talk about the function of ty 0F Azimiao~, why is your home page articles in a disordered order? The previous ones have all come up. I don't know why. Every time you open your home page, it's very slow. It takes several minutes emmmmm~~ I don't know what happened to the network problem... I tried to visit my friends in Jiangsu, Hainan and my own Hebei Telecom Mobile Unicom, and the speed was OK 😕 Is it because I used an agent? But I'm not very fast at home and in the company. I used to drive in seconds, thinking deeply~~ Do you want to visit this static page? www.azimiao.com/special/star/ This page is OK~