summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax2019-02-17 17:20:43 +0100
committerMax2019-02-17 17:20:43 +0100
commitc4b2eb526c5733cc32b0550eb76fd072531e223c (patch)
tree9e3355627357ca392ae26574c81181bf33bd028e
parent43a8c0fe50529a6b4161d12f087925c06ce37574 (diff)
downloadfuselkoenig_de-c4b2eb526c5733cc32b0550eb76fd072531e223c.tar.gz
Creates custom post type and custom taxonomy and renders them correctly.
-rw-r--r--angebote/angebote.php2
-rw-r--r--angebote/inc/functions.php82
-rw-r--r--angebote/inc/template.php107
-rw-r--r--functions.php16
-rw-r--r--loop-templates/content-angebote.php51
-rw-r--r--loop-templates/content-angebotenotitle.php15
-rw-r--r--sass/theme/_offer.scss14
-rw-r--r--search.php6
-rw-r--r--single-angebote.php53
-rw-r--r--taxonomy-type.php88
10 files changed, 427 insertions, 7 deletions
diff --git a/angebote/angebote.php b/angebote/angebote.php
index 5409b55..06998f3 100644
--- a/angebote/angebote.php
+++ b/angebote/angebote.php
@@ -7,8 +7,6 @@ if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
-require_once __DIR__ . '/inc/functions.php';
-
get_header();
$container = get_theme_mod( 'understrap_container_type' );
diff --git a/angebote/inc/functions.php b/angebote/inc/functions.php
index de9a03d..42dab03 100644
--- a/angebote/inc/functions.php
+++ b/angebote/inc/functions.php
@@ -41,3 +41,85 @@ function create_offer_link() {
return "https://angebote.fuselkoenig.de/wp/whisky?page=" . $page . "&_sort=" . $sort . "&_order=" . $order;
}
+
+function create_offer_post_type() {
+ register_post_type(
+ 'angebote',
+ array(
+ 'labels' => array(
+ 'name' => __('Angebote'),
+ 'singular_name' => __('Angebot')
+ ),
+ 'public' => true,
+ 'has_archive' => true,
+ 'hierarchical' => false,
+ 'taxonomies' => array( 'type' ),
+ 'supports' => array(
+ 'title',
+ 'editor',
+ 'thumbnail',
+ 'comments'
+ ),
+ 'rewrite' => array(
+ #'slug' => 'aangebote/%custom-taxonomy-name%',
+ 'slug' => 'angebote/%type%',
+ 'with_front' => true,
+ )
+ )
+ );
+ // create a new taxonomy
+ register_taxonomy(
+ 'type',
+ 'angebote',
+ array(
+ 'label' => __( 'Type' ),
+ 'hierarchical' => false,
+ 'rewrite' => array(
+ 'slug' => 'angebote',
+ 'with_front' => true
+ )
+ )
+ );
+}
+
+function generate_taxonomy_rewrite_rules( $wp_rewrite ) {
+ $rules = array();
+ $post_types = get_post_types( array( 'name' => 'angebote', 'public' => true, '_builtin' => false ), 'objects' );
+ $taxonomies = get_taxonomies( array( 'name' => 'type', 'public' => true, '_builtin' => false ), 'objects' );
+
+ foreach ( $post_types as $post_type ) {
+ $post_type_name = $post_type->name; // 'developer'
+ $post_type_slug = $post_type->rewrite['slug']; // 'developers'
+
+ foreach ( $taxonomies as $taxonomy ) {
+ if ( $taxonomy->object_type[0] == $post_type_name ) {
+ $terms = get_categories( array( 'type' => $post_type_name, 'taxonomy' => $taxonomy->name, 'hide_empty' => 0 ) );
+ foreach ( $terms as $term ) {
+ $rules[$post_type_slug . '/' . $term->slug . '/?$'] = 'index.php?' . $term->taxonomy . '=' . $term->slug;
+ }
+ }
+ }
+ }
+ $wp_rewrite->rules = $rules + $wp_rewrite->rules;
+}
+
+function post_link_includes_taxonomy( $post_link, $id = 0 ){
+ $post = get_post($id);
+ if ( is_object( $post ) ){
+ $terms = wp_get_object_terms( $post->ID, 'type' );
+ file_put_contents("/tmp/wp.debug", json_encode($terms));
+ if( $terms ){
+ # file_put_contents("/tmp/wp.debug", str_replace( 'angebote/' , 'angebote/' . $terms[0]->slug , $post_link ));
+ # return $post_link;
+ # return str_replace( '/angebote/' , '/angebote/' . $terms[0]->slug . '/', $post_link );
+ return str_replace( '%type%' , $terms[0]->slug, $post_link );
+ } else {
+ return str_replace( '%type%' , '', $post_link );
+ }
+ }
+ return $post_link;
+}
+
+add_action('init', 'create_offer_post_type');
+add_action('generate_rewrite_rules', 'generate_taxonomy_rewrite_rules');
+add_filter( 'post_type_link', 'post_link_includes_taxonomy', 1, 3 );
diff --git a/angebote/inc/template.php b/angebote/inc/template.php
new file mode 100644
index 0000000..d0bbcc3
--- /dev/null
+++ b/angebote/inc/template.php
@@ -0,0 +1,107 @@
+<?php
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit; // Exit if accessed directly.
+}
+
+function render_offer_template( $atts ) {
+ global $post;
+ $categories = get_the_terms( $post, 'type' );
+ $spirit_type = 'Verschiedenes';
+
+ if ( isset($categories[0]) ) {
+ $spirit_type = $categories[0]->name;
+ }
+
+ $include_post_link = false;
+ if ( is_archive() || is_search() ) {
+ $include_post_link = true;
+ }
+ if ( is_search() ) {
+ $css_border_left = " card-border-left";
+ } else {
+ $css_border_left = "";
+ }
+
+ $offer = shortcode_atts( array(
+ 'spirit_type' => $spirit_type,
+ 'shop' => '',
+ 'procent' => '',
+ 'img_url' => '',
+ 'name' => '',
+ 'discounted_price' => '',
+ 'original_price' => '',
+ 'shipping_costs' => 'Versand ist nie kostenlos',
+ 'abv' => '',
+ 'volume' => '',
+ 'base_price' => '',
+ 'url' => '',
+ 'created_at' => '',
+ 'include_post_link' => $include_post_link,
+ ), $atts
+ );
+?>
+ <div class="card <?php echo $css_border_left; ?>">
+ <div class="row ">
+ <div class="col-md-4">
+ <div class="card-header-dp-none">
+ <p><strong>
+ <span style="visibility: hidden;">
+ <?php echo $offer['spirit_type']; ?><span class="float-right"><?php echo $offer['shop']; ?></span>
+ </span>
+ </strong></p>
+ </div>
+ <div class="card-img-overlay card-img-overlay-badge" >
+ <p class="card-text float-right rounded off-badge" ><?php echo $offer['procent']; ?> %</p>
+ </div>
+ <img src="<?php echo $offer['img_url']; ?>" class="w-100 card-img img-fluid" >
+ </div>
+ <div class="col-md-8 px-10">
+ <div class="card-header">
+ <p><strong>
+ <?php echo $offer['spirit_type']; ?><span class="float-right"><?php echo $offer['shop']; ?></span>
+ </strong></p>
+ </div>
+ <div class="card-block card-body px-3">
+<?php
+ if ( $offer['include_post_link'] ) {
+?>
+ <h3 class="card-title"><a class="offer-title" href="<?php echo get_post_permalink( $post ); ?>" title="<?php echo $offer['name']; ?>"><?php echo $offer['name']; ?> <i class="material-icons icon-small" sstyle="font-size: 50%;">
+launch
+</i></a></h3>
+<?php
+ } else {
+?>
+ <h3 class="card-title"><?php echo $offer['name']; ?></h3>
+<?php
+ }
+?>
+ <div class="row">
+ <p class="card-text col-md-6">
+ Preis: <?php echo $offer['discounted_price']; ?> €
+ <br>
+ Alter Preis: <?php echo $offer['original_price']; ?> €
+ <br>
+ Versand: <?php echo $offer['shipping_costs']; ?> €
+ </p>
+ <p class="card-text col-md-6">
+ Alkohol: <?php echo $offer['abv']; ?> %
+ <br>
+ Volumen: <?php echo $offer['volume']; ?> Liter
+ <br>
+ <?php echo $offer['base_price']; ?> € / Liter
+ </p>
+ </div>
+ </div>
+ <div class="card-footer">
+ <a href="<?php echo $offer['url']; ?>" class="btn btn-primary">Zum Shop</a>
+ <!--p class="float-right">Preis vom <?php echo $offer['created_at']; ?></p-->
+ </div>
+ </div>
+
+ </div>
+ </div>
+<?php
+}
+
+add_shortcode('angebot', 'render_offer_template');
diff --git a/functions.php b/functions.php
index 7553f43..8321d02 100644
--- a/functions.php
+++ b/functions.php
@@ -92,10 +92,12 @@ require get_template_directory() . '/taxonomy.php';
* Removes "Tag:" and "Category:" from archive pages.
*/
add_filter('get_the_archive_title', function ($title) {
- if ( is_category() ) {
- $title = single_cat_title( '', false );
- } elseif ( is_tag() ) {
- $title = single_tag_title( '', false );
+
+ if ( is_tax('type') ) {
+ $title = single_term_title( '', false );
+ $title = 'Aktuelle ' . $title . "-Angebote";
+ } else {
+ $title = single_term_title( '', false );
}
return $title;
});
@@ -255,6 +257,12 @@ if ( ! function_exists("get_my_clean_title")) {
}
/**
+ * Support for special offer pages.
+ */
+require_once __DIR__ . '/angebote/inc/functions.php';
+require_once __DIR__ . '/angebote/inc/template.php';
+
+/**
* Removes emoji support.
*/
/*
diff --git a/loop-templates/content-angebote.php b/loop-templates/content-angebote.php
new file mode 100644
index 0000000..76c6bbd
--- /dev/null
+++ b/loop-templates/content-angebote.php
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Single post partial template.
+ *
+ * @package understrap
+ */
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit; // Exit if accessed directly.
+}
+?>
+
+<article <?php post_class(array('')); ?> id="post-<?php the_ID(); ?>">
+
+ <header class="entry-header">
+
+ <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
+
+ <?php echo get_the_post_thumbnail( $post->ID, 'large', array( 'class' => 'mx-auto d-block border rounded' ) ); ?>
+
+ <div class="entry-meta entry-meta-single text-muted">
+
+ <?php understrap_posted_on(); ?>
+
+ </div><!-- .entry-meta -->
+ <footer class="entry-footer">
+
+ <div class="row">
+ <?php understrap_entry_footer(); ?>
+ </div>
+
+ </footer><!-- .entry-footer -->
+
+ </header><!-- .entry-header -->
+<hr>
+
+ <div class="entry-content">
+
+ <?php the_content(); ?>
+
+ <?php
+ wp_link_pages( array(
+ 'before' => '<div class="page-links">' . __( 'Pages:', 'understrap' ),
+ 'after' => '</div>',
+ ) );
+ ?>
+
+ </div><!-- .entry-content -->
+
+
+</article><!-- #post-## -->
diff --git a/loop-templates/content-angebotenotitle.php b/loop-templates/content-angebotenotitle.php
new file mode 100644
index 0000000..11f8b0e
--- /dev/null
+++ b/loop-templates/content-angebotenotitle.php
@@ -0,0 +1,15 @@
+<?php
+/**
+ * Single post partial template.
+ *
+ * @package understrap
+ */
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit; // Exit if accessed directly.
+}
+?>
+
+<div <?php post_class(array('offer-page')); ?> id="post-<?php the_ID(); ?>">
+ <?php do_shortcode( the_content() ); ?>
+</div>
diff --git a/sass/theme/_offer.scss b/sass/theme/_offer.scss
index 14a9510..6f94d2d 100644
--- a/sass/theme/_offer.scss
+++ b/sass/theme/_offer.scss
@@ -73,3 +73,17 @@
.page-link {
font-size: 18px;
}
+
+.offer-title {
+ color: rgba(0, 0, 0, 0.87);
+ text-decoration: underline;
+}
+
+.icon-small {
+ font-size: inherit !important;
+}
+
+/*.offer-page .card {*/
+.card-border-left {
+ border-left: 5px solid theme-color(primary);
+}
diff --git a/search.php b/search.php
index 2c59501..1495828 100644
--- a/search.php
+++ b/search.php
@@ -51,7 +51,11 @@ $container = get_theme_mod( 'understrap_container_type' );
* If you want to overload this in a child theme then include a file
* called content-search.php and that will be used instead.
*/
- get_template_part( 'loop-templates/content', 'search' );
+ if ( "angebote" == get_post_type() ) {
+ get_template_part( 'loop-templates/content', 'angebotenotitle' );
+ } else {
+ get_template_part( 'loop-templates/content', 'search' );
+ }
?>
<?php endwhile; ?>
diff --git a/single-angebote.php b/single-angebote.php
new file mode 100644
index 0000000..1182b5d
--- /dev/null
+++ b/single-angebote.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * The template for displaying all single posts.
+ *
+ * @package understrap
+ */
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit; // Exit if accessed directly.
+}
+
+get_header();
+$container = get_theme_mod( 'understrap_container_type' );
+?>
+
+<div class="wrapper single-angebote" id="single-wrapper">
+
+ <div class="<?php echo esc_attr( $container ); ?>" id="content" tabindex="-1">
+
+ <div class="row">
+
+ <!-- Do the left sidebar check -->
+ <?php get_template_part( 'global-templates/left-sidebar-check' ); ?>
+
+ <main class="site-main article-shadow-sm" id="main">
+
+ <?php while ( have_posts() ) : the_post(); ?>
+
+ <?php get_template_part( 'loop-templates/content', 'angebote' ); ?>
+
+ <?php understrap_post_nav(); ?>
+
+ <?php
+ // If comments are open or we have at least one comment, load up the comment template.
+ if ( comments_open() || get_comments_number() ) :
+ comments_template();
+ endif;
+ ?>
+
+ <?php endwhile; // end of the loop. ?>
+
+ </main><!-- #main -->
+
+ <!-- Do the right sidebar check -->
+ <?php get_template_part( 'global-templates/right-sidebar-check' ); ?>
+
+ </div><!-- .row -->
+
+</div><!-- Container end -->
+
+</div><!-- Wrapper end -->
+
+<?php get_footer(); ?>
diff --git a/taxonomy-type.php b/taxonomy-type.php
new file mode 100644
index 0000000..0d83afd
--- /dev/null
+++ b/taxonomy-type.php
@@ -0,0 +1,88 @@
+<?php
+/**
+ * The template for displaying archive pages.
+ *
+ * Learn more: http://codex.wordpress.org/Template_Hierarchy
+ *
+ * @package understrap
+ */
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit; // Exit if accessed directly.
+}
+
+get_header();
+?>
+
+<?php
+$container = get_theme_mod( 'understrap_container_type' );
+?>
+
+<div class="wrapper angebote-wrapper" id="archive-wrapper">
+
+ <div class="<?php echo esc_attr( $container ); ?>" id="content" tabindex="-1">
+
+ <div class="row">
+
+ <!-- Do the left sidebar check -->
+ <?php get_template_part( 'global-templates/left-sidebar-check' ); ?>
+
+ <main class="site-main" id="main">
+
+ <?php if ( have_posts() ) : ?>
+
+ <header class="page-header">
+
+ <div class="card taxonomy-card">
+ <div class="card-body">
+ <?php
+ the_archive_title( '<h1 class="card-title page-title">', '</h1>' );
+ the_archive_description( '<div class="card-text taxonomy-description">', '</div>' );
+ ?>
+ </div>
+ </div>
+ <?php
+ #the_archive_title( '<h1 class="page-title taxonomy-title">', '</h1>' );
+ #the_archive_description( '<div class="taxonomy-description">', '</div>' );
+ ?>
+
+ </header><!-- .page-header -->
+
+ <?php /* Start the Loop */ ?>
+ <?php while ( have_posts() ) : the_post(); ?>
+
+ <?php
+
+ /*
+ * Include the Post-Format-specific template for the content.
+ * If you want to override this in a child theme, then include a file
+ * called content-___.php (where ___ is the Post Format name) and that will be used instead.
+ */
+ #get_template_part( 'loop-templates/content', get_post_format() );
+ # Loads specific archive template.
+ get_template_part( 'loop-templates/content', 'angebotenotitle' );
+ ?>
+
+ <?php endwhile; ?>
+
+ <?php else : ?>
+
+ <?php get_template_part( 'loop-templates/content', 'none' ); ?>
+
+ <?php endif; ?>
+
+ </main><!-- #main -->
+
+ <!-- The pagination component -->
+ <?php understrap_pagination(); ?>
+
+ <!-- Do the right sidebar check -->
+ <?php get_template_part( 'global-templates/right-sidebar-check' ); ?>
+
+ </div> <!-- .row -->
+
+</div><!-- Container end -->
+
+</div><!-- Wrapper end -->
+
+<?php get_footer(); ?>