wordpress theme page not showing plugin gallery - wordpress

I am new to Wordpress. I am trying to build a theme from scratch.
I created the page.php which is the following:
<?php
/**
* The template for displaying pages
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages and that
* other "pages" on your WordPress site will use a different template.
*
* #package nameofpackage
*/
get_header(); ?>
<?php get_footer(); ?>
I also installed the NextGen plugin.
I created a new page, and use the "add Gallery" button of NextGen; i ended up with
[ngg src="galleries" ids="1" display="basic_thumbnail"]
inside the text section of the page (the visual section shows the plugin logo in a box).
When i tried to preview the result i only get the header and the footer with nothing in the middle; the inspector shows no presence of the code related to the gallery.
If i try the same thing with ThemeFifteen it works.
So my question is: is there something i need to include in the function.php that allows my theme to include the output of the plugin in the page? thx

You're missing the WP loop and the_content(), so its absolutely normal to not see anything between the header and the footer. You need something like this for example:
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'loop-templates/content', 'page' );//calling the folder with your loop templates ?>
<?php
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
<?php endwhile; // end of the loop. ?>
And inside your loop template something like :
<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->
<?php echo get_the_post_thumbnail( $post->ID, 'large' ); ?>
<div class="entry-content">
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'understrap' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php edit_post_link( __( 'Edit', 'understrap' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-footer -->
</article><!-- #post-## -->
This is very common way to structure your theme, but please spend some time on beginners tutorials about developing custom themes. It's very easy to get the basic concepts, you'll need couple of hours to get the idea ! This is just an example I want to stress on that, quick and dirty fix of your code would be:
<?php
/**
* The template for displaying pages
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages and that
* other "pages" on your WordPress site will use a different template.
*
* #package nameofpackage
*/
get_header(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; // end of the loop. ?>
<?php get_footer(); ?>

What you're looking for is do_shortcode() See the docs
Make sure to echo it as well.
<?php
get_header();
echo do_shortcode('[ngg src="galleries" ids="1" display="basic_thumbnail"]');
get_footer();
You could also use apply_filters() and pass in the 'the_content' hook. That would render your shortcode with the same hooks/filters as used br the wysiwyg editor in the back-end but ultimately it's just using do_shortcode() behind the scenes.
<?php
get_header();
echo apply_filters('the_content', '[ngg src="galleries" ids="1" display="basic_thumbnail"]');
get_footer();

Related

Remove Page Header from Blog Posts

I have a page-header that is getting copied over to all of my blog posts that I want to remove completely. I am removing it visually via CSS, but SEO crawlers are still picking it up via the tag.
I am using a standard wordpress them augmented with Elementor. Here is a screenshot of the SEO report.
And here is a screenshot of the actual HTML code
Let me know if any of you have any additional questions! Thank you for your help!
You can make a conditional statement that just outputs the title of the post if on single blog posts, so something like this
<div class="container clr page-header-inner">
<?php
// Return if page header is disabled
if ( oceanwp_has_page_header_heading() ) { ?>
<!-- check to see if single blog posts -->
<?php if (is_single()) : ?>
<h1><?php echo get_the_title(); ?></h1>
<!-- otherwise show the existing title format -->
<?php else: ?>
<<?php echo esc_attr( $heading ); ?> class="page-header-title clr"<?php oceanwp_schema_markup( 'headline' ); ?>><?php echo wp_kses_post( oceanwp_title() ); ?></<?php echo esc_attr( $heading ); ?>>
<?php endif; ?>
<?php get_template_part( 'partials/page-header-subheading' ); ?>
<?php } ?>
<?php if ( function_exists( 'oceanwp_breadcrumb_trail' ) ) {
oceanwp_breadcrumb_trail();
} ?>
</div><!-- .page-header-inner -->
you would have to replace the existing code

Co-Authors Plus Wordpress Plugin - List all the authors for same post

I want to display name of multiple authors on the front end like below
By John Doe,Linn Doe and Penny
In the back end I can add many users for the same post.But In the front end only the first author on the post shows up both for the byline and the bio. I'm using Twenty Thirteen theme and how to show all the user added in the back end in the front end?
this is my single.php file
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php twentythirteen_post_nav(); ?>
<?php comments_template(); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Incorporate Co-Authors Plus template tags into your theme
Other Solution:
In order to add add Co-Authors Plus support you must have access to edit the theme template. In order to display information about multiple authors on the fronted, you'll need to add the necessary Co-Authors Plus template tags to your single.php and other theme files.
Specifically for the bylines, you'll want to replace where it says something like:
<?php the_author(); ?>
With something like this:
<?php if ( function_exists( 'coauthors' ) ) { coauthors(); } else { the_author(); } ?>
That specific snippet will allow your theme to degrade gracefully when Co-Authors Plus isn't activated.
To show the authors with their posts link, you'll want to use something like:
<?php if ( function_exists( 'coauthors_posts_links' ) ) { coauthors_posts_links(); } else { the_author_posts_link(); } ?>
You can use the following code for the bios
<?php $coauthors = get_coauthors(); ?>
<?php foreach( $coauthors as $coauthor ): ?>
<center><div class="authbio">
<img src="<?php bloginfo('template_url'); ?>/images/<?php echo $coauthor->user_firstname; ?>.jpg" alt="" class="alignleft"/>
<?php $userdata = get_userdata( $coauthor->ID ); ?>
<?php if ( $userdata->user_description ) echo $userdata->user_description; ?>
</div></center>
<?php endforeach; ?>
Reference

How to add sidebar at single.php in Wordpress

I'm having a problem when it comes to adding sidebar at single.php. I already included
<?php get_sidebar(); ?>
But it seems to be appear below and the content(Blog post) still at the middle of the whole page. I've tried to check all of the previous forum but none of them helped me to figure this out.
Here's my single.php
<?php
/**
* The template for displaying all single posts.
*
* #package Tesseract
*/
get_header(); ?>
<div id="primary" class="full-width-page">
<main id="main" class="site-main" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'single' ); ?>
<?php tesseract_post_nav(); ?>
<?php
// If comments are open or we have at least one comment, load up the comment template
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
<?php comments_template(); ?>
<?php endwhile; // end of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
The most logical reason for this to happen is that there isn't enough room for both the main content and the sidebar to appear next to each other. Check the width of your sections in your stylesheet and make the necessary changes to the styles.
First of all you create the sidebar in the admin and then call that sidebar where you want.Following is the code for calling sidebar
<ul id="sidebar">
<?php dynamic_sidebar( 'right-sidebar' ); ?>
Use following link to know more about how to create a sidebar
https://codex.wordpress.org/Function_Reference/register_sidebar

Wordpress homepage with latest posts and Advanced Custom fields - How?

I'd like my homepage to display my latest posts which are portfolio projects of mine. Beneath these project thumbnails I've got my static content which I'm using the Repeater add-on from Advanced Custom Fields to grab. I cant get it all to work on the same page... either get the blog to work or the ACF stuff to work. Never both because one needs to be a designated static page and one needs to be a posts page. I don't understand how to tie it together and make it appear as one page.
I've experimented with the settings in the reading panel..
I've tried using front-page.php
I've read up on the WP hierarchy etc
I've tried using templates...
I've tried wp_reset_postdata(); which I read about elsewhere on Stack Overflow.
What settings must I use in the reading panel. Do I need to use a template file?
Here's the code I'm working with, I've split the code between templates and different files already, but just for ease of reading its all together here (maybe that's the right way to do it anyway, I wouldn't know..)
<!-- The posts/portfolio items -->
<?php get_header(); ?>
<div>
<?php if(have_posts()) : ?>
<ul>
<?php while ( have_posts() ) : the_post(); ?>
<li>
<!-- Permalink,title and post thumbnail here (omitted) -->
</li>
<?php endwhile; ?>
</ul>
<?php else: ?>
<h2>No Posts found</h2>
<?php endif; ?>
</div>
<!-- Now for the ACF Stuff -->
<?php if(get_field('care_list')): ?>
<?php while(has_sub_field('care_list')): ?>
<div class="grid_2 what-i-care-about gap">
<div class="important-img-container">
<?php the_sub_field('care_list_image'); ?>
</div>
<h3><?php the_sub_field('care_list_title'); ?></h3>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php get_footer(); ?>
Please help a frustrated learner! Thanks in advance.
It looks like you're going to need to add the post id of your 'home page' (the one with the ACF repeater on it) to the get_field() function like so:
<?php $post_id = **post_id_of_your_homepage_here**; ?>
<?php if(get_field('care_list', $post_id)): ?>
<?php while(has_sub_field('care_list')): ?>
<div class="grid_2 what-i-care-about gap">
<div class="important-img-container">
<?php the_sub_field('care_list_image'); ?>
</div>
<h3><?php the_sub_field('care_list_title'); ?></h3>
</div>
<?php endwhile; ?>
This is because the $post_id parameter defaults to the current post being brought up by wordpress, which means ACF is looking for the repeater on the last Portfolio item/post you are displaying. If you set the $post_id parameter to the ID of your homepage, ACF will instead look for the repeater on that page.
Source: http://www.advancedcustomfields.com/resources/functions/get_field/#parameters
If I'm understanding correctly, you have a bunch of posts and you want to display a list of them with title and post thumbnail on your homepage, and then display a custom field you've assigned to the homepage underneath the list of posts?
Step 1: Create a new page template by copying page.php, changing the name to homepage.php and adding this to the top:
<?php
/*
Template Name: Homepage
*/ ?>
Step 2: Crete a Wordpress page called "Homepage" and in the attributes module in the right sidebar of the page creation tool, select "Homepage" as your page template.
Step 3: In your reading settings, change the front page from posts page to "Homepage." Now your homepage is your page called "Homepage."
Step 4: Make something like this the full code on your new page template homepage.php. It will output your posts list followed by your page custom field:
<?php get_header(); ?>
<?php $the_query = new WP_Query( $args );
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_post_thumbnail(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php if(get_field('repeater_field_name')): ?>
<?php while(has_sub_field('repeater_field_name')): ?>
<?php the_sub_field('sub_field_1'); ?>
<?php endwhile; ?>
<?php endif; ?>
<?php get_footer(); ?>

Where is wordpress search page content generated?

I'm trying to style a search page in wordpress. In search.php I can style most of the page but then the following statement (which I got from the original uneditted page) generates the content.
<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
This ALMOST displays the page as I want it, but there are a few elements off the page, making it expand etc. I can't figure out what file is generating this content!
Using the instructions I created a content-search.php and change the line of code to this...
get_template_part( 'content', get_post_format() );
Which works...but it doesn't display much of anything because I don't know what to put in my page within seeing the original.
Anyone have any clue?
You can use a template part named post-search.php and can use it inside your search.php file like
get_template_part( 'post' , 'search')
but you have to create a php file inside your theme folder and name it post-search.php and inside this file just put the WordPress' loop i.e.
<?php while (have_posts()) : the_post(); ?>
<div class="post-entry clearfix"> <!-- Main wrapper -->
<div class="post-entry-content"> <!-- Post-entry-content -->
<h2><?php the_title(); ?></h2>
<div class="post-entry-date">Posted on <?php the_time('F Y') ?> with <?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></div>
<?php the_excerpt(); ?>
Read More ?
</div><!-- END of post-entry-content -->
</div><!--End of main wrapper -->
<?php endwhile; ?>
and your search.php could be something like this
<?php get_header(' '); ?>
<div id="post-wrap">
<div id="post-content">
<?php if (have_posts()) : ?>
<?php get_template_part( 'post' , 'search') ?> // This will load/include the file post-search.php and result will be displayed as formatted in this file
<?php else : ?>
<p>Sorry, it does not exist !</p>
<?php endif; ?>
</div><!-- END post-conten -->
<?php get_sidebar(' '); ?>
</div><!-- END post-wrap -->
<?php get_footer(' '); ?>
This is just an example, change div/h2 id/class names according to your theme css.
Note: I'm currently using this approach in one of my site and I've one file named 'post-entry.php' in my theme folder and in my every template file (index.php, search.php e.t.c) I just use this file by calling
<?php get_template_part( 'post' , 'entry') ?>

Resources