WordPress.org

Ready to get started?Download WordPress

Forums

Having a page only show posts from a specific category (19 posts)

  1. Sutton74
    Member
    Posted 1 year ago #

    I have a website, and it currently runs off of three different themes. Well I got the functionality working for it so that its a portfolio page, and then you can go to the blog, and get a blog layout as well.

    And I got it so that the blog only shows posts under the category blog....however, when you click on the entry, you go to the entry page for the blog, and it'll have Next and Previous titles on the top of the blog....and those will let you go Next to hidden posts and posts I generally don't want the public to see (client proofs and such)

    My website is located at http://zsuttonphoto.com. As you can see, its very portfolio based. But when you click blog (http://zsuttonphoto.com/blog/) it maintains the format, while making it vertical scroll, with blog entries.

    Well my theme is unique in the fact that my portfolios are also post entries, that just follow a different format for display.

    So if you go to an individual blog post, such at this -- http://zsuttonphoto.com/actor-headshot-session-with-dorian-roberts/
    In the top left of the blog page, it says I can go back to Portrait Portfolio 1. I'd rather have it read it as though there are no other older entries, as I only want it to pull entries from the 'Blog' category...not all categories.

    I know, this is confusing, but I don't really know of a better way to tell it. Does anyone know how to make it so the top of my blog entries page only ready from the Category 'Blog'?

  2. Sutton74
    Member
    Posted 1 year ago #

    Its worth noting that my individual entries are on a separate theme, so we can just hard wire it into the code without any issues elsewhere

  3. phe.le
    Member
    Posted 1 year ago #

    First, I doubt that your site is running under three different themes.

    Second, all public posts are viewable to all people. I would recommend you to set posts that you don't want to show to normal users as private. The other option would be to remove the next or previous posts from the single.php file to prevent them from displaying at all.

  4. Sutton74
    Member
    Posted 1 year ago #

    I assure you my website is running on three different themes. I designed them, afterall.

    But by setting them to private, aren't I making it so no one can view them but me? The ultimate goal is to make proof galleries, that clients will be able to direct link to and select photos they'd like to have edited.

  5. Sutton74
    Member
    Posted 1 year ago #

    And the general idea is to have the previous and next links on the top and bottom of individual posts, but making sure its only pulling entries from the category 'Blog'

  6. phe.le
    Member
    Posted 1 year ago #

    There is no reason to run a website under many different themes (I don't know if it is possible).

    You can certainly create a username and password with the ability to view private posts for your clients. You can also create them as pages instead of posts.

  7. Sutton74
    Member
    Posted 1 year ago #

    There is plenty of reason if you understood the functionality of my website. And while, I could narrow it down to two different themes, its unlikely I could have it all embraced under one theme.

    And I'd be unable to create them as pages due to the functionality of the site. I'd prefer to just have it so that my blog only pulls entries under the category 'Blog'. I know its possible, as I have that functionality within http://zsuttonphoto.com/Blog/. I'm hoping someone here would be able to provide me with that single line of code that would make that its standard function.

  8. phe.le
    Member
    Posted 1 year ago #

    You can change the previous and next links to display posts from the same category or exclude all other categories.

    Open your single.php that display the above post, then edit the next and previous php codes:

    http://codex.wordpress.org/Template_Tags/previous_post_link
    http://codex.wordpress.org/Template_Tags/next_post_link

    For example: <?php next_post_link(,,TRUE,); ?> to display next posts in the same category.

  9. Sutton74
    Member
    Posted 1 year ago #

    My navigation is set up as an array, so I'm unable to just add a True statement for the category choice.

    if (have_posts()){
    					/* Display navigation to next/previous posts when applicable */
    					if (theme_get_option('theme_top_single_navigation')) {
    						theme_page_navigation(
    							array(
    							    'next_link' => theme_get_previous_post_link('&laquo; %link'),
    								'prev_link' => theme_get_next_post_link('%link &raquo;')
    							)
    						);
  10. phe.le
    Member
    Posted 1 year ago #

    You have a custom function to get the previous and next posts. Look for theme_page_navigation() in one of your theme files, probably in functions.php or other include ones.

    Or you can always make your own custom previous and next links:

    <div class="navigation">
    <div class="alignleft">
    << <?php previous_post_link(,,TRUE,); ?>
    </div>
    <div class="alignright">
    <?php next_post_link(,,TRUE,); ?> >></div>
    </div>

    Customize the the parameters for your needs.

  11. Sutton74
    Member
    Posted 1 year ago #

    Here is the code in functions.php --

    if (!function_exists('theme_page_navigation')){
    	function theme_page_navigation($args = '') {
    		$args = wp_parse_args($args, array('wrap' => true, 'prev_link' => false, 'next_link' => false));
    		$prev_link = $args['prev_link'];
    		$next_link = $args['next_link'];
    		$wrap = $args['wrap'];
    		if (!$prev_link && !$next_link) {
    			if (function_exists('wp_page_numbers')) { // http://wordpress.org/extend/plugins/wp-page-numbers/
    				ob_start();
    				wp_page_numbers();
    				theme_post_wrapper(array('content' => ob_get_clean()));
    				return;
    			}
    			if (function_exists('wp_pagenavi')) { // http://wordpress.org/extend/plugins/wp-pagenavi/
    				ob_start();
    				wp_pagenavi();
    				theme_post_wrapper(array('content' => ob_get_clean()));
    				return;
    			}
    			//posts
    			$prev_link = get_previous_posts_link(__('Newer posts <span class="meta-nav">&rarr;</span>', THEME_NS));
    			$next_link = get_next_posts_link(__('<span class="meta-nav">&larr;</span> Older posts', THEME_NS));
    		}
    		$content = '';
    		if ($prev_link || $next_link) {
    
    			$content = <<<EOL
    	<div class="navigation">
    		<div class="alignleft">{$next_link}</div>
    		<div class="alignright">{$prev_link}</div>
    	 </div>

    And idea on what to change to make it category based? I'd appreciate any help you can give me.

  12. phe.le
    Member
    Posted 1 year ago #

    I would replace the code in the single.php:

    /* Display navigation to next/previous posts when applicable */
    if (theme_get_option('theme_top_single_navigation')) {
    	theme_page_navigation(
    	array(
    	'next_link' => theme_get_previous_post_link('&laquo; %link'),
    	'prev_link' => theme_get_next_post_link('%link &raquo;')
    	)
    	);
    }

    With:

    <div class="navigation">
    	<div class="alignleft">
    		<?php previous_post_link('%link','<< %title',TRUE,''); ?>
    	</div>
    	<div class="alignright">
    		<?php next_post_link('%link','%title  >>',TRUE,''); ?>
    	</div>
    </div>
  13. Sutton74
    Member
    Posted 1 year ago #

    Am I able to embed html into that, as it does have a while script.

    <?php
    				if (have_posts()){
    					/* Display navigation to next/previous posts when applicable */
    					if (theme_get_option('theme_top_single_navigation')) {
    						theme_page_navigation(
    							array(
    								'next_link' => theme_get_previous_post_link('&laquo; %link'),
    								'prev_link' => theme_get_next_post_link('%link &raquo;')
    							)
    						);
    					}
    
    					while (have_posts())
    					{
    						the_post();
    						get_template_part('content', 'single');
    						comments_template();
    					}
    
    					/* Display navigation to next/previous posts when applicable */
    					if (theme_get_option('theme_bottom_single_navigation')) {
    						theme_page_navigation(
    							array(
    								'next_link' => theme_get_previous_post_link('&laquo; %link'),
    								'prev_link' => theme_get_next_post_link('%link &raquo;')
    							)
    						);
    					}
    
    				} else {    
    
    					theme_404_content();
    
    				}
    			?>
  14. phe.le
    Member
    Posted 1 year ago #

    Yes, you need to end the php code before the html and start it again after.

    <?php
    	if (have_posts()){ ?>
    
    		<div class="navigation">
    			<div class="alignleft">
    				<?php previous_post_link('%link','<< %title',TRUE,''); ?>
    			</div>
    			<div class="alignright">
    				<?php next_post_link('%link','%title  >>',TRUE,''); ?>
    			</div>
    		</div>
    
    		<?php
    		while (have_posts())
    		{
    			the_post();
    			get_template_part('content', 'single');
    			comments_template();
    		}
    		?>
    
    		<div class="navigation">
    			<div class="alignleft">
    				<?php previous_post_link('%link','<< %title',TRUE,''); ?>
    			</div>
    			<div class="alignright">
    				<?php next_post_link('%link','%title  >>',TRUE,''); ?>
    			</div>
    		</div>
    
    	<?php } else {    
    
    		theme_404_content();
    
    	}
    ?>
  15. Sutton74
    Member
    Posted 1 year ago #

    Seems to work, thanks.

    However, it messes up the formatting pretty bad...Any idea on how to make the format unchanged while removing and posts not under the category 'Blog'?

    Old Way - http://i.imgur.com/G4LOn.png

    New Way - http://i.imgur.com/AkYhd.png

  16. phe.le
    Member
    Posted 1 year ago #

    Sorry, I pasted you the code with the the starting and ending php. Just replace part from "if (have_posts()){ ?>" to "}" with the same part in single.php:

    if (have_posts()){ ?>
    
    		<div class="navigation">
    			<div class="alignleft">
    				<?php previous_post_link('%link','« %title',TRUE,''); ?>
    			</div>
    			<div class="alignright">
    				<?php next_post_link('%link','%title  »',TRUE,''); ?>
    			</div>
    		</div>
    
    		<?php
    		while (have_posts())
    		{
    			the_post();
    			get_template_part('content', 'single');
    			comments_template();
    		}
    		?>
    
    		<div class="navigation">
    			<div class="alignleft">
    				<?php previous_post_link('%link','<< %title',TRUE,''); ?>
    			</div>
    			<div class="alignright">
    				<?php next_post_link('%link','%title  >>',TRUE,''); ?>
    			</div>
    		</div>
    
    	<?php } else {    
    
    		theme_404_content();
    
    	}

    If it doesn't work, paste your single.php file using http://pastebin.com/

  17. Sutton74
    Member
    Posted 1 year ago #

    Still loses the format :-\

    Thanks for your help with this issue BTW

    http://pastebin.com/P5vu48j8

  18. phe.le
    Member
    Posted 1 year ago #

    I viewed the source code of your current single post. There are some weird auto-generated DIVs around the previous and next post links:

    <div class="BlogCSSpost">
    	<div class="BlogCSSpost-tl"></div>
    	<div class="BlogCSSpost-tr"></div>
    	<div class="BlogCSSpost-bl"></div>
    	<div class="BlogCSSpost-br"></div>
    	<div class="BlogCSSpost-tc"></div>
    	<div class="BlogCSSpost-bc"></div>
    	<div class="BlogCSSpost-cl"></div>
    	<div class="BlogCSSpost-cr"></div>
    	<div class="BlogCSSpost-cc"></div>
    	<div class="BlogCSSpost-body">
    		<div class="BlogCSSpost-inner BlogCSSarticle">
    			<div class="BlogCSSpostcontent">
    				<!-- article-content -->
    				<div class="navigation">
    					<div class="alignleft">« <a href="http://zsuttonphoto.com/model-photoshoot-with-sita/" title="Model Photoshoot with Sita Huber" rel="prev">Model Photoshoot with Sita Huber</a></div>
    					<div class="alignright"></div>
    				</div>
    				<!-- /article-content -->
    			</div>
    			<div class="cleared"></div>
    		</div>
    		<div class="cleared"></div>
    	</div>
    </div>

    I would try to wrap the new previous and next post links with the above DIVs.

    if (have_posts()){ ?>
    
    	<div class="BlogCSSpost">
    	<div class="BlogCSSpost-tl"></div>
    	<div class="BlogCSSpost-tr"></div>
    	<div class="BlogCSSpost-bl"></div>
    	<div class="BlogCSSpost-br"></div>
    	<div class="BlogCSSpost-tc"></div>
    	<div class="BlogCSSpost-bc"></div>
    	<div class="BlogCSSpost-cl"></div>
    	<div class="BlogCSSpost-cr"></div>
    	<div class="BlogCSSpost-cc"></div>
    	<div class="BlogCSSpost-body">
    		<div class="BlogCSSpost-inner BlogCSSarticle">
    			<div class="BlogCSSpostcontent">
    				<!-- article-content -->
    				<div class="navigation">
    					<div class="alignleft">
    						<?php previous_post_link('%link','« %title',TRUE,''); ?>
    					</div>
    					<div class="alignright">
    						<?php next_post_link('%link','%title  »',TRUE,''); ?>
    					</div>
    				</div>
    				<!-- /article-content -->
    			</div>
    			<div class="cleared"></div>
    		</div>
    		<div class="cleared"></div>
    	</div>
    	</div>
    
    	<?php
    	while (have_posts())
    	{
    		the_post();
    		get_template_part('content', 'single');
    		comments_template();
    	}
    	?>
    
    	<div class="BlogCSSpost">
    	<div class="BlogCSSpost-tl"></div>
    	<div class="BlogCSSpost-tr"></div>
    	<div class="BlogCSSpost-bl"></div>
    	<div class="BlogCSSpost-br"></div>
    	<div class="BlogCSSpost-tc"></div>
    	<div class="BlogCSSpost-bc"></div>
    	<div class="BlogCSSpost-cl"></div>
    	<div class="BlogCSSpost-cr"></div>
    	<div class="BlogCSSpost-cc"></div>
    	<div class="BlogCSSpost-body">
    		<div class="BlogCSSpost-inner BlogCSSarticle">
    			<div class="BlogCSSpostcontent">
    				<!-- article-content -->
    				<div class="navigation">
    					<div class="alignleft">
    						<?php previous_post_link('%link','« %title',TRUE,''); ?>
    					</div>
    					<div class="alignright">
    						<?php next_post_link('%link','%title  »',TRUE,''); ?>
    					</div>
    				</div>
    				<!-- /article-content -->
    			</div>
    			<div class="cleared"></div>
    		</div>
    		<div class="cleared"></div>
    	</div>
    	</div>
    
    <?php } else {    
    
    	theme_404_content();
    
    }

    If it doesn't work this time, I'll leave this to someone else.

  19. Sutton74
    Member
    Posted 1 year ago #

    You're the man.

    Thanks a ton!

Topic Closed

This topic has been closed to new replies.

About this Topic