ആർട്ടിക്കിൾ ഡയറക്ടറി
വേർഡ്പ്രൈസ്ഒരു ബിൽറ്റ്-ഇൻ ആർട്ടിക്കിൾ സ്റ്റിക്കിംഗ് ഫംഗ്ഷൻ ഉണ്ട്, എന്നാൽ സ്ഥിരസ്ഥിതിയായി, സ്റ്റിക്കി ലേഖനങ്ങൾ പ്രദർശിപ്പിക്കുന്നതിന് മുകളിലെ പേജ് മാത്രമേ പിന്തുണയ്ക്കൂ.
മറ്റ് ആർക്കൈവ് പേജുകൾക്ക് (വിഭാഗ പേജുകൾ, ടാഗ് പേജുകൾ, രചയിതാവിന്റെ പേജുകൾ, തീയതി പേജുകൾ എന്നിവ പോലുള്ളവ) മുകളിൽ സ്റ്റിക്കി ലേഖനങ്ങൾ പ്രദർശിപ്പിക്കാൻ കഴിയില്ല, സ്ഥിരസ്ഥിതി ക്രമത്തിൽ മാത്രം.
WordPress-മായി ഒരുപാട് കാര്യങ്ങൾ ചെയ്യാനുണ്ട്എസ്.ഇ.ഒ.സുഹൃത്തുക്കളേ, ഈ പ്രശ്നങ്ങൾ പരിഹരിക്കുമെന്ന് പ്രതീക്ഷിക്കുന്നു.
വാസ്തവത്തിൽ, നമുക്ക് wp-includes/query.php-ന്റെ ഹോം പേജിന്റെ കോഡ് റഫർ ചെയ്ത് ചെറുതായി പരിഷ്ക്കരിക്കേണ്ടതുണ്ട്, അതുവഴി ആർക്കൈവ് പേജിന്റെ മുകളിൽ (വിഭാഗ പേജ്, ടാബ് പേജ്, രചയിതാവ് പേജ്, തീയതി പേജ് എന്നിവ പോലെ). ) മുകളിലെ ലേഖനവും പ്രദർശിപ്പിക്കാൻ കഴിയും.
WordPress സ്റ്റിക്കി ലേഖന കോഡ്
നിങ്ങളുടെ നിലവിലെ തീമിന് താഴെയുള്ള functions.php ഫയലിൽ ഇനിപ്പറയുന്ന കോഡ് ഇടുക ▼
//让WordPress分类、标签、存档和作者页显示置顶文章 add_filter('the_posts', 'putStickyOnTop' ); function putStickyOnTop( $posts ) { if ( is_series() || is_home() || !is_main_query() || !is_archive()) return $posts; global $wp_query; $sticky_posts = get_option('sticky_posts'); if ( $wp_query->query_vars['paged'] <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !get_query_var('ignore_sticky_posts') ) { $stickies1 = get_posts( array( 'post__in' => $sticky_posts ) ); foreach ( $stickies1 as $sticky_post1 ) { // 判断当前是否分类页 if($wp_query->is_category == 1 && !has_category($wp_query->query_vars['cat'], $sticky_post1->ID)) { // 移除不是本分类的文章 $offset1 = array_search($sticky_post1->ID, $sticky_posts); unset( $sticky_posts[$offset1] ); } if($wp_query->is_tag == 1 && has_tag($wp_query->query_vars['tag'], $sticky_post1->ID)) { // 移除不是本标签的文章 $offset1 = array_search($sticky_post1->ID, $sticky_posts); unset( $sticky_posts[$offset1] ); } if($wp_query->is_year == 1 && date_i18n('Y', strtotime($sticky_post1->post_date))!=$wp_query->query['m']) { // 移除不是本年份的文章 $offset1 = array_search($sticky_post1->ID, $sticky_posts); unset( $sticky_posts[$offset1] ); } if($wp_query->is_month == 1 && date_i18n('Ym', strtotime($sticky_post1->post_date))!=$wp_query->query['m']) { // 移除不是本月份的文章 $offset1 = array_search($sticky_post1->ID, $sticky_posts); unset( $sticky_posts[$offset1] ); } if($wp_query->is_day == 1 && date_i18n('Ymd', strtotime($sticky_post1->post_date))!=$wp_query->query['m']) { // 移除不是本日期的文章 $offset1 = array_search($sticky_post1->ID, $sticky_posts); unset( $sticky_posts[$offset1] ); } if($wp_query->is_author == 1 && $sticky_post1->post_author != $wp_query->query_vars['author']) { // 移除不是本作者的文章 $offset1 = array_search($sticky_post1->ID, $sticky_posts); unset( $sticky_posts[$offset1] ); } } $num_posts = count($posts); $sticky_offset = 0; // Loop over posts and relocate stickies to the front. for ( $i = 0; $i < $num_posts; $i++ ) { if ( in_array($posts[$i]->ID, $sticky_posts) ) { $sticky_post = $posts[$i]; // Remove sticky from current position array_splice($posts, $i, 1); // Move to front, after other stickies array_splice($posts, $sticky_offset, 0, array($sticky_post)); // Increment the sticky offset. The next sticky will be placed at this offset. $sticky_offset++; // Remove post from sticky posts array $offset = array_search($sticky_post->ID, $sticky_posts); unset( $sticky_posts[$offset] ); } } // If any posts have been excluded specifically, Ignore those that are sticky. if ( !empty($sticky_posts) && !empty($wp_query->query_vars['post__not_in'] ) ) $sticky_posts = array_diff($sticky_posts, $wp_query->query_vars['post__not_in']); // Fetch sticky posts that weren't in the query results if ( !empty($sticky_posts) ) { $stickies = get_posts( array( 'post__in' => $sticky_posts, 'post_type' => $wp_query->query_vars['post_type'], 'post_status' => 'publish', 'nopaging' => true ) ); foreach ( $stickies as $sticky_post ) { array_splice( $posts, $sticky_offset, 0, array( $sticky_post ) ); $sticky_offset++; } } } return $posts; } //置顶文章添加样式 add_filter('post_class', 'addStickyClass' ,10,3 ); function addStickyClass( $classes, $class, $post_id ){ if( is_sticky() && is_category() && !isset( $classes['sticky'] ) ){ $classes[] = 'sticky'; } return $classes; }
സ്റ്റിക്കി ലേഖനത്തിന്റെ കോഡ് ഉപയോഗിക്കുന്നതിനുള്ള നിർദ്ദേശങ്ങൾ
1) ആർക്കൈവ് പേജ് എല്ലാ പ്രധാന ലേഖനങ്ങളും പ്രദർശിപ്പിക്കണമെങ്കിൽ, കോഡിന്റെ 11-43 വരികൾ ഇല്ലാതാക്കുക;
2) വർഗ്ഗ പേജിൽ പ്രധാന ലേഖനം പ്രദർശിപ്പിക്കാൻ നിങ്ങൾ ആഗ്രഹിക്കുന്നില്ലെങ്കിൽ, ദയവായി വരി 3 ൽ ▼ ചേർക്കുക
if(
▼ എന്നതിലേക്ക് പരിഷ്ക്കരിക്കുക
// abc是分类的名称 if ( is_category( 'abc' ) ||
3) ടാബ് പേജിൽ പ്രധാന ലേഖനം പ്രദർശിപ്പിക്കാൻ നിങ്ങൾക്ക് താൽപ്പര്യമില്ലെങ്കിൽ, ദയവായി 3 വരിയിൽ ▼
if(
ഇതിലേക്ക് മാറ്റുക:
// abc是标签的名称
if ( is_tag( 'abc' ) ||
4) രചയിതാവ് പേജ് പ്രധാന ലേഖനം പ്രദർശിപ്പിക്കാൻ ആഗ്രഹിക്കുന്നില്ലെങ്കിൽ, ദയവായി 3 വരിയിൽ ▼
if(
▼ എന്നതിലേക്ക് പരിഷ്ക്കരിക്കുക
// abc是作者的昵称
if ( is_author( 'abc' ) ||
5) നിങ്ങൾക്ക് ഒരു ഇഷ്ടാനുസൃത വിഭാഗം പേജ് മുകളിൽ ലേഖനം പ്രദർശിപ്പിക്കാൻ താൽപ്പര്യമില്ലെങ്കിൽ, ഇടുക
if(
ഇതിലേക്ക് മാറ്റുക:
// series是自定义分类、abc是自定义分类名称 if ( is_series( 'abc' ) ||
ആർക്കൈവ് പേജിൽ പോസ്റ്റുകളുടെ ഒരു ലിസ്റ്റ് ലഭിക്കുന്നതിന് നിങ്ങൾ WP_Query അല്ലെങ്കിൽ query_posts ഉപയോഗിക്കുകയും ആ ലിസ്റ്റുകൾക്ക് മുകളിൽ പിൻ ചെയ്ത പോസ്റ്റ് പ്രദർശിപ്പിക്കാൻ ആഗ്രഹിക്കുകയും ചെയ്യുന്നുവെങ്കിൽ, മുകളിലുള്ള കോഡ് പ്രധാന ലൂപ്പിന് മാത്രമേ സാധുതയുള്ളൂ.
വരി 3-ൽ നിങ്ങൾക്ക് ഇനിപ്പറയുന്ന കോഡ് ഇല്ലാതാക്കാം (പ്രദർശിപ്പിച്ചിരിക്കുന്ന ലേഖനങ്ങളുടെ എണ്ണം നിങ്ങൾ സജ്ജമാക്കിയതിൽ നിന്ന് വ്യത്യസ്തമാകാം) ▼
|| !is_main_query()
മുകളിലെ ലേഖനത്തിലേക്ക് ശൈലി ചേർക്കുക
നിങ്ങൾക്ക് സ്റ്റിക്കി പോസ്റ്റിലേക്ക് ശൈലികൾ ചേർക്കണമെങ്കിൽ, functions.php-ലേക്ക് ഇനിപ്പറയുന്ന കോഡ് ചേർക്കുകയും സ്റ്റിക്കി പോസ്റ്റിലേക്ക് സ്റ്റിക്കി എന്ന് പേരുള്ള ഒരു ക്ലാസ് ചേർക്കുകയും ചെയ്യുക.
പൊതുവായ വേർഡ്പ്രസ്സ് തീമുകൾക്ക് മികച്ച ലേഖന ശൈലിയുടെ CSS കോഡ് ഉണ്ടായിരിക്കും, നിങ്ങൾക്ക് ഇഷ്ടാനുസൃതം ചേർക്കാനും കഴിയും ▼
//置顶文章添加样式 add_filter('post_class', 'addStickyClass' ,10,3 ); function addStickyClass( $classes, $class, $post_id ){ if( is_sticky() && is_category() && !isset( $classes['sticky'] ) ){ $classes[] = 'sticky'; } return $classes; }
- വിഭാഗം താളിന്റെ ഏറ്റവും ഉയർന്ന ലേഖന ശൈലി ഇഫക്റ്റ്,ചെൻ വെയ്ലിയാങ്ബ്ലോഗ് ലേഖന വിഭാഗങ്ങൾ:ചൈനീസ് മൊബൈൽ നമ്പർ
- (തീം മാറ്റുക കാലഹരണപ്പെട്ടു)
വേർഡ്പ്രസ്സ് വിഭാഗ ആർക്കൈവ് പേജുകൾ വേർഡ്പ്രസ്സ് ലേഖനങ്ങൾ മുകളിൽ കാണിക്കാൻ മറ്റൊരു വഴിയുണ്ട്▼
ഹോപ്പ് ചെൻ വെയ്ലിയാങ് ബ്ലോഗ് ( https://www.chenweiliang.com/ ) പങ്കിട്ടു "വേർഡ്പ്രസ്സ് വിഭാഗം/ടാഗ്/രചയിതാവ് പേജ് സ്റ്റിക്കി ലേഖനങ്ങൾ കാണിക്കുന്നത് എങ്ങനെ? , നിന്നെ സഹായിക്കാൻ.
ഈ ലേഖനത്തിന്റെ ലിങ്ക് പങ്കിടാൻ സ്വാഗതം:https://www.chenweiliang.com/cwl-878.html
ഏറ്റവും പുതിയ അപ്ഡേറ്റുകൾ ലഭിക്കുന്നതിന് ചെൻ വെയ്ലിയാങ്ങിന്റെ ബ്ലോഗിന്റെ ടെലിഗ്രാം ചാനലിലേക്ക് സ്വാഗതം!
📚 ഈ ഗൈഡിൽ വലിയ മൂല്യമുണ്ട്, 🌟 ഇതൊരു അപൂർവ അവസരമാണ്, ഇത് നഷ്ടപ്പെടുത്തരുത്! ⏰⌛💨
ഇഷ്ടമായാൽ ഷെയർ ചെയ്യുക, ലൈക്ക് ചെയ്യുക!
നിങ്ങളുടെ ഷെയറിംഗും ലൈക്കുകളുമാണ് ഞങ്ങളുടെ തുടർച്ചയായ പ്രചോദനം!