这对我来说是非常难的代码。 我想创建一个自定义帖子类型的年份存档页面。 我的自定义帖子类型是带有文章的杂志。 1年内有6本杂志。每本杂志都有一张图片。
这是我的年代循环代码:
<?php
$my_archives=wp_get_archives(array(
'post_type'=>'issue_number',
'type'=>'yearly',
'format' => 'custom',
'before' => '
<h3 class="entry-title mh-loop-title archivio-anno-list">Table of contents<br>
',
'after' => '
<br></h3>',
'show_post_count'=>true,
'limit'=>20,
));
print_r($my_archives);
?>
我也希望看到这张图片中的杂志图像:
怎么办?给我一个解决方案!
答案 0 :(得分:0)
创建分类文件,例如“taxonomy-yourtaxonomyslug.php” 然后使用下面的代码进行分类/类别。
<?php
$issue_number_type = 'issue_number';
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$issue_number_args=array(
'type' => $issue_number_type,
'post_status' => 'publish',
'posts_per_page' => 20,
'paged' => $paged,
'caller_get_posts' => -1,
'type'=>'yearly',
'format' => 'custom',
'show_post_count'=>true,
'limit'=>20
);
$issue_number_my_query = null;
$issue_number_my_query = new WP_Query($issue_number_args);
if( $issue_number_my_query->have_posts() )
{
while ($issue_number_my_query->have_posts()) : $issue_number_my_query->the_post();
$issue_number_description = get_the_excerpt($post->ID);
the_title( '<h1>', '</h1>' );
if ( has_post_thumbnail() ) {
//get_the_post_thumbnail( $post->ID, array( 100, 100) );
echo get_the_post_thumbnail($post->ID,"thumbnail"); //thumbnail,medium,large,full,array(100,100)
}
echo $issue_number_description;
echo '<a href="<?php echo get_permalink(); ?>">Read More...</a>';
endwhile;
}
wp_reset_query($issue_number_my_query);
?>
帖子类型:issue_number
if strings.Contains(msg, "Log-In") {
cmd1 = exec.Command("echo", "Please log in")
} else {
if strings.Contains(msg, "SignUp") {
cmd1 = exec.Command("echo", "Please SignUp")
}
}
答案 1 :(得分:0)
答案 2 :(得分:0)
分辨
我解决了这个问题,从year到issue_number添加了一个名为ANNO的新自定义帖子类型和一个名为anno_issue的关系字段。 代码是用于查询的代码:
<?php
// args
$args = array(
‘numberposts’ => -1,
‘post_type’ => ‘anno’,
‘posts_per_page’ => 100,
);
// query
$the_query = new WP_Query( $args );
?>
<?php while( $the_query->have_posts() ) : $the_query-
>the_post();
mh_before_page_content();
mh_magazine_page_title();?>
<?php
/*
* Query posts for a relationship value.
* This method uses the meta_query LIKE to match the string “123”
to the database value a:1:{i:0;s:3:”123″;} (serialized array)
*/
$posts = get_posts(array(
‘post_type’ => ‘issue_number’, //nome post type da dove recupero le
info
‘posts_per_page’ => -1,
‘meta_query’ => array(
array(
‘key’ => ‘anno_issue’, // nome custom field all’interno di post che mi da
l’info
‘value’ => ‘”‘ . get_the_ID() . ‘”‘, // matches exaclty “123”, not just
123. This prevents a match for “1234”
‘compare’ => ‘LIKE’
)
)
));
?>
<?php /*ciclo stampa articoli */ ?>
<?php if( $posts ): ?>
<?php foreach( $posts as $post ): ?>
<?php /*layout 1 del tema per articoli */ ?>
<article >
—HTML CODE DISPLAYNG YOUR LOOP—
</article>
<?php /*fine layout 1 */ ?>
<?php endforeach; ?>
<?php endif; ?>
<?php /*fine ciclo stampa articoli */ ?>
<?php endwhile; // end of the loop. ?>