Add custom shortcode into the template
-
Hello,
I’m having trouble inserting a custom PHP code from another plugin into the template file.
On the linked page you can see the example.
It has basic structure:– title
– featured image (if any)
– excerpt
– read moreNow, I want to add some custom fields, but I guess I need to edit more than just a template file, right?
Can you, please, provide me some support?
I need to add <?php rw_the_post_rating();?> shortcode.
So far, I have tried inserting it like this:
$lcp_display_output .= rw_the_post_rating();But this is not the result I wanted, the ratings need to go below each post.
Thanks in advance
The page I need help with: [log in to see the link]
-
Hi @olessons
So the code you inserted into your template works, that is good, now you only need to adjust the placement so that the end result is exactly what you want.
To display your ratings below each list element you can insert a
<br>tag before your custom code:$lcp_display_output .= '<br>' . rw_the_post_rating();Or you could wrap your custom code with additional tags and then style the result with css:
$lcp_display_output .= '<div class="example">' . rw_the_post_rating() . '</div>';Hope this is helpful.
-
This reply was modified 8 years, 3 months ago by
zymeth25.
Hello @zymeth25, thank you for your reply.
The problem stays the same, with <br> or any other div wrapper.
Here’s the code for whole template:
<?php /* Plugin Name: List Category Posts - Template "Default" Plugin URI: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/ Description: Template file for List Category Post Plugin for WordPress which is used by plugin by argument template=value.php Version: 0.9 Author: Radek Uldrych & Fernando Briano Author URI: http://picandocodigo.net http://radoviny.net */ /* Copyright 2009 Radek Uldrych (email : verex@centrum.cz) Copyright 2009-2015 Fernando Briano (http://picandocodigo.net) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /** * The format for templates changed since version 0.17. Since this * code is included inside CatListDisplayer, $this refers to the * instance of CatListDisplayer that called this file. */ /* This is the string which will gather all the information.*/ $lcp_display_output = ''; // Show category link: $lcp_display_output .= $this->get_category_link('strong'); // Show the conditional title: $lcp_display_output .= $this->get_conditional_title(); /* Posts Loop * * The code here will be executed for every post in the category. As * you can see, the different options are being called from functions * on the $this variable which is a CatListDisplayer. * * CatListDisplayer has a function for each field we want to show. So * you'll see get_excerpt, get_thumbnail, etc. You can now pass an * html tag as a parameter. This tag will sorround the info you want * to display. You can also assign a specific CSS class to each field. */ global $post; while ( have_posts() ): the_post(); //Add 'starting' tag. Here, I'm using an unordered list (ul) as an example: $lcp_display_output .= '<div class="web-div">'; $lcp_display_output .= '<div class="web-div-inner"'; //Show the title and link to the post: $lcp_display_output .= $this->get_post_title($post, 'lcp_post'); //Thumbnail div $lcp_display_output .= '<div class="web-img">'; //Post Thumbnail $lcp_display_output .= $this->get_thumbnail($post); //End of thumbnail div $lcp_display_output .= '</div>'; /** * Post content - Example of how to use tag and class parameters: * This will produce:<div class="lcp_excerpt">The content</div> */ $lcp_display_output .= $this->get_excerpt($post, 'p'); // Star Rating $lcp_display_output .= '<div class="example">' . rw_the_post_rating() . '</div>'; $lcp_display_output .= '</div>'; // Get Posts "More" link: $lcp_display_output .= $this->get_posts_morelink($post, 'a', 'read_more'); //Show comments: $lcp_display_output .= $this->get_comments($post); //Show date: $lcp_display_output .= ' ' . $this->get_date($post); //Show date modified: $lcp_display_output .= ' ' . $this->get_modified_date($post); //Show author $lcp_display_output .= $this->get_author($post); //Custom fields: $lcp_display_output .= $this->get_custom_fields($post); /** * Post content - Example of how to use tag and class parameters: * This will produce:<p class="lcp_content">The content</p> */ $lcp_display_output .= $this->get_content($post, 'p', 'lcp_content'); // Close the wrapper I opened at the beginning: $lcp_display_output .= '</div>'; endwhile; // If there's a "more link", show it: $lcp_display_output .= $this->get_morelink(); // Get category posts count $lcp_display_output .= $this->get_category_count(); //Pagination $lcp_display_output .= $this->get_pagination(); $this->lcp_output = $lcp_display_output;Ok @olessons, I had a closer look at your website and the code you have shared. First, there are a couple things you need to fix:
- This line doesn’t work:
$lcp_display_output .= $this->get_post_title($post, 'lcp_post');, I assume you wantedlcp_postto be a class, but you forgot to pass html tag as an argument. If you would like the title to be wrapped withh1you could try this:$lcp_display_output .= $this->get_post_title($post, 'h1', 'lcp_post'); - You have a bug on this line:
$lcp_display_output .= '<div class="web-div-inner"';, you forgot about>, please change it to$lcp_display_output .= '<div class="web-div-inner">';
Now, to fix your positioning problem I have to say this has nothing to do with List Category Posts, the problem is you chose a wrong shortcode from the ones described in rating widget documentation. You chose
rw_the_post_ratingwhich OUTPUTS the rating, what you should have used isrw_get_post_ratingwhich RETURNS the rating.To resolve all your issues, first fix the 2 problems I described and then try your template with
rw_get_post_rating.-
This reply was modified 8 years, 3 months ago by
zymeth25.
-
This reply was modified 8 years, 3 months ago by
zymeth25.
-
This reply was modified 8 years, 3 months ago by
zymeth25.
-
This reply was modified 8 years, 3 months ago by
zymeth25.
-
This reply was modified 8 years, 3 months ago by
zymeth25.
-
This reply was modified 8 years, 3 months ago by
Kathryn Presner.
-
This reply was modified 8 years, 3 months ago by
zymeth25.
Thank you for your support, works like charm
-
This reply was modified 8 years, 3 months ago by
The topic ‘Add custom shortcode into the template’ is closed to new replies.