everybody,
I have created a custom_post_type;
function create_post_type_veranstaltungen()
{
register_post_type('veranstaltungen', array(
'label' => __('Veranstaltungen'),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_icon' => 'dashicons-admin-site-alt',
'supports' => array('thumbnail', 'title', 'editor', 'author',
'excerpt', 'comments'),
)
);
}
add_action('init', 'create_post_type_veranstaltungen');
with its own section of taxonomies
function tr_create_my_taxonomy()
{
register_taxonomy(
'veranstaltungen-category',
'veranstaltungen',
array(
'label' => __('Category'),
'rewrite' => array('slug' => 'veranstaltungen-category'),
'hierarchical' => true,
)
);
}
add_action('init', 'tr_create_my_taxonomy');
Then I created 4 post and I implemented the corresponding loop that works
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$custom_args = array(
'post_type' => 'veranstaltungen',
'orderby' => 'date',
'order' => 'DESC',
'paged' => $paged,
'posts_per_page' => '10'
);
$wp_query = new WP_Query($custom_args);
if (have_posts()) :
while (have_posts()) : the_post();
?>
<div class="pagination">
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links(array(
base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages
));
?>
</div>
if income posts_per_page => '-1' works, if I enter posts_per_page => '1' also works, but if I enter posts_per_page => '10' does not show anything at all.
Does anyone have an idea of what may be happening?
Thanks
everybody,
I have created a custom_post_type;
function create_post_type_veranstaltungen()
{
register_post_type('veranstaltungen', array(
'label' => __('Veranstaltungen'),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_icon' => 'dashicons-admin-site-alt',
'supports' => array('thumbnail', 'title', 'editor', 'author',
'excerpt', 'comments'),
)
);
}
add_action('init', 'create_post_type_veranstaltungen');
with its own section of taxonomies
function tr_create_my_taxonomy()
{
register_taxonomy(
'veranstaltungen-category',
'veranstaltungen',
array(
'label' => __('Category'),
'rewrite' => array('slug' => 'veranstaltungen-category'),
'hierarchical' => true,
)
);
}
add_action('init', 'tr_create_my_taxonomy');
Then I created 4 post and I implemented the corresponding loop that works
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$custom_args = array(
'post_type' => 'veranstaltungen',
'orderby' => 'date',
'order' => 'DESC',
'paged' => $paged,
'posts_per_page' => '10'
);
$wp_query = new WP_Query($custom_args);
if (have_posts()) :
while (have_posts()) : the_post();
?>
<div class="pagination">
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links(array(
base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages
));
?>
</div>
if income posts_per_page => '-1' works, if I enter posts_per_page => '1' also works, but if I enter posts_per_page => '10' does not show anything at all.
Does anyone have an idea of what may be happening?
Thanks
Share Improve this question asked Jun 20, 2019 at 10:18 Dario B.Dario B. 15510 bronze badges 1 |3 Answers
Reset to default 0after days of research, I found that the fault was simply in the pagination. By changing the pagination code, I have made it work.
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$custom_args = array(
'post_type' => 'veranstaltungen',
'orderby' => 'date',
'order' => 'DESC',
'paged' => $paged,
'posts_per_page' => '10'
);
$wp_query = new WP_Query($custom_args);
if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<div class="accordion">
<div class="columns is-mobile is-flexend ">
<div class="column is-half">
<div class="columns is-mobile is-vcentered">
<div class="column is-one-fifth">
<i class="angle fa fa-angle-down fa-2x" aria-hidden="true"></i>
</div>
<div class="column is-four-fifths">
<?php
$categories = get_the_terms($custom_args->ID, 'veranstaltungen-category');
$cats = ''; // set empty string as value
foreach ($categories as $i => $category) {
if ($i) echo ', ';
echo '<span>' . $category->name . '</span>';
}
?>
<div class="title">
<?php the_title(); ?>
</div>
</div>
</div>
</div>
<div class="column is-half">
<div class="postdate">
<p><?php the_field('tag') ?></p>
<p><?php the_field('datum') ?></p>
</div>
</div>
</div>
</div>
<div class="thepanel">
<div class="theimage">
<?php the_post_thumbnail(); ?>
</div>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<div class="columns is-mobile">
<div class="column is-3 is-offset-9">
<div class="pagination">
<?php
$nav = get_the_posts_pagination(array(
'mid_size' => 2,
'prev_text' => 'Zurück',
'next_text' => 'Vor',
'screen_reader_text' => 'A'
));
$nav = str_replace('<h2 class="screen-reader-text">A</h2>', '', $nav);
echo $nav;
?>
</div>
</div>
</div>
<?php endif;
wp_reset_query();
?>
Ahora funciona perfectamente. Gracias a todos
you have missed $wp_query like this $wp_query->have_posts() to add in the loop. Please see the code:
$wp_query = new WP_Query($custom_args);
if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post();
Please try below code :
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$custom_args = array(
'post_type' => 'veranstaltungen',
'orderby' => 'date',
'order' => 'DESC',
'paged' => $paged,
'posts_per_page' => '10'
);
$wp_query = new WP_Query($custom_args);
while ( $wp_query->have_posts() ) {
$wp_query->the_post();
echo '<lable>Post Name : ' . get_the_title() .'</lable><br/>';
}
wp_reset_query();
?>
<div class="pagination">
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages
));
?>
</div>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745369018a4624715.html
archive-veranstaltungen.php
? – Jacob Peattie Commented Jun 20, 2019 at 12:18