How to add pagination in wordpress - wordpress

I have tried as following code in my template file in wordpress...
<?php query_posts('showposts=3&post_type=packages&order=ASC&paged='.$paged) ?>
It's not working... Please help me!!! I am a beginner in wordpress

first parameter is your seperator between links
second parameter is previous page
third parameter is next page
<div style="text-align:center;">
<?php posts_nav_link(' · ', 'previous page', 'next page'); ?>
</div>
you can replace them with images as well
<?php posts_nav_link( ' ', '<img src="' . get_bloginfo('stylesheet_directory') . '/images/prev.jpg" />', '<img src="' . get_bloginfo('stylesheet_directory') . '/images/next.jpg" />' ); ?>

Related

domPDF and ACF repeater fields

I am using domPDF to generate PDFs on certain pages of my site
The problem I am having is that it won’t allow me to use repeater values (via any sort of loop), it doesn’t seem to want to generate them when the PDF is created.
If I call the repeater field itself as a variable, it returns ‘array’, so I assume it’s possible to get it working, somehow.
It appears the repeaters first need to be generated and then included (perhaps as a variable?), but I’m unsure of how to do this.
Does anyone have any idea of how I can get this to work?
This is my ACF repeater code:
<?php if( have_rows('team_contact_details') ): ?>
<div class="profile-item">
<ul class="list-contact">
<?php while( have_rows('team_contact_details') ): the_row(); ?>
<li>
<div class="list-contact-letter">
<?php the_sub_field("contact_label"); ?>
</div>
<div class="list-contact-detail">
<?php
if(get_sub_field('contact_link') == 'phone' ) {
echo '' . get_sub_field("phone_number") . '';
} else if(get_sub_field('contact_link') == 'email' ) {
echo '' . get_sub_field("email_address") . '';
}
?>
</div>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php endif; ?>
This is my domPDF code:
//Print PDF
require_once get_template_directory() . '/dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$content = '
<html>
<head></head>
<body>
<div class="person">
<img src="' . get_field('page_image') . '"/>
</div>
<h1>' . get_the_title() . '</h1>
<div class="pdf-label">' . get_field('team_academic') . '</div>
<div class="pdf-label">' . get_field('team_position') . '</div>
<<<< Attempting to put repeater values here as unordered list >>>>
</body>
</html>
';
// instantiate and use the dompdf class
$dompdf = new Dompdf(array(
'enable_remote' => true
)
);
$dompdf->loadHtml($content);
// (Optional) Setup the paper size and orientation
$dompdf->set_paper( 'letter' , 'portrait' );
// Render the HTML as PDF
$dompdf->render();
$doctitle = get_the_title();
$dompdf->stream($doctitle);
Thanks
I got it. FYI, this was how:
if( have_rows('team_contact_details')) :
while(have_rows('team_contact_details')) : the_row();
$content .= '<h3>'. get_sub_field('contact_label') .'</h3>';
if(get_sub_field('contact_link') == 'phone') {
$content .= '<div>'. get_sub_field('phone_number') .'</div>';
} else {
$content .= '<div>'. get_sub_field('email_address') .'</div>';
}
endwhile;
endif;

Next Previous Post in wordpress with previous / next link with title?

I recently tried the previous post and the next post button link. I do that with image in the left and right side of the site.Its working perfect.But i didn't know how to do this
For Example:
<div class="alignleftfp">
<?php next_post('%', '<img class="imgalign" src="' . WP_CONTENT_URL . '/uploads/1.png" alt="Next" /> ', 'no');
?>
</div>
<div class="alignrightfp">
<?php previous_post('%', '<img class="imgalign" src="' . WP_CONTENT_URL . '/uploads/1.png" alt="Next" /> ', 'no');
?>
</div>
Is it Possible to Show the Previous Post and Next Post Link with Under Title in every Bottom of the Post. Here is the Screenshot.
<nav id="nav-single">
<?php
$prev_post = get_previous_post();
$id = $prev_post->ID ;
$permalink = get_permalink( $id );
?>
<?php
$next_post = get_next_post();
$nid = $next_post->ID ;
$permalink = get_permalink($nid);
?>
<span class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">←</span> Previous', 'twentyeleven' ) ); ?>
<h2><?php echo $prev_post->post_title; ?></h2>
</span>
<span class="nav-next"><?php next_post_link( '%link', __( 'Next <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?>
<h2><?php echo $next_post->post_title; ?></h2>
</span>
</nav>
I hope you are using this code in single.php from where the whole of the post is displayed. For displaying the links (Next/Prev), you need to check the function.
get_template_part()
in the same file (Single.php of your theme). In my case function in single.php has been passes parameters like
<?php get_template_part( 'content-single', get_post_format() ); ?>
So, you will open the "content-single.php" according to the parameters specified in the function and paste the same code
<div class="alignleftfp">
<?php next_post('%', '<img class="imgalign" src="' . get_bloginfo('template_directory') . '/images/1.png" alt="Next" /> ', 'no');
?>
</div>
<?php previous_post('%', '<img class="imgalign" src="' . get_bloginfo('template_directory') . '/images/2.png" alt="Next" /> ', 'no');
?>
</div>
below <h1 class="entry-title"><?php the_title(); ?></h1>
I hope this will solve your problem.

Get image of a post in Wordpress

I want to make a slide show in wordpress, I made a category for it and now I want to get images of that category for my slide show. Here is part of my code:
<div id="slide-show">
<ul>
<?php query_posts('cat=1'); while(have_posts()): the_post();?>
<li>
<a href="<?php the_permalink();?>">
<img src="<?php
$image=wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail');
echo $image[0];?>" alt="<?php the_title();?>" /></a>
</li>
<?php endwhile; wp_reset_query();?>
</ul>
</div>
But it does not work. Can anybody help me please?
First of all, I'll repeat myself:
First of all, don't use query_posts.
Please, check:
When should you use WP_Query vs query_posts() vs get_posts()?
When to use WP_query(), query_posts() and pre_get_posts
In this case, I'd suggest building a function to create the desired output. You put it inside your theme functions.php file. Put it at the end of the file.
If there is any ?> as the last thing of a PHP file, remove it, it is not necessary and may break your site if there is any white space after it.
That said, our function will print exactly the Html you want and it is called like this in any theme template file (index.php, single.php, page.php, etc).
<?php get_gallery(4); ?>
The number 4 is the Category ID.
And this is the function, check the comments in the code:
function get_gallery( $id )
{
// Simple query
$posts = get_posts( array(
'category' => $id,
'post_status' => 'publish',
'post_type' => 'post',
) );
// Start building the Html code
$slide_show = '
<div id="slide-show">
<ul>';
// Iterate through the results
foreach ( $posts as $post )
{
// Assign value and test if it exists at the *same time*
if( $thumb = get_post_thumbnail_id( $post->ID ) )
{
$permalink = get_permalink( $post->ID );
$image = wp_get_attachment_image_src( $thumb );
// Build the Html elements
$slide_show .= '
<li>
<a href="' . $permalink . '">
<img src="'. $image[0] . '" alt="' . $post->post_title .'" />
</a>
</li>';
}
}
// Finish the Html
$slide_show .= '
</ul>
</div>
';
// Print the Html
echo $slide_show;
}
Result:

wordpress url structure

Is it possible in wordpress when I call example.com/category to have listed all available categories. If I request the url like in my example I'm getting an 404 page
I'm not sure if there is a default link to list all the categories.
But it doesn't mean you can't do it yourself. Create a new template file in your theme, name it for example category_list.php and add this code:
You might want to tweak it a bit to display it how you want.
<?php
/**
* Template Name: Category listing
* Description: list all the categories
*/
get_header(); ?>
<div class="container">
<?php
$args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($args);
foreach($categories as $category):
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
echo '<p> Description:'. $category->description . '</p>';
echo '<p> Post Count: '. $category->count . '</p>';
echo '<hr />';
endforeach;
?>
</div>
<?php get_footer(); ?>
Then go to Pages -> add new. Name the Page as "Category", so that the url will be example.com/category.
And in the template list select the template you just created. It will be named "Category listing" as you can see in the code above in the comments at the top.

Lightbox 2 and Flickr - Where are the next and previous buttons?

I'm looking to integrate a lightbox2 gallery system with Slick Flickr's ability to pull in a RSS feed containing image information. So far, I have lightbox set up and display correctly, but it fails to show next or previous buttons to cycle through the other images on the gallery.
Here's the current html. The rest is default lightbox2 file stuff.
<div class="album-wrapper">
<?php foreach ($feed->get_items() as $item): ?>
<div class="photoContainer">
<?php
if ($enclosure = $item->get_enclosure()) {
$img = image_from_description($item->get_description());
$full_url = select_image($img, 4);
$thumb_url = select_image($img, 0);
echo '<a href="' . $full_url . '" rel="lightbox" ><img class="photo' . $i . '" src="' . $thumb_url . '" /></a>'."\n";
}
?>
</div>
<?php endforeach; ?>
Put <!doctype html>on the first line of your code will fix the problem

Resources