• Resolved JanDieckmann

    (@jandieckmann)


    I am a little bit confused because I thought this would be a simple task but I fail while implementing. I found similar requests and howtos, but either there are to old and don’t fit into the latest codes or I don’t understand them. And I also don’t succeed to change the code by myself based on my little knowledge and using trial and error.

    It is just the wish to get a list of all posts inside a specified category that shows only the titles which should be linked. In other words: if I add a category to the menu, I will see the whole posts, one after the other, if I chose this link in the navigation. So it should be done with a little modification of the category.php, in my case the one from twenty twelve, right?:

    <?php
    /**
     * The template for displaying Category pages
     *
     * Used to display archive-type pages for posts in a category.
     *
     * @link https://codex.www.ads-software.com/Template_Hierarchy
     *
     * @package WordPress
     * @subpackage Twenty_Twelve
     * @since Twenty Twelve 1.0
     */
    
    get_header(); ?>
    
    	<section id="primary" class="site-content">
    		<div id="content" role="main">
    
    		<?php if ( have_posts() ) : ?>
    			<header class="archive-header">
    				<h1 class="archive-title"><?php printf( __( 'Category Archives: %s', 'twentytwelve' ), '<span>' . single_cat_title( '', false ) . '</span>' ); ?></h1>
    
    			<?php if ( category_description() ) : // Show an optional category description ?>
    				<div class="archive-meta"><?php echo category_description(); ?></div>
    			<?php endif; ?>
    			</header><!-- .archive-header -->
    
    			<?php
    			/* Start the Loop */
    			while ( have_posts() ) : the_post();
    
    				/* Include the post format-specific template for the content. If you want to
    				 * this in a child theme then include a file called called content-___.php
    				 * (where ___ is the post format) and that will be used instead.
    				 */
    				get_template_part( 'content', get_post_format() );
    
    			endwhile;
    
    			twentytwelve_content_nav( 'nav-below' );
    			?>
    
    		<?php else : ?>
    			<?php get_template_part( 'content', 'none' ); ?>
    		<?php endif; ?>
    
    		</div><!-- #content -->
    	</section><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    Another idea is to get such a list as a sub menu, when I hover the cursor over the category link in the nav menu. Is this possible to?

    I researched now and found out that there are also plugins to create list-like pages but I am not sure what might be a better solution to reach my goal. That is why I finally decided to ask for suggestions and help here.

    Bye
    Jan

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    The code to generate a simple link in the loop with no content:
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    You can wrap that with ul and li tags, p tags, div tags, or just put a br tag afterwards.
    This can replace the get_template_part() line of categories.php.

    You can do the rollover thing on the nav menu as well, but that will take some more coding knowledge than it sounds like you have. The sub menu list is initially set with no visibility. On the rollover event, javascript changes the visibility. On rollout, the container is made not visible again. The are various nav menu filters with which you can insert the menu list below the existing category link.

    Thread Starter JanDieckmann

    (@jandieckmann)

    Thank you, bcworks.

    The code you gave me makes sense to me but the simple replacement doesn’t work. I get a Parse error: syntax error, unexpected ‘<‘ in /wp-content/themes/twentytwelve/category.php on line 36.

    So, something just like the_title(); instead is working. I don’t find the way to add the links. Please one more hint ??

    Moderator bcworkz

    (@bcworkz)

    The code I provided, of itself, is correct. I neglected to include the ?> and <?php tags front and back to take the flow out of PHP mode and into HTML mode. That’s probably all it is. Sorry for any confusion.

    To be clear, I should have provided this to replace that one line:
    ?><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a><?php

    Moderator bcworkz

    (@bcworkz)

    Oh, one more thing. You shouldn’t edit the twentytwelve theme, your changes will be lost when the theme updates. Create a child theme and copy category.php into the child. Edit that copy and your changes will be protected.

    Thread Starter JanDieckmann

    (@jandieckmann)

    Perfect!

    Thank you a lot for this explanation and hint, it helped my. And not only I could make the change I want I also got a little more comprehension of the code.

    Bye
    Jan

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘List all posts inside a category’ is closed to new replies.