无法在我的页面中显示值...... ACF

时间:2014-11-13 21:26:45

标签: wordpress advanced-custom-fields

嗨,大家好,我的名字是Fotis,我是一名初级网络开发者。

我需要您帮助的原因是因为我正在尝试创建此图库http://www.elliotcondon.com/creating-an-image-gallery-with-advanced-custom-fields/,而我正在使用自定义字段和添加转发器。

但我在浏览器和主页上看不到任何内容。为什么会这样?我做错了什么?

请任何知道帮助我的人

感谢您阅读我的要求! 这是我的index.php代码

  <?php


get_header(); ?>


<div id="content">
<div id="main">







    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
        <?php the_content(); ?>
    <?php endwhile; else: endif; ?>

    <?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    <p><?php the_content(); ?>
    <?php endwhile; else: endif; ?>



<!-- Slider -->
<?php if(get_field('images')): ?>
    <div id="slider">
        <?php while(the_repeater_field('images')): ?>
            <?php $image = wp_get_attachment_image_src(get_sub_field('image'), 'full'); ?>
            <?php $thumb = wp_get_attachment_image_src(get_sub_field('image'), 'thumbnail'); ?>
            <img src="<?php echo $image[0]; ?>" alt="<?php  the_sub_field('title');?>" rel="<?php echo $thumb[0]; ?>" />
        <?php endwhile; ?>
    </div>
    <?php endif; ?>
</div>
</div>

1 个答案:

答案 0 :(得分:0)

通过制作一个首页.php解决了这个问题,其中包含了所有索引.php代码。然后在设置的首页中设置了您创建的主页,并将空白博客页面发布到页面。如此简单,你可以解决问题。这是我做的frontpage.php,我解决了我的问题。

<?php
/**
 * Template Name: front-page.php Template
 */

get_header(); ?>

<?php
$args = array( 'posts_per_page' => 10 );
$lastposts = get_posts( $args );
foreach ( $lastposts as $post ) :
  setup_postdata( $post ); ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_content(); ?>
<?php endforeach; 


//for each category, show 3 posts
$cat_args=array(
  'orderby' => 'name',
  'order' => 'ASC'
   );
$categories=get_categories($cat_args);
  foreach($categories as $category) {
    $args=array(
      'showposts' => 3,
      'category__in' => array($category->term_id),
      'caller_get_posts'=>1
    );
    $posts=get_posts($args);
      if ($posts) {
        echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
        foreach($posts as $post) {
          setup_postdata($post); ?>
          <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
          <?php
        } // foreach($posts
      } // if ($posts
    } // foreach($categories


wp_reset_postdata();  ?>
<?php global $post;
$pid = $post->ID;
get_field('slide',$pid);
?>
<!-- Slider -->
<div class="flexslider">
    <ul class="slides">
    <?php
    $rows = get_field('slide');
    if($rows) {

        foreach($rows as $row) {
            // retrieve size 'large' for background image
            $bgimg = $row['bg_image']['sizes']['large'];
            $output = "<li style='background-image: url(". $bgimg .");'>\n";
            $output .= "  <div class='slide-text'>\n";
            $output .= "  <h2>". $row['slide_heading'] ."</h2>\n";
            $output .= "  " . $row['slide_text'];
            $output .= "  </div>\n";
            $output .= "</li>\r\n\n";
            $output .= "  " . $row['slide_link']; 

            echo $output;
        }    
    }
    ?> 


    </ul>
</div> 



</div>
</div>

<?php get_footer(); ?

这是functions.php文件,您可以在其中为每个页面设置模板。

<?php 
/***********************************************************************************************/
/* Define Constants */
/***********************************************************************************************/
define('THEMEROOT', get_stylesheet_directory_uri());
define('IMAGES', THEMEROOT.'/images');

function register_my_menu() {
  register_nav_menu('header-menu',__( 'Header Menu' ));
}
add_action( 'init', 'register_my_menu' );



// Add support for featured images
add_theme_support( 'post-thumbnails' );

function get_future_posts($post_type, $require_featured, $number_posts=1) {
    $today = current_time( 'timestamp' );
    $posts = get_posts(array(
        'posts_per_page'    => $number_posts,
        'post_type'         => $post_type,
        'meta_key'          => 'date_time',
        'meta_compare'      => '>=',
        'meta_value'        => $today,
        'orderby'           => 'meta_value_num',
        'order'             => 'ASC',
        'meta_query' => array(
            array(
                'key' => 'featured_event',
                'value' => $require_featured
            )
        )
    ));
    return $posts;
}
add_action('init', 'my_custom_init');

function my_custom_init() {
    // remember add first parameter post type as 'page'
    add_post_type_support( 'page', 'page-attributes' );
}

 // Load our scripts
if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
   wp_deregister_script('jquery');
   wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
   wp_enqueue_script('jquery');
}
?>

当然还有header.php

<head>
  <!-- Page Meta -->
  <meta http-equiv="content-type" content="<?php bloginfo('html_type') ?>; charset=<?php bloginfo('charset') ?>" />
  <title><?php wp_title( '-', true, 'right' ); echo esc_html( get_bloginfo('name'), 1 ); ?></title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" type="text/css" media="screen" href="<?php bloginfo('stylesheet_url') ?>" />
   <link rel="stylesheet" type="text/css" media="screen" href="<?php bloginfo('stylesheet_url') ?>/css/flexislider.css" />
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
  <script src="<?php bloginfo('template_url'); ?>/js/jquery.flexislider.js"type="text/javascript"></script>
<script>
(function($) {
    $(window).load(function() {
        $('.flexslider').flexslider({
                animation: 'slide',
            controlsContainer: '.flex-container'
        });
    });
})(jQuery)
</script>

  <?php wp_head(); ?>
</head>



<nav>


<div class="container">
                <ul class="nav-list">

                    <li><a href="<?php bloginfo('url'); ?>/Home" class="event-link">Αρχική</a></li>
                    <li><a href="<?php bloginfo('url'); ?>/Useful" class="event-link">Χρήσιμα</a></li>
                    <li><a href="<?php bloginfo('url'); ?>/Social" class="event-link">Κοινωνικά</a></li>
                    <li><a href="<?php bloginfo('url'); ?>/Other things" class="event-link">Διάφορα</a></li>
                    <li><a href="<?php bloginfo('url'); ?>/Sports" class="event-link">Αθλητικά</a></li>
                    <li><a href="<?php bloginfo('url'); ?>/News" class="event-link">Ειδήσεις</a></li>
                    <li><a href="<?php bloginfo('url'); ?>/Events" class="event-link">Εκδηλώσεις</a></li>

                </ul>
</div>
        </nav>




    </header>

最后这是为了开发带有ACF中继器的flexi滑块的代码。

享受!