ソースを参照

Added show on homepage option for tdas

Moritz Schmidt 8 年 前
コミット
9ee9a128ed
2 ファイル変更59 行追加4 行削除
  1. 23 4
      functions.php
  2. 36 0
      index.php

+ 23 - 4
functions.php

@@ -11,7 +11,7 @@ register_nav_menu("primary", "Top Menu");
 /** STYLES **/
 
 function ams_enqueue_styles() {
-  wp_enqueue_style('bootstrap', get_template_directory_uri() . '/dist/bootstrap/bootstrap.css', array(), '4.0.0-3', true);
+  wp_enqueue_style('bootstrap', get_template_directory_uri() . '/dist/bootstrap/bootstrap.min.css', array(), '4.0.0-3', true);
   wp_enqueue_style('slick', get_template_directory_uri() . '/dist/slick/slick.css', array(), '1.6.0', true);
   wp_enqueue_style('slick-theme', get_template_directory_uri() . '/dist/slick/slick-theme.css', array("slick"), '1.6.0', true);
   wp_enqueue_style('font-awesome', get_template_directory_uri() . '/dist/font-awesome-4.7.0/css/font-awesome.min.css', array(), '4.7.0', true);
@@ -104,12 +104,21 @@ function ams_post_box_setup() {
 function ams_post_box_add() {
   add_meta_box(
     'ams_post_box',      // Unique ID
-    esc_html__( 'Post type'),    // Title
+    esc_html__('Post type'),    // Title
     'ams_post_box',   // Callback function
     'post',         // Admin page (or post type)
     'side',         // Context
     'default'         // Priority
   );
+
+  add_meta_box(
+    'ams_tda_box',      // Unique ID
+    esc_html__('Aktuell'),    // Title
+    'ams_tda_box',   // Callback function
+    'tdas',         // Admin page (or post type)
+    'side',         // Context
+    'default'         // Priority
+  );
 }
 
 function ams_post_box( $object, $box ) { ?>
@@ -129,12 +138,22 @@ function ams_post_box( $object, $box ) { ?>
   </p><?php
 }
 
+function ams_tda_box( $object, $box ) { ?>
+  <?php wp_nonce_field( basename( __FILE__ ), 'ams_post_box_nonce' ); ?>
+  <p>
+    <label for="ams_show_on_homepage">Auf Startseite anzeigen</label>
+    <input type="checkbox" name="ams_show_on_homepage" id="ams_show_on_homepage" style="float: right;" <?php if(get_post_meta($object->ID, 'ams_show_on_homepage', true)) { echo "checked"; } ?> />
+  </p><?php
+}
+
 function ams_post_box_save( $post_id, $post ) {
+
   $inputs = array(
     "ams_dual_columns_post",
     "ams_tda_gallery",
     "ams_partners",
-    "ams_projects"
+    "ams_projects",
+    "ams_show_on_homepage"
   );
 
   if(!isset( $_POST['ams_post_box_nonce']) || !wp_verify_nonce($_POST['ams_post_box_nonce'], basename(__FILE__))) {
@@ -682,7 +701,7 @@ function hoverboxes_shortcode_func($atts) {
   $output = "";
 
   // images (gallery)
-  $tdaQuery = new WP_Query(array('post_type' => $a['type']));
+  $tdaQuery = new WP_Query(array('post_type' => $a['type'], 'meta_query' => array(array('key' => 'ams_show_on_homepage','compare' => 'NOT EXISTS'))));
   if($tdaQuery->have_posts()) {
     $output .= "<div class=\"col-md-12 tda-gallery clearfix\">" . PHP_EOL;
       $output .= "<div class=\"row\">" . PHP_EOL;

+ 36 - 0
index.php

@@ -5,6 +5,42 @@
     <div class="posts-wrapper"><?php
 
     if(is_home()) {
+      // current news
+      $args = array(
+      	'orderby'  => 'title',
+      	'order'    => 'DESC',
+        'post_type' => 'tdas',
+        'meta_key' => 'ams_show_on_homepage',
+        'meta_value' => '1' // true
+      );
+      $query = new WP_Query( $args );
+      if($query->have_posts()) {
+        while($query->have_posts()) {
+          $query->the_post(); ?>
+          <div id="post-<?php the_ID(); ?>" class="content-wrapper">
+            <div class="relcontainer">
+              <div id="post-<?php the_ID(); ?>-jumper" class="jumper"></div>
+            </div>
+            <div class="beam"></div>
+            <div class="container text-muted">
+              <div class="row">
+                <div class="col-md-12">
+                  <?php the_content(); ?>
+                </div>
+              </div>
+            </div>
+            <div class="container b-to-top">
+              <div class="row">
+                <div class="col-xs-12">
+                  <a href="#top" class="scroll-link"><i class="fa fa-chevron-up" aria-hidden="true"></i></a>
+                </div>
+              </div>
+            </div>
+          </div><?php
+        }
+      }
+
+      // main home elements
       $args = array(
         'category_name' => 'Startseite',
         'meta_key'      => 'order',