PDA

View Full Version : Post Inside Page...



Mike1
03-20-2012, 11:58 AM
Hi All,

I have created a page and would like to insert posts from specific category inside that page...

I know I can just add link to that category in navigation bar but I would like to add some
images and text that will show all the time on that page while posts from specific category
will be updated...

Maybe best way to do this is create a new template that will include posts from specific
category... but I have no idea how to do this and I did have a look trough forum and
wp forum but it is too complicated for me...

Can someone help,

Thank you in advance...

Dan Nickerson
03-20-2012, 06:25 PM
Just look at related posts plugins. You can just insert shortcodes into a page to show posts.

Or look at this solution
http://wordpress.org/support/topic/display-the-posts-of-one-category-in-a-page-solved

Google this..

display posts from single category in page template

Mike1
03-21-2012, 04:33 AM
Hi Dan,

Thank you for quick reply I appreciate it...

I have created a page and saved it as story.php also I have added <?php /* Template Name: Story */ ?> at the very top of the page... (this page is a copy of index.php)...

Now I have a problem with this step:

COPY FROM WP FORUM:


NOW..to implement this code, make a template page (copy pages.php and rip out it's content but leave the
generic stuff like get_sidebar etc), and put this code (above) bang in the center.



which is mentioned on: http://wordpress.org/support/topic/display-the-posts-of-one-category-in-a-page-solved

Can you please help me do this step as I would not like to delete some of other functions Socrates Theme offers...

Copy of Socrates index.php code:


<?php /* Template Name: Story */ ?>
<?php

/**

* Socrates Premium Theme for Wordpress

* (c) 2010 Flying Monkey Media, Inc.

* http://www.socratestheme.com

* Version 2.2.15

*

* Development Team:

* Tim Golen (tg)

*

* @File index.php

*/

get_header();

include "topAd.php";

//include "sidebar.php";

//include "sidebar2.php";

$inpost1counter = 0;

$inpost2counter = 0;

$layout = get_option("layoutOptions");

if($layout['sidebar'] == 'styleBothSides.css') {

include "sidebar.php";

}

$topAd = get_option("socratesOptions");

?>



<div id="im-mainContent" class="im-mainContent">

<div id="post-" class="post">

<?php if (have_posts()) : ?>

<?php while (have_posts()) : the_post(); ?>

<div <?php post_class() ?> id="post-<?php the_ID(); ?>">



<?php

// if this is a page, then we might have to use h1 tags for the title instead of the default h2 tags

$titleTag = 'h2';

if (is_page()){

$titleTag = ($topAd['useh1page'] == 'on')?'h1':'h2';

}

?>



<<?php echo $titleTag; ?>><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></<?php echo $titleTag; ?>>

<?php

$custom_fields = get_post_custom($post->ID);

if($topAd['authonpage'] == 'on' ) { ?>

<div class="postAuthor">By <?php the_author_posts_link(); ?> on <?php the_time('l, F jS, Y') ?> | <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></div>

<?php } ?>





<div class="entry">

<?php

$topAd = get_option("socratesOptions");

if(($topAd['inpostad1'] != '' && !is_page() && $inpost1counter<$topAd['inpostadmaxrepeat']) && !$custom_fields['_mcf_postDisableInPostAd'][0]) {

if ($topAd['inpostposition'] != 'top'){

echo '<div id="socratesinpostad" style="float:'.$topAd['inpostposition'].'; display:block; padding:5px; margin:0;">'.stripslashes($topAd['inpostad1']).'</div>';

} else {

echo '<div id="socratesinpostad" style="display:block; padding:5px; margin:0;">'.stripslashes($topAd['inpostad1']).'</div><br />';

}

$inpost1counter++;

}

?>



<?php

$custom_fields = get_post_custom($post->ID);

// do we need to display custom text for the read more link?

$readMoreText = ($custom_fields['_mcf_postcustomreadmore'][0] != '')?$custom_fields['_mcf_postcustomreadmore'][0]:'Read More...';

?>

<?php the_content($readMoreText); ?>



<div class="entry-utility postmetadata">

<?php if ( count( get_the_category() ) ) : ?>

<span class="cat-links">

<?php printf( __( '<span class="%1$s">Posted in</span> %2$s', 'socrates' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?>

</span>

<span class="meta-sep">|</span>

<?php endif; ?>

<?php

$tags_list = get_the_tag_list( '', ', ' );

if ( $tags_list ):

?>

<span class="tag-links">

<?php printf( __( '<span class="%1$s">Tags</span> %2$s', 'socrates' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?>

</span>



<?php endif; ?>

<?php

$custom_fields = get_post_custom($post->ID);

if($topAd['authonpage'] == 'on' ) { ?><span class="meta-sep">|</span>

<span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'socrates' ), __( '1 Comment', 'socrates' ), __( '% Comments', 'socrates' ) ); ?></span><?php } ?>

<?php edit_post_link( __( 'Edit', 'socrates' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>

</div><!-- .entry-utility -->

</div>

</div>

<?php

if(($topAd['inpostad2'] != '' and !is_page() and $inpost2counter<$topAd['inpostad2maxrepeat']) && !$custom_fields['_mcf_postDisableInPostAd'][0]) {

echo '<div id="socratesinpostadbottom" style="clear: both; display: block;">'.stripslashes($topAd['inpostad2']).'</div><br>';

$inpost2counter++;

}

?>

<div class="commentsFrame"><?php comments_template() ?></div>

<?php endwhile; ?>



<div class="navigation">

<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>

<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>

</div>

<?php else : ?>

<h2 class="center">Not Found</h2>

<p class="center">Sorry, but you are looking for something that isn't here.</p>

<?php get_search_form(); ?><br />

<?php $args = array(

'smallest' => 8,

'largest' => 22,

'unit' => 'pt',

'number' => 45,

'format' => 'flat',

'separator' => ', ',

'orderby' => 'name',

'order' => 'ASC',

'link' => 'view',

'taxonomy' => 'post_tag',

'echo' => true ); ?>

<?php wp_tag_cloud( $args ); ?>

<?php endif; ?>

</div><!-- /posts -->

</div><!-- /im-mainContent -->



<?php

if($layout['sidebar'] != 'styleBothSides.css' || $layout['sidebar'] == 'styleDoubleRight.css') {

if ($layout['sidebar'] != 'styleNoSides.css'){

include "sidebar.php";

}

}

if ($layout['sidebar'] != 'styleNoSides.css'){

include "sidebar2.php";

}

?>



<div class="line"></div>





<?php get_footer(); ?>


and this is what I have to insert once code above is adjusted:


<?php
query_posts('cat=1');
while (have_posts()) : the_post();
the_content();
endwhile;
?>

Once again thank you for your time and help...

Dan Nickerson
03-21-2012, 12:40 PM
You didn't say where you wanted it but if it were me I'd put it above this code.

<div class="commentsFrame"><?php comments_template() ?></div>

Mike1
03-22-2012, 12:35 AM
You didn't say where you wanted it but if it were me I'd put it above this code.

<div class="commentsFrame"><?php comments_template() ?></div>




Hi Dan,

Thank you for quick reply...

When I do that.... Insert a code above

<div class="commentsFrame"><?php comments_template() ?></div>

and than check the page it looks broken and post from selected
category repeats infinity down the page...

How I Wold like this new page to look is:

----------------------------------------------------

Page Title

Page Content (some text I would put to explain what this page is about)

Posts from specific category

Footer

----------------------------------------------------

Once again thank you for your help...

Dan Nickerson
03-22-2012, 12:32 PM
Did you change the category ID#

Did you look into using a Related posts plugin?

Can you share a link?

Mike1
03-23-2012, 12:50 PM
Hi Dan,

All sorted... had one of my friends working on it and it looks great now,

Thank you...