How to display tags and category in Random Post

Begonnen von Dorian, 06. November 2018, 12:29:00

Vorheriges Thema - Nächstes Thema

Dorian

Hi Powie,
 
Simple question!
 
I\'ve been using your Random Post plugin on my website for some time, and it works really well. All I display is a single page containing the \"random post\" shortcode.
 
However, since I updated the plugin recently, I discovered that the randomly displayed post doesn\'t show its categories, or tags, anymore...
 
How can I bring this back? What template file should I modify?
 
It\'s probably very simple to do, but I\'m not very good at programming...
 
Thanks in advance.
 
Dorian

Powie

Hmm...... i think that\'s not related to the plugin. It should be displayed as configured or made by the WP theme....

Dorian

Hi Powie,
 
Thanks for your reply, and sorry for this late follow-up.
 
I find it a little strange that the issue would come from my WP theme, as I haven\'t modified it lately...
 
Would you have any idea what template file I should modify, and in what way, to fix this issue?
 
To give you more background, here\'s my setup:
 
- I\'ve configured my website to simply display a certain page as a homepage;
 
- The content of that page is simply the random post shortcode, to display one single random post.
 
So, as this is a page, I\'ve looked at the \"page.php\" file in my theme folder (called \"Readly\").
 
Here is the code:
 

<?php
/**
 * The template for displaying all 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 Readly
 * @since Readly 1.0
 */
get_header(); ?>
<div id=\"primary\" class=\"content-area\">
   <div id=\"content\" class=\"site-content\" role=\"main\">
      <?php while (have_posts()): the_post(); ?>
         <?php get_template_part(\'content\', \'page\'); ?>
         <?php
            // If comments are open or we have at least one comment, load up the comment template
            if (comments_open() || \'0\' != get_comments_number())
               comments_template();
         ?>
      <?php endwhile; // end of the loop. ?>
   </div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

 
However, as it seems that this file summons up the \"content\" part of the template, I\'m wondering whether the actual theme file to modify should be the one named \"Content.php\" in the same folder? This is the code:
 

<?php
/**
 * @package Readly
 * @since Readly 1.0
 */
?>
<article id=\"post-<?php the_ID(); ?>\" <?php post_class(); ?>>
<?php
$post_format = get_post_format();
if ($post_format != \'quote\'):
?>
<header class=\"entry-header\">
   <div class=\"entry-meta\">
      <?php readly_posted_on(); ?>
      <?php if (!post_password_required() && (comments_open() && \'0\' != get_comments_number())): ?>
         <span class=\"sep\"> &#183; </span>
         <span class=\"comments-link\"><?php comments_popup_link(__(\'Leave a comment\', \'readly\'), __(\'1 Comment\', \'readly\'), __(\'% Comments\', \'readly\')); ?></span>
      <?php endif; ?>
      <?php edit_post_link(__(\'Edit\', \'readly\'), \'<span class=\"sep\"> &#183; </span><span class=\"edit-link\">\', \'</span>\'); ?>
   </div><!-- .entry-meta -->
   <?php if (\'link\' !== get_post_format()): ?>
   <h1 class=\"entry-title\">   
      <a href=\"<?php the_permalink(); ?>\" title=\"<?php echo esc_attr(sprintf(__(\'Permalink to %s\', \'readly\'), the_title_attribute(\'echo=0\'))); ?>\" rel=\"bookmark\"><?php the_title(); ?></a>
   </h1>
   <?php endif; ?>
</header><!-- .entry-header -->
<?php endif; ?>
<?php
if (\'audio\' == $post_format) readly_formatted_audio();
elseif (\'video\' == $post_format) readly_formatted_video();
elseif (\'image\' == $post_format) readly_formatted_image();
elseif (\'gallery\' == $post_format) {
   $result = wpShower::getContentAndAttachments();
   echo readly_formatted_gallery($result[\'attachments\'], \'readly_big\');
}
?>
<div class=\"entry-content\">
   <?php
   if (\'gallery\' == $post_format) echo $result[\'content\'];
   else the_content(__(\'Read More<span></span>\', \'readly\'));
   ?>
</div><!-- .entry-content -->
<?php if (\'post\' == get_post_type()): // Hide category and tag text for pages on Search ?>
   <?php if ($post_format == \'quote\'): ?>
   <footer class=\"entry-meta\">
      <?php readly_posted_on(); ?>
      <?php if (!post_password_required() && (comments_open() && \'0\' != get_comments_number())): ?>
         <span class=\"sep\"> &#183; </span>
         <span class=\"comments-link\"><?php comments_popup_link(__(\'Leave a comment\', \'readly\'), __(\'1 Comment\', \'readly\'), __(\'% Comments\', \'readly\')); ?></span>
      <?php endif; ?>
      <?php edit_post_link(__(\'Edit\', \'readly\'), \'<span class=\"edit-link\">\', \'</span>\'); ?>
   </footer><!-- .entry-meta -->
   <?php endif; ?>
<?php endif; ?>
<div class=\"article-separator\">j j j</div>
</article><!-- #post-## -->

 
Or could it be... \"Content-single.php\"?
 

<?php
/**
 * @package Readly
 * @since Readly 1.0
 */
?>
<article id=\"post-<?php the_ID(); ?>\" <?php post_class(); ?>>
<header class=\"entry-header\">
   <div class=\"entry-meta\">
      <?php readly_posted_on(); ?>
   </div><!-- .entry-meta -->
   <?php if (\'link\' !== get_post_format()): ?>
   <h1 class=\"entry-title\"><?php the_title(); ?></h1>
   <?php endif; ?>
</header><!-- .entry-header -->
<?php
$post_format = get_post_format();
if (\'audio\' == $post_format) readly_formatted_audio();
elseif (\'video\' == $post_format) readly_formatted_video();
elseif (\'image\' == $post_format) readly_formatted_image();
elseif (\'gallery\' == $post_format) {
   $result = wpShower::getContentAndAttachments();
   echo readly_formatted_gallery($result[\'attachments\'], \'readly_big\');
}
?>
<div class=\"entry-content\">
   <?php
   if (\'gallery\' == $post_format) echo $result[\'content\'];
   else the_content(__(\'Read More<span></span>\', \'readly\'));
   ?>
   <?php wp_link_pages(array(\'before\' => \'<div class=\"page-links\">\'.__(\'Pages:\', \'readly\'), \'after\' => \'</div>\')); ?>
</div><!-- .entry-content -->
<footer class=\"entry-meta\">
   <?php
      /* translators: used between list items, there is a space after the comma */
      $category_list = get_the_category_list(__(\', \', \'readly\'));
      /* translators: used between list items, there is a space after the comma */
      $tag_list = get_the_tag_list(\'\', __(\', \', \'readly\'));
      if (!readly_categorized_blog()) {
         // This blog only has 1 category so we just need to worry about tags in the meta text
         if (\'\' != $tag_list) {
            $meta_text = __(\'Tagged %2$s\', \'readly\');
         }
         else {
            $meta_text = \'\';
         }
      }
      else {
         // But this blog has loads of categories so we should probably display them here
         if (\'\' != $tag_list) {
            $meta_text = __(\'Posted in %1$s<span class=\"sep\"> &#183; </span>Tagged %2$s\', \'readly\');
         }
         else {
            $meta_text = __(\'Posted in %1$s\', \'readly\');
         }
      } // end check for categories on this blog
      printf(
         $meta_text,
         $category_list,
         $tag_list,
         get_permalink(),
         the_title_attribute(\'echo=0\')
      );
   ?>
   <?php edit_post_link(__(\'Edit\', \'readly\'), \'<span class=\"edit-link\">\', \'</span>\'); ?>
</footer><!-- .entry-meta -->
</article><!-- #post-## -->

 
Or \"Single.php\"? It says that this is the template \"for displaying all single posts\", which is what my page is doing...
 

<?php
/**
 * The Template for displaying all single posts.
 *
 * @package Readly
 * @since Readly 1.0
 */
get_header(); ?>
<div id=\"primary\" class=\"content-area\">
   <div id=\"content\" class=\"site-content\" role=\"main\">
   <?php while (have_posts()): the_post(); ?>
      <?php get_template_part(\'content\', \'single\'); ?>
      <?php readly_content_nav(\'nav-below\'); ?>
      <?php
         // If comments are open or we have at least one comment, load up the comment template
         if (comments_open() || \'0\' != get_comments_number())
            comments_template();
      ?>
   <?php endwhile; // end of the loop. ?>
   </div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

 
Sorry for the many copy-pastes, but I\'m really not very good at finding the root of such problems.
 
Please let me know if you have any advice.
 
Best,
 
Dorian

Powie

So.. You got right!! I\'ve checked this and it\'s true that at this time no stylings or any other things will shown with the plugin. It can only display Title and Body at this time.

dorian

Hi Powie,
 
In this case, would there be a way for me to go back to the previous version of your plugin?
 
It worked perfectly fine (displaying tags + categories) before I updated it :D
 
Please let me know.

all your base are belong to us