Skip to content

Commit

Permalink
Adds post and page navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer committed Jul 8, 2016
1 parent 90bdb60 commit 8dd8d74
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 9 deletions.
4 changes: 4 additions & 0 deletions components/content-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@

<div class="entry-content">
<?php
$text = get_the_content();

nc_template_content_navigation( $text );

the_content();

wp_link_pages( array(
Expand Down
2 changes: 1 addition & 1 deletion editor-style.css

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
<?php endif; ?>
</div>
<div class="footer-info">
<p>&#xa9; <?php bloginfo( 'name' ); ?>. <?php echo esc_html__( 'All rights reserved.', 'nc-template' ); ?>
<?php printf( esc_html__( 'Website by %s.', 'nc-template' ), '<a href="http://connorbaer.io/" rel="designer" target="_blank">Connor B&#228;r</a>' ); ?>
</p>
<p>&#xa9; <?php bloginfo( 'name' ); ?>. <?php echo esc_html__( 'All rights reserved.', 'nc-template' ); ?> Made by <a href="http://connorbaer.io/" rel="designer" target="_blank">Connor B&#228;r</a>.</p>
</div>

</footer>
Expand Down
3 changes: 1 addition & 2 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ function nc_template_setup() {
'header-text' => array( 'site-title' ),
) );

// This theme uses wp_nav_menu() in one location.
// This theme uses wp_nav_menu() in two locations.
register_nav_menus( array(
'header' => esc_html__( 'Header', 'nc-template' ),
'social' => __( 'Social', 'nc-template' ),
'footer' => __( 'Footer', 'nc-template' ),
) );

/*
Expand Down
85 changes: 85 additions & 0 deletions inc/extras.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,88 @@ function nc_template_excerpt_length( $length ) {
return 32;
}
add_filter( 'excerpt_length', 'nc_template_excerpt_length', 999 );

/**
* Filter the excerpt "read more" string.
*
* @param string $more "Read more" excerpt string.
* @return string (Maybe) modified "read more" excerpt string.
*/
function nc_template_excerpt_more( $more ) {
return '...';
}
add_filter( 'excerpt_more', 'nc_template_excerpt_more' );

/**
* Filter the content to remove p tags around images.
*
* @param html $content The post/page content as html.
* @return html Post/page content modified to remove p tags around images.
*/
// function nc_template_content_images( $content ){
// return preg_replace( '/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content );
// }


/**
* Wrap the inserted image html with <figure>
* if the theme supports html5 and the current image has no caption:
*
* @param html $content The post/page content as html.
* @return html Post/page content modified to wrap images in figure tags.
*/
/* function nc_template_content_images ( $content )
{
$content = preg_replace(
'/<p>\\s*?(<a rel=\"attachment.*?><img.*?><\\/a>|<img.*?>)?\\s*<\\/p>/s',
'<figure>$1</figure>',
$content
);
return $content;
} */


function nc_template_content_images ( $content ) {
$dom = new DOMDocument();
$dom -> loadHTML( $content );
$nodes = $dom->getElementsByTagName( 'img' );

$items = array();
foreach ( $nodes as $node ) {
$parent = $node->parentNode;
if ( $parent -> tagName == 'p' ) {
$class = $node -> getAttribute( 'class' );
}
}
}
// add_filter( 'the_content', 'nc_template_content_images', 99 );


// $dom = new DOMDocument();
// $dom -> loadHTML( $content );
// $nodes = $dom->getElementsByTagName( 'img' );
// $items = array();
// foreach ( $nodes as $node ) {
// if ( $node -> hasAttribute( 'id' ) == true ) {
// $items[] = $node -> getAttribute( 'id' );
// }
// }
// if ( count( $items ) != 0 ) {
// echo '<nav class="navigation content-navigation">';
// echo '<h6 class="nav-header">Inhalt</h6>';
// echo '<div class="nav-links">';
// foreach ( $items as $item ) {
// echo '<a href="#', $item, '" title="', $item, '" data-scroll>', $item, ' ↓</a>';
// }
// echo '</nav>';
// }


// x. DOMDocument with $content
// x. get all img nodes
// x. Get all parent node tag names
// x. for all elements where the parent node is a p element:
// x. get the img class attribute
// b. remove parent node
// c. output new node with figure (including class) and img tag
// 5. return $content
66 changes: 66 additions & 0 deletions inc/template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,72 @@ function nc_template_custom_logo() {
}
endif;

if ( ! function_exists( 'get_prev_next' ) ) :
/**
* Prints HTML with links to previous and next pages for the current page.
*/
function get_prev_next() {
$test = wp_get_nav_menu_items( 'header' );

$pagelist = get_pages( array(
'sort_column' => 'menu_order',
'sort_order' => 'asc' ) );
$pages = array();
foreach ( $pagelist as $page ) {
$pages[] += $page->ID;
}

$current = array_search( get_the_ID(), $pages );
$prev_id = $pages[ $current - 1 ];
$next_id = $pages[ $current + 1 ];

echo '<nav class="navigation post-navigation">';
echo '<h2 class="screen-reader-text">Beitragsnavigation</h2>';
echo '<div class="nav-links">';
if ( ! empty( $prev_id ) ) {
echo '<div class="nav-previous">';
echo '<a href="', get_permalink( $prev_id ), '" title="', get_the_title( $prev_id ), '">← ', get_the_title( $prev_id ), '</a>';
echo '</div>';
}
if ( ! empty( $next_id ) ) {
echo '<div class="nav-next">';
echo '<a href="', get_permalink( $next_id ), '" title="', get_the_title( $next_id ), '">', get_the_title( $next_id ), ' →</a>';
echo '</div>';
}
echo '</div>';
echo '</nav>';
}
endif;

if ( ! function_exists( 'nc_template_content_navigation' ) ) :
/**
* Adds anchor tag button to TinyMCE editor on the WordPress backend.
*
* @param string $text The page content to be parsed.
*/
function nc_template_content_navigation( $text ) {

$dom = new DOMDocument();
$dom -> loadHTML( $text );
$nodes = $dom->getElementsByTagName( 'a' );
$items = array();
foreach ( $nodes as $node ) {
if ( $node -> hasAttribute( 'id' ) == true ) {
$items[] = $node -> getAttribute( 'id' );
}
}
if ( count( $items ) != 0 ) {
echo '<nav class="navigation content-navigation">';
echo '<h6 class="nav-header">Inhalt</h6>';
echo '<div class="nav-links">';
foreach ( $items as $item ) {
echo '<a href="#', $item, '" title="', $item, '" data-scroll>', $item, ' ↓</a>';
}
echo '</nav>';
}
}
endif;

if ( ! function_exists( 'nc_template_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
Expand Down
2 changes: 1 addition & 1 deletion js/scripts.js
100644 → 100755

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions page.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

get_template_part( 'components/content', 'page' );

get_prev_next();

// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
Expand Down
6 changes: 5 additions & 1 deletion single.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

get_template_part( 'components/content', get_post_format() );

the_post_navigation();
the_post_navigation( array(
'in_same_term' => true,
'prev_text' => '← %title',
'next_text' => '%title →',
));

// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
Expand Down
2 changes: 1 addition & 1 deletion style.css

Large diffs are not rendered by default.

0 comments on commit 8dd8d74

Please sign in to comment.