Archived topic
How to use custom loop
7 replies · Started by Tesco on February 26, 2022
I want to use a custom loop (just like bellow). How can I do that without alter core files?
<ul class="content">
<?php if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post();?>
<li class="myclass" title="<?php the_title_attribute(); ?>" id="post-<?php the_ID(); ?>">
<?php
$time = get_post_meta($post->ID, 'time', true);
$views = get_post_meta($post->ID, 'views', true);?>
<?php if(!empty($time)) : ?>
<?php echo $time; ?><?php if (current_user_can ('manage_options')){ echo ' - ' . $views ; } ?>
<?php else : ?>
<span class="time"><span class="icon-calendar-alt"></span> <?php the_date('Y-m-d'); ?><?php if (current_user_can ('manage_options')){ echo ' - ' . $views ; } ?></span>
<?php endif ?>
<h2 class="title"><?php the_title(); ?></h2>
<?php endwhile; ?>
Hi Tesco,
You can use a child theme for this:
https://docs.generatepress.com/article/using-child-theme/
But how can I add the custom loop?
Do I have to copy and alter any theme template?
Hi there,
where are you wanting to display the Custom Loop ? Is it on its own page, within the content of your post or before/after the post ?
Hi David,
I want to display the Custom Loop on its own page OR within the content (using elements). The main issue here is how can I do it and consider that I must have page navigation also.
Which is the best way to do it?
Thanks
Thats going to require Custom development which is out of our scope i am afraid, if you're interested i found a gist here that would be a sensible way to do it ie. create a Shortcode:
Thanks, David!
I will investigate this option further.
You're welcome