浏览代码

take a different approach to the read more link:

Ben Dwyer 4 年之前
父节点
当前提交
847be857ff
共有 5 个文件被更改,包括 63 次插入20 次删除
  1. 13 5
      spearhead/assets/sass/_posts-and-pages.scss
  2. 40 11
      spearhead/functions.php
  3. 5 2
      spearhead/style-rtl.css
  4. 5 2
      spearhead/style.css
  5. 0 0
      spearhead/style.css.map

+ 13 - 5
spearhead/assets/sass/_posts-and-pages.scss

@@ -54,17 +54,18 @@
 .entry-content {
     .more-link {
         margin-top: 0;
-        margin-left: 0.5rem;
         display: inline-block;
         color: var(--global--color-foreground);
-        font-size: calc(0.75 * var(--global--font-size-base));
+
         &:hover {
             border: none;
             color: var(--global--color-primary);
-        }
+		}
+
         &:after {
             content: none;
-        }
+		}
+
         svg {
             height: var(--global--font-size-base);
             width: var(--global--font-size-base);
@@ -73,5 +74,12 @@
             vertical-align: middle;
             transform: rotate(-90deg);
         }
-    }
+	}
+
+	.excerpt-more-link {
+		.more-link {
+			font-size: calc(0.75 * var(--global--font-size-base));
+			margin-left: var(--global--spacing-horizontal);
+		}
+	}
 }

+ 40 - 11
spearhead/functions.php

@@ -195,24 +195,53 @@ add_filter(
 	}
 );
 
-/*
- * Create the continue reading link
+/**
+ * Create the continue reading link.
  */
-function spearhead_continue_reading_link() {
-
+function spearhead_continue_reading_link( $more ) {
 	if ( ! is_admin() ) {
-		$continue_reading = sprintf(
-			/* translators: %s: Name of current post. */
-			wp_kses( __( 'More %s', 'seedlet' ), array( 'span' => array( 'class' => array() ) ) ),
-			the_title( '<span class="screen-reader-text">"', '"</span>', false )
-		);
+		$more_link = spearhead_more_link();
 
-		return '<a class="more-link" href="' . esc_url( get_permalink() ) . '">' . $continue_reading . ' ' . seedlet_get_icon_svg( 'dropdown' ) . '</a>';
+		return '<p>' . $more_link . '</p>';
 	}
 }
 
+/**
+ * Create a more link for use in both "Read more" and excerpt contexts.
+ */
+function spearhead_more_link() {
+	$more_text = sprintf(
+		/* translators: %s: Name of current post. */
+		wp_kses( __( 'More', 'spearhead' ), array( 'span' => array( 'class' => array() ) ) ),
+		the_title( '<span class="screen-reader-text">"', '"</span>', false )
+	);
+
+	return '<a class="more-link" href="' . esc_url( get_permalink() ) . '">' . $more_text . ' ' . seedlet_get_icon_svg( 'dropdown' ) . '</a>';
+}
+
+/**
+ * Use this instead of the default WordPress ellipsis which is […].
+ */
+function spearhead_excerpt_more() {
+	return '…';
+}
+
+
+function spearhead_the_excerpt( $excerpt ) {
+	// For cases where the post excerpt is empty
+	// (but the post might have content)
+	if ( 0 === strlen( $excerpt ) ) {
+		return $excerpt . $link;
+	}
+
+	return $excerpt . '<span class="excerpt-more-link">' . spearhead_more_link() . '</span>';
+}
+
 // Filter the excerpt more link
-add_filter( 'excerpt_more', 'spearhead_continue_reading_link' );
+add_filter( 'excerpt_more', 'spearhead_excerpt_more' );
 
 // Filter the content more link
 add_filter( 'the_content_more_link', 'spearhead_continue_reading_link' );
+
+// Filter the excerpt
+add_filter( 'get_the_excerpt', 'spearhead_the_excerpt' );

+ 5 - 2
spearhead/style-rtl.css

@@ -86,10 +86,8 @@ Tags: one-column, flexible-header, accessibility-ready, custom-colors, custom-me
 
 .entry-content .more-link {
 	margin-top: 0;
-	margin-right: 0.5rem;
 	display: inline-block;
 	color: var(--global--color-foreground);
-	font-size: calc(0.75 * var(--global--font-size-base));
 }
 
 .entry-content .more-link:hover {
@@ -110,6 +108,11 @@ Tags: one-column, flexible-header, accessibility-ready, custom-colors, custom-me
 	transform: rotate(90deg);
 }
 
+.entry-content .excerpt-more-link .more-link {
+	font-size: calc(0.75 * var(--global--font-size-base));
+	margin-right: var(--global--spacing-horizontal);
+}
+
 .has-link-color a, a {
 	border-bottom: 1px solid transparent;
 	transition: all 0.1s ease;

+ 5 - 2
spearhead/style.css

@@ -86,10 +86,8 @@ Tags: one-column, flexible-header, accessibility-ready, custom-colors, custom-me
 
 .entry-content .more-link {
 	margin-top: 0;
-	margin-left: 0.5rem;
 	display: inline-block;
 	color: var(--global--color-foreground);
-	font-size: calc(0.75 * var(--global--font-size-base));
 }
 
 .entry-content .more-link:hover {
@@ -110,6 +108,11 @@ Tags: one-column, flexible-header, accessibility-ready, custom-colors, custom-me
 	transform: rotate(-90deg);
 }
 
+.entry-content .excerpt-more-link .more-link {
+	font-size: calc(0.75 * var(--global--font-size-base));
+	margin-left: var(--global--spacing-horizontal);
+}
+
 .has-link-color a, a {
 	border-bottom: 1px solid transparent;
 	transition: all 0.1s ease;

文件差异内容过多而无法显示
+ 0 - 0
spearhead/style.css.map


部分文件因为文件数量过多而无法显示