我正在使用Types插件来构建自定义帖子类型和自定义分类,这很好用。现在我正在尝试显示某个帖子的内容以及上传到该帖子的附件(只有一个,不允许多个)但我无法让它工作。这就是我在single-legislacion.php
模板中所做的事情:
<div class="legislacion-col-izq">
<div class="CajaIzq">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<h4><?php the_title(); ?></h4>
<?php endwhile; ?>
<?php endif; ?>
<?php
$args = array(
'order' => 'ASC',
'post_type' => 'attachment',
'post_parent' => the_ID(),
'post_status' => 'inherit',
'numberposts' => 1
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) { ?>
<div class="BaseIco">
<a class="IcoDescargas" href="<?php echo wp_get_attachment_url( $attachment->ID, true ); ?>">
<img src="<?php echo get_template_directory_uri(); ?>/images/ico_descargas.png"><br>
Descargar PDF
</a>
</div>
<?php }
}
?>
<div class="ModSuscrip">
<p class="A">¿Deseas ver comentarios y jurisprudencia sobre esta ley?</p>
<p class="B"><a href="#">Suscríbete a cualquiera de nuestros planes</a> y podrás ver material
complementario, enlaces, y mucho más para enreiquecer tu investigación</p>
</div>
<?php echo do_shortcode( '[toc label="Índice por Títulos"]' ) ?>
</div>
</div>
<div class="legislacion-col-der">
<div class="CajaInfo">
<div class="titulo">¿Estás buscando una palabra o frase en particular?</div>
Recuerda que puedes usar la función de búsqueda de tu navegador (Ctrl + F o Command + F)
</div>
<div class="CajaContenido">
<h1 class="titulo"><?php the_title(); ?></h1>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php $options = get_option( 'responsive_theme_options' ); ?>
<?php if ( $options['breadcrumb'] == 0 ): ?>
<?php echo responsive_breadcrumb_lists(); ?>
<?php endif; ?>
<div id="post-<?php the_ID(); ?>">
<div class="post-entry">
<?php the_content( __( 'Read more ›', 'responsive' ) ); ?>
<?php wp_link_pages( array(
'before' => '<div class="pagination">' . __( 'Pages:',
'responsive' ),
'after' => '</div>'
) ); ?>
</div>
<!-- end of .post-entry -->
<?php if ( comments_open() ) : ?>
<div class="post-data">
<?php the_tags( __( 'Tagged with:', 'responsive' ) . ' ', ', ', '<br />' ); ?>
<?php the_category( __( 'Posted in %s', 'responsive' ) . ', ' ); ?>
</div><!-- end of .post-data -->
<?php endif; ?>
<div class="post-edit"><?php edit_post_link( __( 'Edit', 'responsive' ) ); ?></div>
</div><!-- end of #post-<?php the_ID(); ?> -->
<?php comments_template( '', true ); ?>
<?php endwhile; ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<?php if ( function_exists( 'wp_paginate' ) ) {
wp_paginate();
} ?>
<?php endif; ?>
<?php else : ?>
<h1 class="title-404"><?php _e( '404 — Fancy meeting you here!', 'responsive' ); ?></h1>
<p><?php _e( 'Don't panic, we'll get through this together. Let's explore our options here.',
'responsive' ); ?></p>
<h6><?php printf( __( 'You can return %s or search for the page you were looking for.', 'responsive' ),
sprintf( '<a href="%1$s" title="%2$s">%3$s</a>',
esc_url( get_home_url() ),
esc_attr__( 'Home', 'responsive' ),
esc_attr__( '← Home', 'responsive' )
) );
?></h6>
<?php get_search_form(); ?>
<?php endif; ?>
</div>
</div>
但是我从任何帖子得到了一个附件而不是这个,我怎么知道?由于帖子上的网址是http://project.dev/wp-content/uploads/2014/12/file.pdf
,我在前面http://project.dev/wp-content/uploads/2013/08/SC-1081-30.docx
上显示了此网址,这有什么问题?如何获得该CPT的附件?
答案 0 :(得分:3)