Skip to content

Commit

Permalink
Bumps version to 1.2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Connor Bär committed Sep 12, 2016
1 parent 21dee2a commit bb045a7
Show file tree
Hide file tree
Showing 20 changed files with 258 additions and 128 deletions.
10 changes: 10 additions & 0 deletions components/content-link.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@
<div class="entry-content">
<?php echo '<p><a href="' . esc_url( get_field( 'link_url' ) ) . '" rel="bookmark" target="_blank">' . esc_html__( 'Continue reading', 'uwc-website' ) . '...</a></p>'; ?>
</div>

<?php if ( $tags = get_the_tags() ) {
echo '<p class="category-tags">';
foreach ( $tags as $tag ) {
$sep = ( end( $tags ) === $tag ) ? '' : ', ';
echo '<a href="' . esc_url( get_term_link( $tag, $tag->taxonomy ) ) . '">#' . esc_html( $tag->name ) . '</a>' . esc_html( $sep );
}
echo '</p>';
} ?>

</article><!-- #post-## -->
15 changes: 5 additions & 10 deletions components/content-none.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
?>

<section class="no-results not-found">
<header class="header-header">
<h1 class="header-title"><?php esc_html_e( 'Nothing Found', 'uwc-website' ); ?></h1>
</header>
<div class="page-content">
<div class="entry-content">
<h1><?php esc_html_e( 'Nothing Found', 'uwc-website' ); ?></h1>
<?php
if ( is_home() && current_user_can( 'publish_posts' ) ) : ?>

Expand All @@ -22,13 +20,10 @@
<?php elseif ( is_search() ) :
get_search_form(); ?>

<p><?php esc_html_e( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'uwc-website' ); ?></p>
<p><?php esc_html_e( 'Sorry, but nothing matched your search terms.', 'uwc-website' ); ?></p>
<?php else : ?>

<p><?php esc_html_e( 'It seems we can&rsquo;t find what you&rsquo;re looking for. Perhaps searching can help.', 'uwc-website' ); ?></p>
<?php
get_search_form();

endif; ?>
<p><?php esc_html_e( 'It seems we can&rsquo;t find what you&rsquo;re looking for.', 'uwc-website' ); ?></p>
<?php endif; ?>
</div>
</section><!-- .no-results -->
17 changes: 9 additions & 8 deletions components/content-section.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
</div>
<?php else : ?>
<nav class="header-navigation">
<ul class="header-links">
<?php wp_list_pages( array(
'child_of' => $post->ID,
'depth' => 1,
'title_li' => '',
'sort_column' => 'menu_order',
) ); ?>
</ul>
<?php if ( has_nav_menu( 'primary' ) ) {
wp_nav_menu( array(
'theme_location' => 'primary',
'sub_menu' => true,
'depth' => '2',
'container' => 'nav',
'fallback_cb' => 'false',
) );
} ?>
</nav>
<?php endif; ?>
</div>
Expand Down
10 changes: 10 additions & 0 deletions components/content-standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@
) );
?>
</div>

<?php if ( $tags = get_the_tags() ) {
echo '<p class="category-tags">';
foreach ( $tags as $tag ) {
$sep = ( end( $tags ) === $tag ) ? '' : ', ';
echo '<a href="' . esc_url( get_term_link( $tag, $tag->taxonomy ) ) . '">#' . esc_html( $tag->name ) . '</a>' . esc_html( $sep );
}
echo '</p>';
} ?>

</article><!-- #post-## -->
14 changes: 13 additions & 1 deletion components/content-video.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<section class="section-video">
<?php the_field( 'video_url' ); ?>
<div class="section-wrapper">
<?php the_field( 'video_url' ); ?>
</div>
</section>

<header class="header -entry -no-featured">
Expand Down Expand Up @@ -45,4 +47,14 @@
) );
?>
</div>

<?php if ( $tags = get_the_tags() ) {
echo '<p class="category-tags">';
foreach ( $tags as $tag ) {
$sep = ( end( $tags ) === $tag ) ? '' : ', ';
echo '<a href="' . esc_url( get_term_link( $tag, $tag->taxonomy ) ) . '">#' . esc_html( $tag->name ) . '</a>' . esc_html( $sep );
}
echo '</p>';
} ?>

</article><!-- #post-## -->
10 changes: 10 additions & 0 deletions components/element-link.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
<header class="header -category">
<?php the_title( '<h2 class="category-title"><a href="' . esc_url( get_field( 'link_url' ) ) . '" rel="bookmark" target="_blank">', '</a></h2>' ); ?>
</header>

<?php if ( $tags = get_the_tags() ) {
echo '<p class="category-tags">';
foreach ( $tags as $tag ) {
$sep = ( end( $tags ) === $tag ) ? '' : ', ';
echo '<a href="' . esc_url( get_term_link( $tag, $tag->taxonomy ) ) . '">#' . esc_html( $tag->name ) . '</a>' . esc_html( $sep );
}
echo '</p>';
} ?>

<p class="category-body"><?php the_excerpt(); ?></p>

<?php echo '<a class="category-link" href="' . esc_url( get_field( 'link_url' ) ) . '" rel="bookmark" target="_blank">' . esc_html__( 'Continue reading', 'uwc-website' ) . '</a>'; ?>
Expand Down
12 changes: 11 additions & 1 deletion components/element-standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@
<div class="category-text">

<?php if ( is_sticky() ) : ?>
<span class="sticky"><?php echo esc_html__( 'Featured', 'uwc-website' ); ?></span>
<span class="featured"><?php echo esc_html__( 'Featured', 'uwc-website' ); ?></span>
<?php endif; ?>

<header class="header -category">
<?php the_title( '<h2 class="category-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' ); ?>
</header>

<?php if ( $tags = get_the_tags() ) {
echo '<p class="category-tags">';
foreach ( $tags as $tag ) {
$sep = ( end( $tags ) === $tag ) ? '' : ', ';
echo '<a href="' . esc_url( get_term_link( $tag, $tag->taxonomy ) ) . '">#' . esc_html( $tag->name ) . '</a>' . esc_html( $sep );
}
echo '</p>';
} ?>

<p class="category-body"><?php the_excerpt(); ?></p>

<?php echo '<a class="category-link" href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . esc_html__( 'Weiter lesen', 'uwc-website' ) . '</a>'; ?>
Expand Down
15 changes: 15 additions & 0 deletions components/element-video.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,24 @@
<a class="category-image" style="background-image: url(<?php the_post_thumbnail_url( 'medium' ); ?>)" href="<?php echo esc_url( get_permalink() ); ?>" rel="bookmark"></a>
<?php endif; ?>
<div class="category-text">

<?php if ( is_sticky() ) : ?>
<span class="featured"><?php echo esc_html__( 'Featured', 'uwc-website' ); ?></span>
<?php endif; ?>

<header class="header -category">
<?php the_title( '<h2 class="category-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' ); ?>
</header>

<?php if ( $tags = get_the_tags() ) {
echo '<p class="category-tags">';
foreach ( $tags as $tag ) {
$sep = ( end( $tags ) === $tag ) ? '' : ', ';
echo '<a href="' . esc_url( get_term_link( $tag, $tag->taxonomy ) ) . '">#' . esc_html( $tag->name ) . '</a>' . esc_html( $sep );
}
echo '</p>';
} ?>

<p class="category-body"><?php the_excerpt(); ?></p>

<?php echo '<a class="category-link" href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . esc_html__( 'Weiter lesen', 'uwc-website' ) . '</a>'; ?>
Expand Down
4 changes: 2 additions & 2 deletions components/navigation-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<div class="navigation-header" role="navigation">
<div class="navigation-search">
<?php get_search_form(); ?>
</div><?php if ( has_nav_menu( 'header' ) ) {
</div><?php if ( has_nav_menu( 'primary' ) ) {
wp_nav_menu( array(
'theme_location' => 'header',
'theme_location' => 'primary',
'depth' => '2',
'container' => 'nav',
'container_class' => 'nav-collapse closed',
Expand Down
3 changes: 1 addition & 2 deletions editor-style.css

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

/**
* UWC Website only works in WordPress 4.4 or later.
* UWC Website has only been tested in WordPress 4.4 and later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.4-alpha', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
Expand Down Expand Up @@ -56,8 +56,8 @@ function uwc_website_setup() {

// This theme uses wp_nav_menu() in two locations.
register_nav_menus( array(
'header' => esc_html( 'Header' ),
'social' => esc_html( 'Social' ),
'primary' => __( 'Primary Menu', 'uwc-website' ),
'social' => __( 'Social Links Menu', 'uwc-website' ),
) );

/*
Expand Down
97 changes: 52 additions & 45 deletions inc/extras.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @param array $args Menu arguments for theme location.
*/
function uwc_website_nav_menu_items( $items, $args ) {
if ( 'header' == $args -> theme_location ) {
if ( 'menu-header' == $args -> menu_class ) {
$addmenu = '<li id="menu-item-search" class="menu-item"><a id="js-searchOpen" href="#"><span class="screen-reader-text">' . __( 'Search', 'uwc-website' ) . '</span></a></li>';
return $items . $addmenu;
} else {
Expand Down Expand Up @@ -66,65 +66,72 @@ function uwc_website_content_images( $content ) {
* Replace spaces with dashes in anchor tags.
*
* @param html $content The post/page content as html.
* @return html Post/page content modified to replace .
* @return html Post/page content modified to urlencode anchor ids.
*/
function uwc_website_content_anchors( $content ) {
$content = preg_replace(
'/<p>\\s*?<a\\s*?id=\"(.*?)\">?\\s*<\\/p>/s',
'Forth-tag',
$content = preg_replace_callback(
'/<a id=\"([^\"]*)\"><\/a>/iU',
function ( $matches ) {
return '<a id="' . urlencode( $matches[1] ) . '"></a>';
},
$content
);
return $content;
}
add_filter( 'the_content', 'uwc_website_content_anchors' );

/**
* Synchronize the page hierarchy when the menu structure is changed.
* From https://www.wp-code.com/wordpress-snippets/synchronize-a-menu-with-your-page-hierarchy/
* Output a submenu with the child pages of the current page.
* From https://stackoverflow.com/questions/18875400/display-current-parent-and-its-sub-menu-only-wordpress
*
* @param integer $menu_id The id of the menu to be kept in sync.
* @param array $menu_data Array with data of the menu to be kept in sync.
* @param array $sorted_menu_items The sorted menu defined in the wp_nav_menu.
* @param array $args The arguments defined in the wp_nav_menu call.
*/
function uwc_website_hierarchy_from_menu( $menu_id, $menu_data = null ) {

$term = get_term_by( 'name', 'Header', 'nav_menu' );
$sync_menu_id = $term->term_id;
function uwc_website_wp_nav_menu_objects_sub_menu( $sorted_menu_items, $args ) {
if ( isset( $args->sub_menu ) ) {
$root_id = 0;
// Find the current menu item.
foreach ( $sorted_menu_items as $menu_item ) {
if ( $menu_item->current ) {
// Set the root id based on whether the current menu item has a parent or not.
$root_id = ( $menu_item->menu_item_parent ) ? $menu_item->menu_item_parent : $menu_item->ID;
break;
}
}

if ( $sync_menu_id != $menu_id ) { // You should update this integer to the id of the menu you want to keep in sync.
return; }
if ( null !== $menu_data ) { // If $menu_data !== null, this means the action was fired in nav-menu.php, BEFORE the menu items have been updated, and we should ignore it.
return; }
$menu_details = get_term_by( 'id', $menu_id, 'nav_menu' );
if ( $items = wp_get_nav_menu_items( $menu_details->term_id ) ) {
// Create an index of menu item IDs, so we can find parents easily.
foreach ( $items as $key => $item ) {
$item_index[ $item->ID ] = $key; }
// Loop through each menu item.
foreach ( $items as $item ) {
// Only proceed if we're dealing with a page.
if ( 'page' == $item->object ) {
// Get the details of the page.
$post = get_post( $item->object_id, ARRAY_A );
if ( 0 != $item->menu_item_parent ) {
// This is not top-level menu items, so we need to find the parent page.
if ( 'page' != $items[ $item_index[ $item->menu_item_parent ] ]->object ) {
// The parent isn't a page. Queue an error message.
global $messages;
$messages[] = '<div id="message" class="error"><p>' . sprintf( __( 'The parent of <strong>%1$1s</strong> is <strong>%2$2s</strong>, which is not a page, which means that this part of the menu cannot sync with your page hierarchy.', 'uwc-website' ), $item->title, $items[ $item_index[ $item->menu_item_parent ] ]->title ) . '</p></div>';
$new_post['post_parent'] = new WP_Error;
} else { // Get the new parent page from the index.
$new_post['post_parent'] = $items[ $item_index[ $item->menu_item_parent ] ]->object_id;
// Find the top level parent.
if ( ! isset( $args->direct_parent ) ) {
$prev_root_id = $root_id;
while ( 0 != $prev_root_id ) {
foreach ( $sorted_menu_items as $menu_item ) {
if ( $menu_item->ID == $prev_root_id ) {
$prev_root_id = $menu_item->menu_item_parent;
// Don't set the root_id to 0 if we've reached the top of the menu.
if ( 0 != $prev_root_id ) { $root_id = $menu_item->menu_item_parent;
}
break;
}
} else { $new_post['post_parent'] = 0; // Top-level menu item, so the new parent page is 0.
} if ( ! is_wp_error( $new_post['post_parent'] ) ) {
$new_post['ID'] = $post['ID'];
$new_post['menu_order'] = $item->menu_order;
if ( $new_post['menu_order'] !== $post['menu_order'] || $new_post['post_parent'] !== $post['post_parent'] ) {
// Only update the page if something has changed.
wp_update_post( $new_post ); }
}
}
}

$menu_item_parents = array();
foreach ( $sorted_menu_items as $key => $item ) {
// Init menu_item_parents.
if ( $item->ID == $root_id ) { $menu_item_parents[] = $item->ID;
}

if ( in_array( $item->menu_item_parent, $menu_item_parents ) ) {
// Part of sub-tree: keep!
$menu_item_parents[] = $item->ID;
} else if ( ! ( isset( $args->show_parent ) && in_array( $item->ID, $menu_item_parents ) ) ) {
// Not part of sub-tree: away with it!
unset( $sorted_menu_items[ $key ] );
}
}
return $sorted_menu_items;
} else {
return $sorted_menu_items;
}
}
add_action( 'wp_update_nav_menu', 'uwc_website_hierarchy_from_menu', 10, 2 );
add_filter( 'wp_nav_menu_objects', 'uwc_website_wp_nav_menu_objects_sub_menu', 10, 2 );
Loading

0 comments on commit bb045a7

Please sign in to comment.