WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Show content from single.php in category.php (6 posts)

  1. mgkoller
    Member
    Posted 1 year ago #

    I am using WordPress 3.5.1. / Twenty Twelve Theme
    I would like to show all the content I have in single.php to show in category.php.
    I have it working by using the second code block example, but I assume there is a better function to use.
    The following code below displays custom fields inside the <header class="entry-header"> in single.php (this is the only content displayed in a single post)

    <?php echo get_post_meta($post->ID, "user_submit_starttime", true); ?>
    <?php echo get_post_meta($post->ID, "user_submit_endtime", true); ?>
    <?php echo get_post_meta($post->ID, "user_submit_location", true); ?>

    The following code is only what I want to show up in categories.php,
    So far I have the following code (same as the above code, but formatted differently) setup inside the category.php in the "/* Start the Loop */ "

    $metastime = get_post_meta($post->ID,'user_submit_starttime',true);
    echo '<a class="metastime">'.$metastime.'</a>';
    $metaetime = get_post_meta($post->ID,'user_submit_endtime',true);
    echo '<a class="metaetime">'.$metaetime.'</a>';
    $metaloc = get_post_meta($post->ID,'user_submit_location',true);
    echo '<a class="metaloc">'.$metaloc.'</a>';

    It works but I assume there is a better function to use. Like the the following?

    get_template_part( 'content', get_post_format() );
  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Do not edit the Twenty Twelve theme. It is the current default WordPress theme and having access to an original, unedited, copy of the theme is vital in many situations. First create a child theme for your changes. Or install a custom CSS plugin.

  3. mgkoller
    Member
    Posted 1 year ago #

    I didn't ask whether editing twenty twelve is good or bad (I have it backed up anyways), I also didn't ask about using unnecessary plugins like a css editor plugin (using Less/Sass is much better). Also I'm testing this locally not in production.

    I just want to know how I can use get_template_part( 'content', get_post_format() ); (which calls content.php) instead of hardcoding a php construct inside the category.php loop.

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    I have it backed up anyways

    Doesn't matter. We're the ones who have to try and help you pick up the pieces when your site falls down and you have no way to get it back up again. If you do not want to create a child theme, then fork Twenty Twelve and re-upload a fresh, unpacked, copy of the Twenty Twelve folder to wp-content/themes using FTP or whatever file management application your host provides.
    http://wordpress.org/themes/twentytwelve

  5. mgkoller
    Member
    Posted 1 year ago #

    First I already have a "fresh, unpacked" copy of twenty twelve, second I'm not even going to use twenty twelve as a parent theme. (I'm using - http://underscores.me/), thirdly I'm working in MAMP so a hosting problem wouldn't even be possible.

    To go back to the original question I assume using get_template_part( 'content', get_post_format() ); I have to add the custom field code into the perfect block of code specific to the archive page, would it be <?php if ( is_single() ) : ?> in content.php?

  6. esmi
    Forum Moderator
    Posted 1 year ago #

    I already have a "fresh, unpacked" copy of twenty twelve

    Is this on your site? In that case, are you working on a fork of the default theme?

Topic Closed

This topic has been closed to new replies.

About this Topic