Page title and content in wrong order (wordpress/bootstrap/php) - wordpress

I'm having problem with my Wordpress 4.7.8 localhost custom-theme webpage.
As hard as I try, I keep getting "Title" where content should be and the content at the place of the title
Here is an image
Here is how it looks in wordpress admin dashboard:
...and image the view in wordpress
any Ideas where I might be going wrong?

Try this code.
Search bar in duplicate (wordpress/php/bootstrap)
This code taken from your previous question.
this code for displaying title <?php the_title(); ?> and this code displaying content <?php the_content(); ?>. you can replace this code wherever you want.
<?php get_header(); ?>
<div class="row">
<div class="col-xs-12 col-sm-8">
<div class="row text-center no-margin">
<?php
$currentPage = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page' => 3,'post_type'=>'post', 'paged' => $currentPage);
new WP_Query($args);
if( have_posts() ): $i = 0;
while( have_posts() ): the_post(); ?>
<?php
if($i==0): $column = 12; $class = '';
elseif($i > 0 && $i <= 2): $column = 6; $class = ' second-row-padding';
elseif($i > 2): $column = 4; $class = ' third-row-padding';
endif;
?>
<div class="col-xs-<?php echo $column; echo $class; ?> blog-item">
<?php if( has_post_thumbnail() ):
$urlImg = wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) );
endif; ?>
<div class="blog-element" style="background-image: url(<?php echo $urlImg; ?>);">
<!--<?php the_title( sprintf('<h1 class="entry-title">', esc_url( get_permalink() ) ),'</h1>' ); ?> -->
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php the_content(); ?>
<small><?php the_category(' '); ?></small>
</div>
</div>
<?php $i++; endwhile; ?>
<div class="col-xs-6 text-left">
<?php next_posts_link('« Older Posts'); ?>
</div>
<div class="col-xs-6 text-right">
<?php previous_posts_link('Newer Posts »'); ?>
</div>
<?php endif;
wp_reset_query();
?>
</div>
</div>
<div class="col-xs-12 col-sm-4">
<?php get_sidebar(); ?>
</div>
</div>

You might need to edit content-single.php file to change the post content order. Your post content is loading first before post title.
Check if ,
the_content() or get_the_content()
is showing before ,
get_the_title() or the_title()

Related

ACF repeater - apply different row last repeater

I use ACF repeater in my wordpress website.
Each repeater display in a col-md-6.
I would like to display the last in a col-md-12.
<div class="container">
<?php if ( have_rows( 'salon' ) ) : ?>
<div class="row">
<?php while ( have_rows( 'salon' ) ) : the_row(); ?>
<div class="col-md-6">
<div class="card">
<div class="card-body">
<h2 class="card-title">Card title</h2>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
</div>
Try this example with your code it's working for me.
<?php if( have_rows('services_repeater', $services) ): ?>
<?php $rowCount = count( get_field('services_repeater', $services) ); //GET THE COUNT ?>
<?php $i = 1; ?>
<?php while( have_rows('services_repeater', $services) ): the_row(); ?>
<?php // vars
$service = get_sub_field('service');
$description = get_sub_field('description');
?>
<span class="hint--bottom" data-hint="<?php echo $description; ?>"><?php echo $service; ?></span>
<?php if($i < $rowCount): ?>
<div id="separator"> / </div>
<?php endif; ?>
<?php $i++; ?>
<?php endwhile; ?>
<?php endif; ?>

how to add pagination in wordpress

I have posts in different custom taxonomies. I need to display posts for one taxonomy in a page. Now I'm getting the all the posts in all taxonomies in a single page. I have a foreach loop for taxonomy and inside the loop all the posts corresponding to that taxonomy is displaying through post method.I have never used pagination before. How can I add pagination in this case?
I am enclosing my code below
<div class="main">
<section class="brands-sec product-sec">
<div class="container">
<?php
$siteurl = home_url('/');
$tax = 'product'; // slug of taxonomy
$terms = get_terms($tax);
foreach ($terms as $term) {
$id = $term->term_id;
$slug = $term->slug;
$description = $term->description;
$image_url = z_taxonomy_image_url( $id, NULL, TRUE ); // category image display
$link = "<a href='$siteurl?$tax=$slug' ><h1> $term->name </h1></a>";
echo '<img src="' . $image_url . '">'; ?>
<div class="col-md-8 pull-right col-sm-10 pull-right col-xs-12 brnd prdct">
<img src="<?php echo $image_url ; ?>" class="img-responsive pdt-logo" alt="loyd"/>
<div class="brand-logos pdt">
<p><?php echo $description ; ?></p>
<h4>Product</h4>
<?php $args = array("posts_per_page" => "-1", "product"=>$slug ,"post_type" => "products" );
$posts = get_posts($args);
foreach($posts as $data){
$thumb = wp_get_attachment_url( get_post_thumbnail_id($data ->ID) );
$custom_fonts = get_post_custom($data->ID);$custom_fonts_key= $custom_fonts['category'];$custom_fonts_array = $custom_fonts_key[0]; ?>
<div class="row mb40">
<div class="col-md-4 col-sm-4 col-xs-12 brand-single product-single">
<img src="<?php echo $thumb; ?>" class="img-responsive" alt="allegro products"/>
<h5><?php echo $data->post_title; ?></h5>
<p><?php echo $data->post_content; ?></p>
</div>
<div class="col-md-8 col-sm-8 col-xs-12 brand-single product-detail">
<ul class="products">
<?php
$attachments = new Attachments( 'my_attachments',$data->ID ); /* pass the instance name */ ?>
<?php if( $attachments->exist() ) : ?>
<?php while( $attachments->get() ) : ?>
<li><img src="<?php echo $attachments->url(); ?>" class="img-responsive" alt="allegro products"/></li>
<?php endwhile; ?>
<?php endif; ?>
</ul>
</div>
</div>
<?php } ?>
</div><!--end brand-logos-->
</div><!--end brnd-->
<?php } ?>
</div>
Here product is custom taxonomy . In that there are more than one terms say loyd,Nycofee,.... In Both these terms there are more than one posts. I need to display posts in loyd in one page and ncofee in next page. How to add pagination in this case?
Try this:
You have the post_per_page to be -1
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array("posts_per_page" => "-1", "product"=>$slug ,"post_type" => "products" );
change it to the number you would like. and add to the end
'paged' => $paged
before Ending the PHP here
</div>
<?php } ?>
</div><!--end brand-logos-->
Add
<?php if (function_exists('wp_pagenavi')) wp_pagenavi(array('query' => $args )); ?>
<?php wp_reset_postdata(); ?>
Here is the basic pagination for wordpress
<?php if ( have_posts() ) : ?>
<!-- Add the pagination functions here. -->
<!-- Start of the main loop. -->
<?php while ( have_posts() ) : the_post(); ?>
<!-- the rest of your theme's main loop -->
<?php endwhile; ?>
<!-- End of the main loop -->
<!-- Add the pagination functions here. -->
<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
Soruce: https://codex.wordpress.org/Pagination "Example Loop with Pagination"
If it still show the full list.
Try this: http://callmenick.com/post/custom-wordpress-loop-with-pagination

How to paginate custom post type in wordpress of custom taxonomy

I want to implement pagination on custom post type of a custom taxonomy.
but it is not showing the pagination links only shows on default posts but not working. When I click on next link it redirect me to the index page.
Any help.(New to Wordpress)
Code
<?php $term = get_queried_object();
$taxonomy = get_taxonomy($term->taxonomy);
?>
<div class="panel-heading"><h4><?php echo 'محصولات : '.$term->name;?></h4></div>
<div class="panel-body">
<?php
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array('post_type'=>'my_product', 'taxonomy'=>$taxonomy->name,
'posts_per_page'=> 1,
'term'=>$term->slug, 'paged'=>$paged);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()): $query->the_post(); ?>
<div class="thumbnail">
<?php if (has_post_thumbnail()) {
the_post_thumbnail('featured');
} ?>
<div class="caption caption-content">
<h3><?php the_title(); ?></h3>
<p class="text-muted">
<!-- <strong>نویسنده:</strong> <?php //the_author();?> -->
تاریخ: <?php the_date(); ?></p>
<p> <?php the_excerpt(); ?> </p>
<div>
<p class="price-box">
<i class="fa fa-circle"> </i>قیمت:
<?php if (the_field('price') == '') {
// echo "00.00";
} else {
the_field('price');
} ?>
</p>
</div>
</div>
<hr>
</div>
<?php endwhile;
}
else {
echo '<h3>هیچ موردی درین بخش یافت نشد.</h3>';
}
?>
<!-- pagination here -->
<p> <?php
if (function_exists("custom_pagination")):
custom_pagination($custom_query->max_num_pages,"",$paged);
endif;
?>
<?php wp_reset_postdata(); ?>
</p>
</div>

Pagination don't work in custom page template

I created a custom page template like category.php but I can't get the pagination working.
I just filter post from one category.
Here is my code:
<?php
/* Template Name: News */
?>
<?php get_header(); ?>
<div class="col-lg-9 col-md-8 content">
<div class="box">
<h1 class="title"><?php the_title(); ?></h1>
<div class="box-int">
<article>
<?php // Display blog posts on any page # http://m0n.co/l
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('showposts=5' . '&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php
if (has_post_thumbnail()) {
the_post_thumbnail();
}
?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<br><br>
<?php endwhile; ?>
<?php if ($paged > 1) { ?>
<nav id="nav-posts">
<div class="prev"><?php next_posts_link('« Old'); ?></div>
<div class="next"><?php previous_posts_link('Newx »'); ?></div>
</nav>
<?php } else { ?>
<nav id="nav-posts">
<div class="prev"><?php next_posts_link('« Old'); ?></div>
</nav>
<?php } ?>
<?php wp_reset_postdata(); ?>
</article>
</div>
</div>
</div>
<div class="col-lg-3 col-md-4">
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
What's wrong here? I click in Page 2, but the post are always the same.
Your query is a bit of a mess here with some syntax errors as well.showposts died with the dinosaurs, it is long time depreciated. You should use posts_per_page. 'showposts=5' . '&paged='.$paged is also a mess. You query shouls simplify look like this
$args = array(
'posts_per_page' => 5,
'paged' => $paged
);
$query = new WP_Query( $args );
while ($query->have_posts()) : $query->the_post(); ?>
When querying the loop with WP_Query, you need to assign $max_pages parameter to the next_posts_link().
So you would need to change <?php next_posts_link('« Old'); ?> to <?php next_posts_link('« Old', $the_query->max_num_pages ); ?>
Also go and read this question on this subject. If I missed something, this question will most certainly help you out a lot.

Wordpress category template is showing posts from all categories instead of specific category posts

I have an archive page that's set up to display category specific posts. However, instead of showing only the posts from a given category on the category page, it's showing all posts. For an example, see here.
Here's the code I'm using on my archive.php page. I know it's improper use of the loop, but I'm not sure how to fix it. Thanks for the help.
<?php get_header(); ?>
<div id="content">
<div id="inner-content" class="wrap clearfix">
<h1 class="blogTitle" style="margin:10px 0 3px 0;">Blog Title</h1>
<nav class="blogNav" role="navigation">
<?php bones_blog_nav(); // Adjust using Menus in Wordpress Admin ?>
</nav>
<div id="main" class="eightcol first clearfix" role="main">
<div class="catwhiteBg">
<?php if (is_category()) { ?>
<h1 class="catTitle">
<span><?php _e("", "bonestheme"); ?></span> <?php single_cat_title(); ?>
</h1>
<?php echo category_description( $category_id ); ?>
<?php } elseif (is_author()) { ?>
<div class="authorTop">
<?php
$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
?>
<div class="author-pic"><?php echo get_avatar( $curauth->user_email, '80' ); ?></div>
<div class="author-name"><span style="font-weight: 200; color: #575757;">POSTS BY:</span>
<?php echo $curauth->first_name; ?> <?php echo $curauth->last_name; ?>
</div>
<div class="author-bio"><?php echo $curauth->description; ?></div>
<div class="author-twitter"><span>twitter</span></div>
</div>
<?php } elseif (is_day()) { ?>
<h1 class="archive-title h2">
<span><?php _e("Daily Archives:", "bonestheme"); ?></span> <?php the_time('l, F j, Y'); ?>
</h1>
<?php } elseif (is_month()) { ?>
<h1 class="archive-title h2">
<span><?php _e("Monthly Archives:", "bonestheme"); ?></span> <?php the_time('F Y'); ?>
</h1>
<?php } elseif (is_year()) { ?>
<h1 class="archive-title h2">
<span><?php _e("Yearly Archives:", "bonestheme"); ?></span> <?php the_time('Y'); ?>
</h1>
<?php } ?>
</div>
<div class="psts">
<?php
global $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
query_posts(array('posts_per_page' => '8','paged'=>$paged));
?>
<?php
$count = 1;
while (have_posts()) : the_post(); ?>
<div class="sixcol small pst<?php if ((isset($count)) && ($count % 2 == 0 )) { echo ' last';} // same logic to add class of last to last item in row of two ?>" id="post-<?php the_ID(); ?>">
<article id="post-<?php the_ID(); ?>" role="article">
<div class="thumb-wrapper mobile">
<?php if(has_post_thumbnail()) { $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'post-thumb' ); echo '<img src="' . $image_src[0] . '" width="100%" class="post-thumb" />'; } ?>
<header class="post-thumb-header">
<h2 class="post-title"><?php the_title(); ?></h2>
</header> <!-- end article header -->
<p class="meta"><?php the_category(', '); ?></p>
</div>
<section class="mobile-content">
<?php the_excerpt(); ?>
</section>
</article> <!-- end article -->
</div>
<?php $count++; ?>
<?php endwhile; ?>
<nav class="wp-prev-next">
<?php echo rb_pagination(); ?>
</nav>
</div> <!-- end .psts -->
</div> <!-- end #main -->
<?php get_sidebar(); // sidebar 1 ?>
</div> <!-- end #inner-content -->
</div> <!-- end #content -->
<?php get_footer(); ?>
I think you're overriding the original query with this line:
query_posts(array('posts_per_page' => '8','paged'=>$paged));
Can you swap this line with this, and let me know the results?
global $query_string;
query_posts( $query_string . "&posts_per_page=8&paged=$paged" );
if that fails try this:
query_posts(array('posts_per_page' => '8','paged'=>$paged, 'cat' => $category_id ));

Resources