I am having to create a custom loop to display posts published within a specific timeframe on a non-index, static page. I searched through the web for a clue with no luck.
So far, I wrote the following script:
<?php
global $wp_query, $paged;
$paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1;
$args = array(
‘category_name’ => ‘property-detail’,
‘post_type’ => ‘post’,
‘posts_per_page’ => 3,
‘paged’ => $paged
);
$catquery = new WP_Query($args);
while($catquery->have_posts()) : $catquery->the_post();
echo “HTML mark-up”;
?>
<?php endwhile;
echo ‘<nav class=”pagination”>’.pagination_bar( $catquery ).'</nav>’;
wp_reset_postdata();
?>
I want the loop to iterate through the fourth latest post to the sixth latest post only. Could someone please teach me how that can be done?
Thank you in advance,
Ead
]]><?php
get_header(); // Loads the header.php template
if (have_posts()) : ?>
<div id="blog-wrap" class="blog-wrap-wide blog-isotope clearfix">
<?php
// Loop through each post
while (have_posts()) : the_post();
get_template_part( 'content', get_post_format() );
endwhile;
?>
</div><!-- /post -->
<?php
wpex_pagination(); // Paginate your posts
endif;
get_footer(); //get template footer ?>
]]>My search query works without my custom query: Normal while:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
But if I want it to work with my custom query: Custom while:
<?php if ($movies->have_posts()) : ?>
<?php while ($movies->have_posts()) : $movies->the_post(); ?>
It doesn’t search, just shows all posts
]]>With this template I have seen a small gallery is generated, which shows products and by-products, and managing a catalog editor called Goods.
When hag click on a product, its features and shows me some sub-products, however I need to show me all byproducts.
Example = On the Menu: Categorias / Laboratorio sample down product characteristics menu Related Products: only shows me 4 when really I have more than 4 sub-products, and thus equal Laboratorio and Orthodoncia.
So far I have not been with the nail, but I’ve managed to do is edit the single-goods.php file but shows only a limited number of posts without names or images
I have noticed that this also depends on two classes: have_posts() and the_post(), but not which of the infinite php folders and files is that class.
As a last attempt, yesterday WordPress update to version 4.4.1-en_US .The results are the same
Please I need help. I’ve been a week with this and the customer has been asking me a lot to the site and is the last thing I need …
]]><?php
add_action( 'admin_menu', 'wp_autoTAG' );
function wp_autoTAG() {
add_options_page( 'Opciones WP autoTAG', 'Wp autoTAG', 'manage_options', 'wp_autoTAG', 'wp_autoTAG_options' );
}
function wp_autoTAG_options() {
echo "function wp_autotag_options()";
if (!current_user_can('manage_options'))
{
wp_die( __('Peque?±o padawan... debes utilizar la fuerza para entrar aquí-.') );
}
if(isset($_POST['gentags'])) {
echo "isset(post['gentags'])";
$limite = $_POST['relevancia'];
$valuetoken = $_POST['apitoken'];
$optionapi = get_option('apitoken','0');
$arraytags = array();
if(isset($_POST['apitoken'])){
echo "isset(post['apitoken'])";
if(!($optionapi === $valuetoken)){
add_option('apitoken', $valuetoken);
update_option('apitoken', $valuetoken);
echo "option added, valor apitoquen guardat";
}
}
//THE LOOP
rewind_posts();
if(have_posts()){
$contador = 0;
echo "have_posts";
while(have_posts()){
echo "bucle $contador";
$contador += 1;
if($contador > 4){
break;
}
the_post();
$post_id = the_ID();
$content = get_the_content();
//FUNCIóN DE ANALISIS DE TEXTO
//ANALISIS DE ENTIDADES
if(isset($_POST['personas']) || isset($_POST['lugares']) || isset($_POST['organizaciones']) || isset($_POST['otros'])){
echo "entidades analizadas";
$url = 'https://api.monkeylearn.com/v2/extractors/ex_Kc8uzhSi/extract/';
$data = array('text_list' => array($content));
$options = array(
'http' => array(
'header' => "Content-type: application/json\r\n".
"Authorization:token $valuetoken\r\n",
'method' => 'POST',
'content' => json_encode($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
//var_dump($result);
$jsonIterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator(json_decode($result, TRUE)),
RecursiveIteratorIterator::SELF_FIRST);
$push = false;
foreach ($jsonIterator as $key => $val) {
if(is_array($val)) {
}
else {
if(isset($_POST['personas'])){
if($key === 'tag' && $val ==='PERS'){
$push = true;
}
}
if(isset($_POST['lugares'])){
if($key === 'tag' && $val ==='LUG'){
$push = true;
}
}
if(isset($_POST['organizaciones'])){
if($key === 'tag' && $val ==='ORG'){
$push = true;
}
}
if(isset($_POST['otros'])){
if($key === 'tag' && $val ==='OTROS'){
$push = true;
}
}
if($key === 'entity' && $push == true){
$entity = $val;
array_push($arraytags, $entity);
$push = false;
}
}
}
}
if(isset($_POST['keywords'])){
echo "analisis de palabras clave";
//ANALISIS DE KEYWORDS CON RELEVANCIA
$limite = $_POST['relevancia'];
$url = 'https://api.monkeylearn.com/v2/extractors/ex_eV2dppYE/extract/';
$data = array('text_list' => array($content));
$options = array(
'http' => array(
'header' => "Content-type: application/json\r\n".
"Authorization:token $valuetoken\r\n",
'method' => 'POST',
'content' => json_encode($data),
),
);
$context = stream_context_create($options);
$result2 = file_get_contents($url, false, $context);
$jsonIterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator(json_decode($result2, TRUE)),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($jsonIterator as $key => $val) {
if(is_array($val)) {
}
else {
//COMPROBAR RELEVANCIA POR ENCIMA DEL LIMITE ESTABLECIDO
if($key ==='relevance'){
if(floatval($val) > floatval($limite)){
$push = true;
}
else{
$push = false;
}
}
//A?ADIR KEYWORDS RELEVANTES AL ARRAY
if($key ==='keyword'){
if($push == true){
array_push($arraytags, $val);
}
}
}
}
} // final de if(isset(post[keywords]))
wp_set_post_tags( $post_id, $arraytags);
}// final while(have posts())
}//FINAL THE LOOP
else{
echo "no_have_posts";
}
?>
<div class="updated">
<p>
<strong>
<?php _e('TAGS generados'); ?>
</strong>
</p>
</div>
<?php
}
echo '<div class="wrap">';
echo "<h2>" . __( 'auto TAG') . "</h2>";
$optionapi = get_option('apitoken','0');
?>
<form name="form1" method="post" action="">
<fieldset style="border:solid black 1px; padding: 15px;">
<p style="margin:0 1em 0 2em;">
<h3><span style="margin-right:1em;"> Clave de API</span></h3>
<input type="text" name="apitoken" size="42" value="<?php echo $optionapi ?>"/></br>
Si no dispone de Clave puede conseguir una <a href="https://app.monkeylearn.com/accounts/register/">aquí</a>
</p>
</fieldset>
<fieldset style="border:solid black 1px; padding: 15px;">
<p style="margin:0 1em 0 2em;">
<h3><span style="margin-right:1em;"> TAGS por palabra clave</span> <input type="checkbox" name="keywords"/></h3>
<?php _e("Relevancia mínima: "); ?>
<input type="number" name="relevancia" min="0.1" max="1" step="0.1" value="0.5"/>
</p>
</fieldset>
<fieldset style="border:solid black 1px; padding: 15px;">
<p style="margin:0 1em 0 2em;">
<h3> TAGS por entidades</h3>
<ul style="width:100%; list-style:none; margin:0; padding:0; float:left; text-align: left;">
<li style="float:left; width:25%; margin:0; paddind:0; list-style: none;">
<input type="checkbox" name="personas"/>
<?php _e("PERSONAS"); ?>
</li>
<li style="float:left; width:25%; margin:0; paddind:0; list-style: none;">
<input type="checkbox" name="lugares"/>
<?php _e("LUGARES"); ?>
</li>
<li style="float:left; width:25%; margin:0; paddind:0; list-style: none;">
<input type="checkbox" name="organizaciones"/>
<?php _e("ORGANIZACIONES"); ?>
</li>
<li style="float:left; width:25%; margin:0; paddind:0; list-style: none;">
<input type="checkbox" name="otros"/>
<?php _e("OTROS"); ?>
</li>
</ul>
</p>
</fieldset>
<p class="submit">
<input type="submit" name="gentags" class="button-primary" value="Generar TAGS" />
</p>
</form>
</div>
<?php
var_dump($arraytags);
}
?>
]]>Ok.
I have 17 posts but the website only showing 10.
This is just a guess, but I guess this is the place where the data is beeing picked up:
“”””””””””””””
<div class=”material-box”>
<div class=”material-box-title” id=”tekniska”>
Tekniska moment
</div>
<div class=”material-box-content” id=”tekniska-info”>
<?php
$loop = new WP_Query( array( ‘post_type’ => ‘material’, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’,’post_count’ => ‘100’,’category_name’=> ‘tekniska’) );
while ( $loop->have_posts() ) : $loop->the_post();
$pdf_name = get_post_meta($post->ID, ‘wpcf-pdf-name’, true);
$pdf_link = get_post_meta($post->ID, ‘wpcf-pdf-file’, true);
$video_name = get_post_meta($post->ID, ‘wpcf-video-name’, true);
$video_link = get_post_meta($post->ID, ‘wpcf-video-file’, true);
?>
<p>“><?php echo $pdf_name; ?></p>
<p>” class=”html5lightbox” data-width=”960″ data-height=”640″ title=”test”><?php echo $video_name; ?></p>
<?php endwhile; ?>
</div>
</div>
“””””””””””””
It says “while loop has posts loop the post”?
So why dont it?
Please help me.
]]>Can anyone show me what I’m doing wrong?
This is the site: https://ofcarquitetura.com.br/site2015
This is the homepage template:
<?php
/**
* Home Template
*
* A custom home page template.
*
* @package Hatch
* @subpackage Template
*/
get_header(); // Loads the header.php template. ?>
<?php do_atomic( 'before_masthead' ); // hatch_before_masthead ?>
<div id="masthead">
<?php do_atomic( 'open_masthead' ); // hatch_open_masthead ?>
<?php $hatch_author_bio = hybrid_get_setting( 'hatch_author_bio' ) ? hybrid_get_setting( 'hatch_author_bio' ) : '1'; ?>
<div id="author-bio"><?php the_author_meta( 'description', $hatch_author_bio ); ?></div>
<div id="header-banner" role="banner">
<?php // Check to see if the header image has been removed
$header_image = get_header_image();
if ( ! empty( $header_image ) ) : ?>
<img src="<?php header_image(); ?>" alt="" />
<?php endif; // end check for removed header image ?>
</div>
<?php do_atomic( 'close_masthead' ); // hatch_close_masthead ?>
</div>
<?php do_atomic( 'before_content' ); // hatch_before_content ?>
<div id="content">
<?php do_atomic( 'open_content' ); // hatch_open_content ?>
<div class="hfeed">
<?php if ( have_posts() ) : ?>
<?php $counter = 1; ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php do_atomic( 'before_entry' ); // hatch_before_entry ?>
<?php if ( ( $counter % 4 ) == 0 ) { ?>
<div id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?> last">
<?php } else { ?>
<div id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">
<?php } ?>
<?php do_atomic( 'open_entry' ); // hatch_open_entry ?>
<?php if ( current_theme_supports( 'get-the-image' ) ) {
get_the_image( array( 'size' => 'archive-thumbnail', 'image_class' => 'featured', 'width' => 220, 'height' => 150, 'default_image' => get_template_directory_uri() . '/images/archive_image_placeholder.png' ) );
} ?>
<?php echo apply_atomic_shortcode( 'entry_title', '[entry-title]' ); ?>
<?php do_atomic( 'close_entry' ); // hatch_close_entry ?>
</div><!-- .hentry -->
<?php do_atomic( 'after_entry' ); // hatch_after_entry ?>
<?php $counter++; ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'loop-error' ); // Loads the loop-error.php template. ?>
<?php endif; ?>
</div><!-- .hfeed -->
<?php do_atomic( 'close_content' ); // hatch_close_content ?>
<?php get_template_part( 'loop-nav' ); // Loads the loop-nav.php template. ?>
</div><!-- #content -->
<?php do_atomic( 'after_content' ); // hatch_after_content ?>
<?php get_footer(); // Loads the footer.php template. ?>
]]>