We found a wordpress plugin that worked well with a few modifications. Everything is working on a page, but we want to move the plugin shortcode to the homepage. When we do, the shortcode is displayed, not the plugin output. I read that there are limitations on when a plugin can be executed (ie, not in the sidebar) and there was some code that was suppossed to allow the shortcode to work, but no matter what, we see the shortcode on our index instead of plugin output.
Does anyone have any experience with getting plugin shortcode to work on the home/index page of a wordpress install?
Thanks,
UPDATE: Below is the index.php which I believe generates the homepage. We make changes to this file to update the homepage, this is where I put the shortcode in standard HTML (which may not be the right way to do it).
<?php get_header();?>
<div id="content">
<h1 class="hidden">Haute Inhabit</h1>
<div class="wrapper clear">
<div class="main section" id="main" role="main">
<div class="widget Blog" id="Blog1">
<div class="blog-posts hfeed">
<!-- google_ad_section_start(name=default) -->
<?php
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$query = new WP_Query( array( 'paged' => $paged, 'cat'=>'-460' ) );
//$query = new WP_Query( 'cat=-460&posts_per_page=5' );
if ( $query->have_posts() ):
/*$tmp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query('showposts=3');*/
//$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
//$my_query = new WP_Query('showposts=3&paged=' . $paged);
while ($query->have_posts() ) : $query->the_post(); ?>
<div class="post hentry">
<a id="6576135133677080233" name=
"6576135133677080233"></a>
<h3 class="date-header"><span><?php echo get_the_date(); ?></span></h3>
<h2 class="post-title entry-title"><?php the_title();?></h2>
<div class="post-lead entry-content">
<?php echo get_first_paragraph() ?>
</div>
<div class="post-image">
<a href="<?php the_permalink();?>">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail('full');
} else {
?>
<img src="<?php echo catch_that_image() ?>">
<?php } ?>
</a>
</div>
<div class="post-utility">
<div class="inner clear">
View More
<div class="comments">
<?php if ( comments_open() ) : ?><span class="comments-link"><?php comments_popup_link( '<span class="leave-reply">' . __( 'Comment', 'hautein' ) . '</span>', __( '<em>1</em> Comment', 'hautein' ), __( '<em>%</em> Comments', 'hautein' ) ); ?></span>
<?php endif; // End if comments_open() ?>
</div>
<span>Share</span>
</div>
<?php include('inc/social.php'); ?>
</div>
</div>
<?php endwhile;?>
<?php
// $wp_query=$tmp;
//hautein_content_nav( 'nav-below' );
endif;?>
<div class="pagination clear">
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'prev_text' => 'Prev',
'next_text' => 'Next'
) );
?>
</div>
</div>
<script type="text/javascript">
window.___gcfg = {'lang': 'en'};
</script>
</div>
</div>
<?php get_sidebar();?>
</div>
</div>
<?php get_footer();?>
you can use a plugin that converts the shortcode in a widget
https://wordpress.org/plugins/shortcode-widget/
or use this shortcodes
https://wordpress.org/plugins/shortcodes-ultimate/
shouldnt have any problems like shortcodes not showing up...
unless your index is pulling the excerpt of your posts then shortcode will prob not be working as intended.
To better solve your issue, you did need to know which file is displaying your index page and show us the code here.
Related
Pagination template part includes common pagination function with style. The template part works for archive.php (it's for "single", you know default wp file) but doesn't work for custom post type.
Why not? How to solve it?
<?php get_header(); ?>
<main role="main">
<!-- section -->
<?php get_template_part( 'breadcrumb' );?>
<!-- Inner Pages Main Section -->
<section class="ulockd-service-details">
<div class="container">
<div class="col-md-12">
<div class="row">
<?php
/**
* Setup query to show the ‘services’ post type with ‘8’ posts.
* Output the title with an excerpt.
*/
$args = array(
'post_type' => 'team',
'post_status' => 'publish',
'posts_per_page' => 1,
);
$loop = new WP_Query( $args );
if (have_posts()): while ( $loop->have_posts() ) : $loop->the_post();
?>
<?php //if (have_posts()): while (have_posts()) : the_post(); ?>
<?php
if ( $thumbnail_id = get_post_thumbnail_id() ) {
if ( $image_src = wp_get_attachment_image_src( $thumbnail_id, 'normal-bg' ) )
?>
<div class="col-md-12 ulockd-mrgn1210">
<div class="ulockd-project-sm-thumb">
<img class="img-responsive img-whp" src="<?php printf( '%s', esc_url($image_src[0]) ); ?>" alt="">
</div>
</div>
<?php
}
?>
<div class="col-md-12 ulockd-mrgn1210">
<article class="ulockd-pd-content">
<div class="ulockd-bp-date">
<ul class="list-inline">
<li class="ulockd-bp-date-innner">On <span class="text-thm2"><?php the_time('j'); ?></span> / <?php the_time('F Y') ?></li>
<li class="ulockd-bp-comment"><span class="flaticon-nurse-head text-thm1"></span> <?php the_author_posts_link(); ?></li>
<li class="ulockd-bp-comment"><span class="flaticon-chat text-thm1"></span> <?php if (comments_open( get_the_ID() ) ) comments_popup_link( __( 'Leave your thoughts', 'html5blank' ), __( '1 Comment', 'html5blank' ), __( '% Comments', 'html5blank' )); ?></li>
<li class="ulockd-bp-comment"><span class="flaticon-black-check-box text-thm1"></span> <?php the_category(); ?></li>
</ul>
</div>
<h3><?php the_title(); ?> </h3>
<p class="project-dp-one"><?php html5wp_excerpt('html5wp_index'); // Build your custom callback length in functions.php ?></p>
<a class="btn btn-lg ulockd-btn-thm2" href="<?php the_permalink(); ?>"> Read More</a>
</article>
</div>
<?php get_template_part('pagination'); ?>
<?php endwhile; ?>
<?php else: ?>
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article>
<?php endif; ?>
</div></div></div></section>
<?php get_footer(); ?>
</main>
First of all, you don't need to include that template inside while loop. That's wrong.
Then, if you want to have an archive page for your team post type, you need to provide 'has_archive' => true within register_post_type() function args.
Also, consider changing archive page default slug if needed. If you do so, you need to open Settings > Permalinks for resetting your permalinks structure.
Then you could either use standard archive.php for the whole team archive page and standard template-parts/content.php for one post inside the loop or rewrite either of those by creating archive-team.php or content-team.php. And the_posts_pagination() function will work on proper archive page (either archive.php or archive-team.php).
I would try two things.
Add the argument paged to your wp_query args :
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'team',
'post_status' => 'publish',
'paged' => $paged,
'posts_per_page' => 1,
);
Put your pagination template outside the loop :
<?php endwhile; ?>
<?php get_template_part('pagination'); ?>
I am trying to loop through a post type called blog. The pagination works fine when the Wordpress permalinks are set to plain however when I change it to post the name and click to go on pagination link, it loads a 404 error.
I found out that you can't have the same post type and page name since it will cause a 404 error. I wanted to know if there was a workaround because changing the name of the post type will affect the blog posts.
My page-blog.php
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$loop = new WP_Query( array( 'post_type' => 'blog',
'posts_per_page' => 2,
'paged' => $paged,
'has_archive' => false,
'rewrite' => array(
'slug' => '/blog', // if you need slug
'with_front' => false,
),)
);
if ( $loop->have_posts() ):
while ( $loop->have_posts() ) : $loop->the_post();
// Set variables
$title = get_the_title();
$post_date = get_the_date('M j');
$amount_of_time_to_read = get_field('amount_of_time_to_read');
?>
<a href="<?php the_permalink(); ?>" class="post-blog-link">
<div class="post">
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'thumbnail' ); ?>
<div class="post-image-v2" style="background-image:url('<?php echo $url ?>');">
</div>
<div class="post-content-v2">
<h2 class="post-title"><?php echo $title; ?></h2>
<div class="post-excerpt">
<p><?php echo get_excerpt(); ?></p>
</div>
<p class="post-date"> <span class="caps"><?php echo $post_date; ?></span> | <?php echo $amount_of_time_to_read; ?>min read</p>
</div>
</div>
</a>
<!--
-->
<?php endwhile; ?>
<center>
<div class="pagination mt-25">
<?php pagination_bar( $loop ); ?>
</div>
</center>
<?php wp_reset_postdata();
endif;
?>
My functions.php
add_action('init', 'custom_rewrite_basic');
function custom_rewrite_basic() {
global $wp_post_types;
foreach ($wp_post_types as $wp_post_type) {
if ($wp_post_type->_builtin) continue;
if (!$wp_post_type->has_archive && isset($wp_post_type->rewrite) && isset($wp_post_type->rewrite['with_front']) && !$wp_post_type->rewrite['with_front']) {
$slug = (isset($wp_post_type->rewrite['slug']) ? $wp_post_type->rewrite['slug'] : $wp_post_type->name);
$page = get_page_by_slug($slug);
if ($page) add_rewrite_rule('^' .$slug .'/page/([0-9]+)/?', 'index.php?page_id=' .$page->ID .'&paged=$matches[1]', 'top');
}
}
}
function get_page_by_slug($page_slug, $output = OBJECT, $post_type = 'page' ) {
global $wpdb;
$page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type= %s AND post_status = 'publish'", $page_slug, $post_type ) );
return ($page ? get_post($page, $output) : NULL);
}
what do you want to achieve to have a Post Type and Page to be of the same slug?
As per my understanding you want to display the archive of your custom post type "Blog". All you have to do is create a file name archive-blog.php and use the plain WordPress loop. That way you don't need to have a page-blog.php (Delete it) to display the Archives of your "Blog" post type. yourwebsite.com/blog will automatically display your "Blog" archive.
Use the code below to paste in your archive-blog.php
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post();
// set vars
$amount_of_time_to_read = get_field('amount_of_time_to_read');
?>
<a href="<?php the_permalink(); ?>" class="post-blog-link">
<div class="post">
<?php $url = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ), 'thumbnail' ); ?>
<div class="post-image-v2" style="background-image:url( '<?php echo $url ?>' );">
</div>
<div class="post-content-v2">
<h2 class="post-title"><?php the_title(); ?></h2>
<div class="post-excerpt">
<p><?php the_excerpt(); ?></p>
</div>
<p class="post-date"> <span class="caps"><?php the_date( 'M j' ); ?></span> | <?php echo $amount_of_time_to_read; ?>min read</p>
</div>
</div>
</a>
<?php endwhile; ?>
<?php
// You need to tweak this function, it shouldn't be needing a $loop var to work
// paste the function here and may be we will take a look at that
// pagination_bar( $loop );
the_posts_pagination();
?>
<?php else : ?>
<?php // No Posts Found ?>
<?php endif; ?>
Had to add this to my functions.php
add_rewrite_rule('^blog/page/([0-9]+)','index.php?pagename=blog&paged=$matches[1]', 'top');
I use the code below to exclude a category from my wordpress search results.
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
query_posts( "s=$s&paged=$paged&cat=-35" );
But i dont get the pagination at the end of results. How should i modify the search.php in order to show the pagination and exclude the category as well? Pagination works in search results if you remove the two lines i mentioned but i need them to exclude the category.
Below is the search.php code...any help appreciated.
<?php
/**
* The template for displaying search results pages.
*
* #link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
*
*
*/
get_header(); ?>
<div class="container">
<div class="row">
<?php
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
query_posts( "s=$s&paged=$paged&cat=-35" );
$archive_content_classes = apply_filters( 'islemag_archive_content_classes', array( 'islemag-content-left', 'col-md-9' ) );
?>
<div
<?php
if ( ! empty( $archive_content_classes ) ) {
echo 'class="' . implode( ' ', $archive_content_classes ) . '"'; }
?>
>
<div class="post-section islemag-template1">
<div class=" islemag-template1-posts smaller-nav no-radius">
<?php
echo '<div style="font-size:50px;">
Results</div>';
while ( $wp_query->have_posts() ) :
$wp_query->the_post();
$choosed_color = array_rand( $colors, 1 );
$category = get_the_category();
$postid = get_the_ID();
?>
<div class="col-md-3 col-xs-6">
<div class="panel panel-default">
<div class="panel-image text-left">
<figure>
<?php the_post_thumbnail();?>
</figure> <!-- End figure -->
</div>
<div class="panel-body text-left">
<span class="panel-shopname">
<a style="color:grey;" href="<?php the_permalink(); ?>">
<?php the_field('add_your_brand'); ?>
</a>
</span><h4 class="panel-promotitle"><?php the_title(); ?></h4>
</div>
<div class="panel-footer">
<div class="left-cell promo-price">
<?php the_field('product_price'); ?>
</div>
<div class="right-cell">
<a href="<?php the_permalink(); ?>" class="btn btn-sm btn-success
">Go <i class="fa fa-external-link-square" aria-hidden="true"></i></a>
</div>
</div>
</div>
</div>
<?php
endwhile;
?>
</div>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
you should paste below code to your active theme's function.php to exclude category.
function wcs_exclude_category_search( $query ) {
if ( is_admin() || ! $query->is_main_query() )
return;
if ( $query->is_search ) {
$query->set( 'cat', '-35' );
$query->set('paged', ( get_query_var('paged') ) ? get_query_var('paged') : 1 );
$query->set('posts_per_page',6);
}
}
add_action( 'pre_get_posts', 'wcs_exclude_category_search', 1 );
And add the_posts_navigation(); after endwhile; in your code.
Remove the_posts_navigation(); and add below code there
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'before_page_number' => '<span class="screen-reader-text">'.$translated.' </span>'
) );
I'm using stanleywp theme for WordPress to display some post, actually I've inserted 20 posts, but it shows only 10posts.
This is what I did:
Portfolio -> Portfolio categories -> I added "brands" category
Portfolio -> add new -> and I've added 20 posts and set "brands" category
when I go to .../portfolio-category/brands/ I should see all my 20 posts, but I see only 10.
How can I solve that?
This is taxonomy-portfolio_cats.php:
<?php
/**
* #package WordPress
*/
?>
<?php get_header(); ?>
<?php if (have_posts()) : ?>
<div class="container pt">
<div class="row mt">
<div class="col-lg-6 col-lg-offset-3 centered">
<h1><?php echo single_term_title(); ?></h1>
<hr>
<?php if(category_description()) { ?>
<?php echo category_description( ); ?>
<?php } ?>
</div>
</div>
<div class="row mt centered">
<?php $cont = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<div class="col-lg-4">
<?php if ( has_post_thumbnail()) : ?>
<a class="zoom green" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>
<?php if(bi_get_data('project_title', '5')) {?>
<p><?php the_title(); ?></p>
<?php } ?>
</div> <!-- /col -->
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
<?php endif; ?>
<?php get_footer(); ?>
I think it's due to the default pagination (10 posts per page): you could increase the value on Settings > Reading > Blog pages show at most, or insert the pagination after <?php wp_reset_query(); ?>, something like:
<?php
// Previous/next page navigation.
the_posts_pagination( array(
'prev_text' => __( 'Previous page', 'your-textdomain' ),
'next_text' => __( 'Next page', 'your-textdomain' ),
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'your-textdomain' ) . ' </span>',
) );
?>
Or if you want to change the number of posts per page only for that taxonomy archive you can use the pre_get_posts action:
function portfolio_cats_posts_per_page( $query ) {
if ( is_admin() || ! $query->is_main_query() )
return;
if ( is_tax( 'portfolio_cats' ) ) {
// Display all posts in one page
$query->set( 'posts_per_page', -1 );
}
}
add_action( 'pre_get_posts', 'portfolio_cats_posts_per_page', 1 );
I'm currently developing my own wordpress theme and so far so good. The problem is I'm using a permalink and a category. The category is inside the permalink. The following code is what I'm using (content.php):
<?php if ( has_tag ('half_half') ) : ?>
<div class="gridHalves">
<article class="project" >
<a class="projectLink" href="<?php the_permalink(); ?>">
<div class="projectwrapper">
<div class="projectOverlayInset">
<div class="projectOverlay">
<div class="projectInfo">
<h4 class="categorie"><?php the_category(', '); ?></h4>
<h2 class="onderwerp"><?php the_title(); ?></h2>
<p class="writer">Written by <strong><?php the_author(); ?></strong></p>
</div>
</div>
</div>
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} ?>
</div>
</a>
</article>
</div>
<?php endif; ?>
The following is happening when I leave the_category in there:
If i leave the_category tag out everything is working fine. I've already checked the function in wp-includes of the_category but couldn't find anything about the permalink. So any suggestions? My loop is the following:
<?php get_header(); ?>
<main id="projectengrid" class="gridmenu-closed">
<section class="gridRightSmall">
<?php if ( have_posts() ) : ?>
<?php
// Start the loop.
while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
// End the loop.
endwhile;
// Previous/next page navigation.
the_posts_pagination( array(
'prev_text' => __( 'Previous page', 'twentyfifteen' ),
'next_text' => __( 'Next page', 'twentyfifteen' ),
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyfifteen' ) . ' </span>',
) );
// If no content, include the "No posts found" template.
else :
get_template_part( 'content', 'none' );
endif;
?>
</section>
</main><!-- .site-main -->
<?php get_footer(); ?>
I left the post navigation in there because I want to use it later on.
Hope someone knows the solution to this! Seems like I'm having some nested loops in there!
Kind regards,
Wouter
If you need any additional info please let me know!