Wordpress blog pagination error - wordpress

An the bottom of the blog page of my WordPress site, there are numbers for pagination.
Assume my initial blog post page is https://example.com/blog
When I click number '2' to view more posts. My url changed as https://example.com/blogpage/2
However if i manually enter the url as https://example.com/blog/page/2 it goes to the second page of blog posts.
I only get this error when i am in page 1. When
I am in page 2 or page 3, the pagination links work fine
How can I correct this issue?
index.php file contains this code
<?php
global $wp_query, $wpl_exe_wp;
get_header();
get_template_part('part', 'breadcrumbs');
$style = $wpl_exe_wp->get_option('blog_archive_layout', 'system_layouts');
$read_more_text = $wpl_exe_wp->get_option('blog_read_more_text', 'system_layouts');
if( is_author() ) {
$style = $wpl_exe_wp->get_option('author_archive_layout', 'system_layouts');
$read_more_text = $wpl_exe_wp->get_option('author_read_more_text', 'system_layouts');
}
if( is_search() ) {
$read_more_text = $wpl_exe_wp->get_option('search_read_more_text', 'system_layouts');
if( get_query_var('post_type') == 'product' ) {
} else {
$style = $wpl_exe_wp->get_option('search_layout', 'system_layouts');
}
}
if( is_post_type_archive('wproto_portfolio') || is_tax( 'wproto_portfolio_category' ) ) {
$style = $wpl_exe_wp->get_option('portfolio_archive_layout', 'system_layouts');
$read_more_text = $wpl_exe_wp->get_option('portfolio_read_more_text', 'system_layouts');
}
?>
<section class="container" id="content">
<div class="row">
<div class="<?php echo wpl_exe_wp_front::content_classes( true ) . ' wproto-primary-content-area'; ?>">
<?php if( is_author() && $wpl_exe_wp->get_option('author_page_display_info', 'system_layouts') ): ?>
<!--
ABOUT AUTHOR INFO
-->
<?php wpl_exe_wp_front::about_author(); ?>
<?php endif; ?>
<?php if( is_post_type_archive('wproto_portfolio') || is_tax( 'wproto_portfolio_category' ) ): ?>
<!--
PORTFOLIO POSTS
-->
<?php echo do_shortcode('[wproto_portfolio read_more_text="' . esc_attr( $read_more_text ) . '" use_wp_query="1" posts_per_page="' . get_option('posts_per_page') . '" order_by="date" sort_by="DESC" style="' . esc_attr( $style ) . '" display_pagination="1" pagination_style="numeric_with_prev_next"]'); ?>
<?php else: ?>
<!--
POSTS
-->
<?php
$term_description = term_description();
if( $term_description <> '' ) {
echo wp_kses_post( $term_description );
}
?>
<?php echo do_shortcode('[wproto_blog read_more_text="' . esc_attr( $read_more_text ) . '" use_wp_query="1" posts_per_page="' . get_option('posts_per_page') . '" order_by="date" sort_by="DESC" style="' . esc_attr( $style ) . '" display_pagination="1" pagination_style="numeric_with_prev_next"]'); ?>
<?php endif; ?>
<div class="clearfix"></div>
</div>
<?php get_sidebar(); ?>
</div>
</section>

Related

How to create wordpress shortcode by this code

Sir,
I have this code to show all post of category and thumbnail for 1st post of them.
<?php $recent = new WP_Query(); ?>
<?php $recent->query( 'cat=1&showposts=5' ); ?>
<?php $is_first_post = true; ?>
<?php while( $recent->have_posts() ) : $recent->the_post(); ?>
<ul>
<li>
<?php
if ( $is_first_post && has_post_thumbnail() ) {
the_post_thumbnail();
$is_first_post = false;
}
?>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</li>
</ul>
<?php endwhile; ?>
But I want show this using shortcode. which using category & post number
but I can not make shortcode. Please help me.
// Add Shortcode
function recentpost_shortcode_func() {
$recent = new WP_Query();
$recent->query( 'cat=1&showposts=5' );
$is_first_post = true;
$html = '';
while( $recent->have_posts() ) : $recent->the_post();
$html .='<ul><li>';
if ( $is_first_post && has_post_thumbnail() ) {
$html .=get_the_post_thumbnail();
$is_first_post = false;
}
$html .='<a href="'.get_the_permalink().'">';
$html .=get_the_title();
$html .='</a></li></ul>';
endwhile;
return $html;
}
add_shortcode( 'recentpost', 'recentpost_shortcode_func' );

Fetch several rss feeds from other blogs in one page

I am trying to make a function which take an rss fedd URL and fetches the most recent 2 posts. I have tried to remake the snippet from here to a full function in funtions.php as following. I don't want to use a plugin for this since the plugins I have looked at have been close to impossible to style with my own html...
function fetch_feed_from_blogg($path) {
$rss = fetch_feed($path);
if (!is_wp_error( $rss ) ) :
$maxitems = $rss->get_item_quantity(2);
$rss_items = $rss->get_items(0, $maxitems);
endif;
function get_first_image_url($html)
{
if (preg_match('/<img.+?src="(.+?)"/', $html, $matches)) {
return $matches[1];
}
}
function shorten($string, $length)
{
$suffix = '…';
$short_desc = trim(str_replace(array("/r", "/n", "/t"), ' ', strip_tags($string)));
$desc = trim(substr($short_desc, 0, $length));
$lastchar = substr($desc, -1, 1);
if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix='';
$desc .= $suffix;
return $desc;
}
if ($maxitems == 0) echo '<li>No items.</li>';
else
foreach ( $rss_items as $item ) :
$html = '<ul class="rss-items" id="wow-feed"> <li class="item"> <span class="rss-image"><img src="' .get_first_image_url($item->get_content()). '"/></span>
<span class="data"><h5><a href="' . esc_url( $item->get_permalink() ) . '" title="' . esc_html( $item->get_title() ) . '"' . esc_html( $item->get_title() ) . '</a></h5></li></ul>';
return $html;
}
I am also trying to make it so that it can be used several times on a single page.
Much easier to use WordPress's built-in RSS function. See https://codex.wordpress.org/Function_Reference/fetch_feed
Use it as many times as you want in a php template, or make it generate a shortcode. Style the <ul> and <li> and add a containing <div> if needed.
Example:
<?php // Get RSS Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( 'http://example.com/rss/feed/goes/here' );
$maxitems = 0;
if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 5.
$maxitems = $rss->get_item_quantity( 5 );
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items( 0, $maxitems );
endif;
?>
<ul>
<?php if ( $maxitems == 0 ) : ?>
<li><?php _e( 'No items', 'my-text-domain' ); ?></li>
<?php else : ?>
<?php // Loop through each feed item and display each item as a hyperlink. ?>
<?php foreach ( $rss_items as $item ) : ?>
<li>
<a href="<?php echo esc_url( $item->get_permalink() ); ?>"
title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('j F Y | g:i a') ); ?>">
<?php echo esc_html( $item->get_title() ); ?>
</a>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>

how to create breadcrumbs using wordpress nav menu without plugin?

trying to show breadcrumbs but i am stuck.
ABOUT US
- TEAM
- WHAT WE DO
i don't understand how to show all menus dynamically in breadcrumbs, if i am currently on what we do page then how to show in breadcrumbs kindly help me
i try this
<?php $menuID = $post->ID;
query_posts( 'post_type=page&post_parent=$menuID' );
while ( have_posts() ) : the_post();
the_title();
endwhile;
?>
this code just show child of every page but how can i find page which one is clicked
Place this code in custom_functions.php:
function the_breadcrumb() {
global $post;
echo '<ul id="breadcrumbs">';
if (!is_home()) {
echo '<li><a href="';
echo get_option('home');
echo '">';
echo 'Home';
echo '</a></li><li class="separator"> / </li>';
if (is_category() || is_single()) {
echo '<li>';
the_category(' </li><li class="separator"> / </li><li> ');
if (is_single()) {
echo '</li><li class="separator"> / </li><li>';
the_title();
echo '</li>';
}
} elseif (is_page()) {
if($post->post_parent){
$anc = get_post_ancestors( $post->ID );
$title = get_the_title();
foreach ( $anc as $ancestor ) {
$output = '<li>'.get_the_title($ancestor).'</li> <li class="separator">/</li>';
}
echo $output;
echo '<strong title="'.$title.'"> '.$title.'</strong>';
} else {
echo '<li><strong> '.get_the_title().'</strong></li>';
}
}
}
elseif (is_tag()) {single_tag_title();}
elseif (is_day()) {echo"<li>Archive for "; the_time('F jS, Y'); echo'</li>';}
elseif (is_month()) {echo"<li>Archive for "; the_time('F, Y'); echo'</li>';}
elseif (is_year()) {echo"<li>Archive for "; the_time('Y'); echo'</li>';}
elseif (is_author()) {echo"<li>Author Archive"; echo'</li>';}
elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "<li>Blog Archives"; echo'</li>';}
elseif (is_search()) {echo"<li>Search Results"; echo'</li>';}
echo '</ul>';
}
Go to your single.php page and add the following code anywhere you want to display the breadcrumbs.
<?php the_breadcrumb(); ?>

Remove Blog Title in Specific Theme

I'd like to use a functions.php in my child theme to remove the blog title. Most posts here are for specific themes. No option I've tried have worked.
I found in header.php where the blog title is called:
<?php do_action('et_header_top'); ?>
<header class="clearfix">
<hgroup id="logo-area">
<?php $bloginfo_name = get_bloginfo( 'name' ); ?>
<h1 id="logo">
<?php if ( 'false' == et_get_option( 'flexible_logo_image', 'false' ) || '' == et_get_option( 'flexible_logo' ) ) echo apply_filters( 'et_logo_markup', $bloginfo_name ); else echo '<img src="' . esc_url( et_get_option( 'flexible_logo' ) ) . '" alt="' . esc_attr( $bloginfo_name ) . '" />'; ?>
</h1>
<h2><?php bloginfo( 'description' ); ?></h2>
</hgroup>
What do I put in functions.php to remove that?
I tried
`function remove_stuff()
{
remove_action('Fable_header','Fable_bloginfotitle',);
remove_action('Fable_header','Fable_bloginfodescription',);
}
add_action('init','remove_stuff');
?>`
with no change.
If you want to get rid of the blog title without deleting the code, you can comment it out. This helps reduce problems. If you want to put the blog title back later, you can easily put it out if it is commented out, but if you delete the text then you can't display the title.
Commenting out works like this: wrap your code in /* and */. Example: /* code */. In your case, you would want to comment out the code like this:
<?php do_action('et_header_top'); ?>
<header class="clearfix">
/* <hgroup id="logo-area">
<?php $bloginfo_name = get_bloginfo( 'name' ); ?>
<h1 id="logo">
<?php if ( 'false' == et_get_option( 'flexible_logo_image', 'false' ) || '' == et_get_option( 'flexible_logo' ) ) echo apply_filters( 'et_logo_markup', $bloginfo_name ); else echo '<img src="' . esc_url( et_get_option( 'flexible_logo' ) ) . '" alt="' . esc_attr( $bloginfo_name ) . '" />'; ?>
</h1>
<h2><?php bloginfo( 'description' ); ?></h2>
</hgroup> */

WordPress - Get posts in custom taxonomy category

I have a bit of a strange problem with my WP-query. I have a custom post type (portfolio), with a custom taxonomy called year. I have categories for each year, so what I want to do is display all posts for each year. The problem is, only 2012 works. Doesn't matter if I order the categories ASC/DESC - only 2012 works.
<section id="content">
<?php
$categories = get_categories('taxonomy=year&order=DESC');
foreach($categories as $category) : ?>
<article class="year">
<h2><?php echo $category->name ?></h2>
<div class="items">
<?php
$posts = get_posts('taxonomy=year&post_type=portfolio&year=' . $category->slug);
foreach($posts as $post) : ?>
<div class="item">
<?php
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" rel="lightbox[' . $category->slug . ']" >';
the_post_thumbnail('thumbnail');
echo '</a>';
?>
</div>
<?php endforeach; ?>
</div>
</article>
<?php
endforeach;
wp_reset_query();
?>
</section>
What am I doing wrong? To me, it seems right.. I've tried a bunch of different takes on this, everything from real querys to ridiculous sortings but I just can't get it right..
Thank you in advance!
I've solved it myself now, still not getting it 100% but it works at least.. There has got to be some smarter way of doing this, since im now looping trough all images for every term. Well, here's the code (get posts grouped by term from custom taxonomy).
<section id="content">
<?php
$categories = get_categories('taxonomy=year&order=DESC');
foreach($categories as $category) { ?>
<article class="year">
<h2><?php echo $category->name ?></h2>
<div class="items">
<?php
$args = array(
'post_type' => 'portfolio'
);
query_posts($args);
$count = 0;
while(have_posts()) : the_post();
$terms = get_the_terms( $post->ID, 'year' );
foreach ( $terms as $term ) {
$imgslug = $term->name;
}
if($imgslug == $category->name) {
if($count == 6) {
echo '<div class="expanded-items">';
}
?>
<div class="item">
<?php
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" rel="lightbox[' . $category->slug . ']" >';
the_post_thumbnail('thumbnail');
echo '</a>';
?>
</div>
<?php
}
$count++;
endwhile;
if($count >= 6) {
echo '</div>';
}
?>
</div>
<div class="expand">Visa fler</div>
</article>
<?php } ?>
</section>
That is with an expandable list, so it shows 6 from the start and then expands to show the rest of the items (jQuery).

Resources