New Category Page Designing : Wordpress
12-20-2010, 04:16 AM
|
New Category Page Designing : Wordpress
|
Posts: 173
Name: Abdullah Saleem
|
Hi,
I'm trying to design my category page as my homepage, but Its posting homepage posts not the category's own post. Here is the code for that :
PHP Code:
<?php get_header(); ?>
<div id="content">
<div class="homecol1">
<?php $my_query = new WP_Query('showposts=1&offset=0'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div style="background: #FFFFFF;
border: 1px solid #C8C8C8;
-moz-border-radius: 0 0 15px 0;
-webkit-border-radius: 0 0 15px 0;
-khtml-border-radius: 0 0 15px 0;
border-radius: 0 0 15px 0;
-moz-box-shadow: 3px 3px 10px 0 #464646;
-webkit-box-shadow: 3px 3px 10px 0 #464646;
-khtml-box-shadow: 3px 3px 10px 0 #464646;
box-shadow: 3px 3px 10px 0 #464646;
padding: 0px 15px 0px 15px; ">
<h1 class="mainitem"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>
<?php if ( get_post_meta($post->ID, 'Image', true) ) { ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php echo get_post_meta($post->ID, "Image", true); ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?> <?php _e('thumbnail'); ?>" align="top" border="0" style="padding: 0px; margin: 0px 0px 0px 0px;width: 380px; height: 232px;"/></a>
<?php } else { ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/default.gif" title="<?php the_title(); ?>" alt="<?php the_title(); ?>" align="top" border="0" style="padding: 0px; margin: 0px 0px 0px 0px;width: 380px; height: 232px;"/></a>
<?php } ?>
<?php the_content_limit(170, ""); ?></div>
<?php endwhile; ?>
<br />
<div class="linksbox">
<a class="linksbox" href="<?php $lbox1url = get_option('stylewp_lbox1url'); echo $lbox1url; ?>" title="<?php $lbox1txt = get_option('stylewp_lbox1txt'); echo $lbox1txt; ?>"><?php $lbox1txt = get_option('stylewp_lbox1txt'); echo $lbox1txt; ?></a> |
<a class="linksbox" href="<?php $lbox2url = get_option('stylewp_lbox2url'); echo $lbox2url; ?>" title="<?php $lbox2txt = get_option('stylewp_lbox2txt'); echo $lbox2txt; ?>"><?php $lbox2txt = get_option('stylewp_lbox2txt'); echo $lbox2txt; ?></a> |
<a class="linksbox" href="<?php $lbox3url = get_option('stylewp_lbox3url'); echo $lbox3url; ?>" title="<?php $lbox3txt = get_option('stylewp_lbox3txt'); echo $lbox3txt; ?>"><?php $lbox3txt = get_option('stylewp_lbox3txt'); echo $lbox3txt; ?></a><br />
<a class="linksbox" href="<?php $lbox4url = get_option('stylewp_lbox4url'); echo $lbox4url; ?>" title="<?php $lbox4txt = get_option('stylewp_lbox4txt'); echo $lbox4txt; ?>"><?php $lbox4txt = get_option('stylewp_lbox4txt'); echo $lbox4txt; ?></a> |
<a class="linksbox" href="<?php $lbox5url = get_option('stylewp_lbox5url'); echo $lbox5url; ?>" title="<?php $lbox5txt = get_option('stylewp_lbox5txt'); echo $lbox5txt; ?>"><?php $lbox5txt = get_option('stylewp_lbox5txt'); echo $lbox5txt; ?></a> |
<a class="linksbox" href="<?php $lbox6url = get_option('stylewp_lbox6url'); echo $lbox6url; ?>" title="<?php $lbox6txt = get_option('stylewp_lbox6txt'); echo $lbox6txt; ?>"><?php $lbox6txt = get_option('stylewp_lbox6txt'); echo $lbox6txt; ?></a>
</div>
<div id="col1split">
<h1 class="splitblock"><?php $haveyouread = get_option('stylewp_haveyouread'); echo $haveyouread; ?></h1>
<div class="col1split_left">
<?php $my_query = new WP_Query('showposts=1&offset=1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php if ( get_post_meta($post->ID, 'Image', true) ) { ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php echo get_post_meta($post->ID, "Image", true); ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?> <?php _e('thumbnail'); ?>" align="top" border="0" style="padding: 0px; margin: 10px 0px 0px 0px;width: 203px; height: 110px;"/></a>
<?php } else { ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/default.gif" title="<?php the_title(); ?>" alt="<?php the_title(); ?>" align="top" border="0" style="padding: 0px; margin: 10px 0px 0px 0px;width: 203px; height: 110px;"/></a>
<?php } ?>
<h1 class="splititem"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>
<?php the_content_limit(110, ""); ?>
<?php endwhile; ?>
</div>
<div class="col1split_right">
<?php $my_query = new WP_Query('showposts=1&offset=2'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php if ( get_post_meta($post->ID, 'Image', true) ) { ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php echo get_post_meta($post->ID, "Image", true); ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?> <?php _e('thumbnail'); ?>" align="top" border="0" style="padding: 0px; margin: 10px 0px 0px 0px;width: 203px; height: 110px;"/></a>
<?php } else { ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/default.gif" title="<?php the_title(); ?>" alt="<?php the_title(); ?>" align="top" border="0" style="padding: 0px; margin: 10px 0px 0px 0px;width: 203px; height: 110px;"/></a>
<?php } ?>
<h1 class="splititem"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>
<?php the_content_limit(110, ""); ?>
<?php endwhile; ?>
</div>
</div>
<div style="clear:both;"></div>
<?php
$cat = get_option('stylewp_fl1l');
$the_query = new WP_Query('category_name=' . $cat . '&showposts=1&offset=0&orderby=post_date&order=desc');
$counter = 0;
while ($the_query->have_posts()) : $the_query->the_post(); $do_not_duplicate = $post->ID;
?>
<h1 class="splitblock"><?php the_category(' | ') ?></h1>
<div style="background: #FFFFFF;
border: 1px solid #C8C8C8;
-moz-border-radius: 0 0 10px 10px;
-webkit-border-radius: 0 0 10px 10px;
-khtml-border-radius: 0 0 10px 10px;
border-radius: 0 0 10px 10px;
-moz-box-shadow: 2px 2px 5px #464646;
-webkit-box-shadow: 2px 2px 5px #464646;
-khtml-box-shadow: 2px 2px 5px #464646;
box-shadow: 2px 2px 5px #464646;
padding: 0px 15px 0px 15px;">
<?php if ( get_post_meta($post->ID, 'Image', true) ) { ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php echo get_post_meta($post->ID, "Image", true); ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?> <?php _e('thumbnail'); ?>" align="left" border="0" style="padding: 0px; margin: 10px 10px 10px 0px;width: 134px; height: 75px;"/></a>
<?php } else { ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/default.gif" title="<?php the_title(); ?>" alt="<?php the_title(); ?>" align="left" border="0" style="padding: 0px; margin: 10px 10px 10px 0px;width: 134px; height: 75px;"/></a>
<?php } ?>
<h1 class="splititem"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>
<?php the_content_limit(120, ""); ?>
<?php endwhile; ?>
</div>
<br />
<div style="background: #ffffff;
border: 1px solid #C8C8C8;
-moz-border-radius: 5px 5px 5px 5px;
-webkit-border-radius: 5px 5px 5px 5px;
-khtml-border-radius: 5px 5px 5px 5px;
border-radius: 5px 5px 5px 5px;
padding: 5px 3px 5px 3px;">
<center><?php $banner2 = get_option('stylewp_banner2'); echo stripslashes($banner2); ?></center>
</div>
<br /><br />
<?php sfc_fanbox(); ?>
<div style="border-bottom:1px dotted #cccccc; margin-bottom:5px; padding:0px 0px 10px 0px; clear:both;"></div>
<div style="background: #ffffff;
border: 1px solid #C8C8C8;
-moz-border-radius: 5px 5px 5px 5px;
-webkit-border-radius: 5px 5px 5px 5px;
-khtml-border-radius: 5px 5px 5px 5px;
border-radius: 5px 5px 5px 5px;
padding: 5px 3px 5px 3px;">
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<script src="jquery.bxSlider.min.js" type="text/javascript"></script>
<script src="lib.js" type="text/javascript"></script>
<!--content slider-->
<ul id="slides1">
<!--Slider Image & Content-->
<li>
<div class="content" id="imgslider0">
<p><strong>Lorem Ipsum</strong><br />
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam elit est, varius blandit semper vestibulum. </p>
</div>
<div class="clear"></div>
</li>
<!--END Slider Image & Content-->
<!--Slider Image & Content-->
<li>
<div class="content" id="imgslider1">
<p><strong>Lorem Ipsum</strong><br />
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam elit est, varius blandit semper vestibulum. </p>
</div>
<div class="clear"></div>
</li>
<!--END Slider Image & Content-->
<!--Slider Image & Content-->
<li>
<div class="content" id="imgslider2">
<p><strong>Lorem Ipsum</strong><br />
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam elit est, varius blandit semper vestibulum. </p>
</div>
<div class="clear"></div>
</li>
<!--END Slider Image & Content-->
<!--Slider Image & Content-->
<li>
<div class="content" id="imgslider3">
<p><strong>Lorem Ipsum</strong><br />
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam elit est, varius blandit semper vestibulum. </p>
</div>
<div class="clear"></div>
</li>
<!--END Slider Image & Content-->
</ul>
<!--end content slider-->
</div>
</div>
<div class="homecol2">
<?php if ( $showtvtab = get_option('stylewp_showtvtab') ) { ?>
<div style="background: #ffffff;
border: 1px solid #C8C8C8;
-moz-border-radius: 5px 5px 5px 5px;
-webkit-border-radius: 5px 5px 5px 5px;
-khtml-border-radius: 5px 5px 5px 5px;
border-radius: 5px 5px 5px 5px;
padding: 5px 3px 5px 3px;">
<div class="coveragetab">
<center><h3><?php $matchinfo = get_option('stylewp_matchinfo'); echo $matchinfo; ?></h3></center>
<center><b>Watch live coverage at <a href="http://www.cricpak.5gigs.net/live-tv.html">Cricpak - Live TV</a></b></center>
</div>
</div>
<br />
<?php } else { ?>
<?php } ?>
<div style="background-image: url('http://www.cricpak.5gigs.net/wp-content/uploads/2010/12/countdown_background.png');
border: 1px solid #C8C8C8;
-moz-border-radius: 5px 5px 5px 5px;
-webkit-border-radius: 5px 5px 5px 5px;
-khtml-border-radius: 5px 5px 5px 5px;
border-radius: 5px 5px 5px 5px;
padding: 5px 3px 5px 3px;
height: 116px;">
<img src="http://www.cricpak.5gigs.net/wp-content/uploads/2010/12/wc_logo.png" width="200" height="25" alt="ICC Cricket World Cup 2011">
<br /><br />
<div class="coveragetab"><?php show_countdown(); ?></div>
<br />
<span class="countlink"><a href="http://www.cricpak.5gigs.net/icc-cricket-world-cup-2011/fixtures/" target="_blank" align="left" title="Cricket World Cup 2011 Fixture" alt="ICC Cricket World Cup 2011 Fixtures">View all fixtures</a></span>
</div>
<br />
<div class="latestlistbar">
<?php $newslink1 = get_option('stylewp_newslink1'); echo $newslink1; ?> | <a class="barlink" href="<?php $newslink2url = get_option('stylewp_newslink2url'); echo $newslink2url; ?>"><?php $newslink2 = get_option('stylewp_newslink2'); echo $newslink2; ?></a> | <a class="barlink" href="<?php $newslink3url = get_option('stylewp_newslink3url'); echo $newslink3url; ?>"><?php $newslink3 = get_option('stylewp_newslink3'); echo $newslink3; ?></a>
</div>
<ul class="latest">
<?php $my_query = new WP_Query('showposts=10&offset=3'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li class="latestlist"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
<div style="background: #ffffff;
border: 1px solid #C8C8C8;
-moz-border-radius: 5px 5px 5px 5px;
-webkit-border-radius: 5px 5px 5px 5px;
-khtml-border-radius: 5px 5px 5px 5px;
border-radius: 5px 5px 5px 5px;
padding: 5px 3px 5px 3px;">
<?php $banner4 = get_option('stylewp_banner4'); echo stripslashes($banner4); ?>
</div>
<br />
<div style="background: #FFFFFF;
border: 1px solid #C8C8C8;
-moz-border-radius: 10px 0;
-webkit-border-radius: 10px 0;
-khtml-border-radius: 10px 0;
border-radius: 10px 0;
-moz-box-shadow: 2px 2px 5px #464646;
-webkit-box-shadow: 2px 2px 5px #464646;
-khtml-box-shadow: 2px 2px 5px #464646;
box-shadow: 2px 2px 5px #464646;
padding: 0px 7px 0px 7px;">
<br />
<div class="contenthead">BBC Cricket - RSS</div>
<?php include('rss/rss.php'); ?>
</div>
<br />
<div class="ad300">
<?php $banner3 = get_option('stylewp_banner3'); echo stripslashes($banner3); ?>
</div>
<div style="background: #FFFFFF;
border: 1px solid #C8C8C8;
-moz-border-radius: 10px 0;
-webkit-border-radius: 10px 0;
-khtml-border-radius: 10px 0;
border-radius: 10px 0;
-moz-box-shadow: 2px 2px 7px #464646;
-webkit-box-shadow: 2px 2px 7px #464646;
-khtml-box-shadow: 2px 2px 7px #464646;
box-shadow: 2px 2px 7px #464646;
padding: 0px 15px 0px 15px;">
<div class="contenthead"><p><?php $pbtitle = get_option('stylewp_pbtitle'); echo $pbtitle; ?></p></div>
<a href="<?php $pburl = get_option('stylewp_pburl'); echo $pburl; ?>"><img src="<?php $pbimg = get_option('stylewp_pbimg'); echo $pbimg; ?>" alt="<?php $pbalt = get_option('stylewp_pbalt'); echo $pbalt; ?>" style="border:0; width: 265px;" /></a>
<font="Tahoma" size="2"><?php $pbalt = get_option('stylewp_pbalt'); echo $pbalt; ?></font> <font style="Tahoma" color="#C8C8C8" size="1"><?php $pbcpy = get_option('stylewp_pbcpy'); echo $pbcpy; ?></font>
<br /><br />
</div>
<br />
<div class="ad300">
<div id="col2split">
<div class="latestlistbar">
<?php $ptitle = get_option('stylewp_ptitle'); echo $ptitle; ?>
</div>
</div>
<div class="col2split_left">
<a href="<?php $p1url = get_option('stylewp_p1url'); echo $p1url; ?>"><img src="<?php $p1img = get_option('stylewp_p1img'); echo $p1img; ?>" alt="<?php $p1txt = get_option('stylewp_p1txt'); echo $p1txt; ?>" align="top" border="0" style="padding: 0px; margin: 0px 0px 0px 0px;width: 147px; height: 80px;"/></a>
<h1 class="splititem"><a href="<?php $p1url = get_option('stylewp_p1url'); echo $p1url; ?>"><?php $p1h1 = get_option('stylewp_p1h1'); echo $p1h1; ?></a></h1>
<p><?php $p1txt = get_option('stylewp_p1txt'); echo $p1txt; ?></p>
</div>
<div class="col2split_right">
<a href="<?php $p2url = get_option('stylewp_p2url'); echo $p2url; ?>"><img src="<?php $p2img = get_option('stylewp_p2img'); echo $p2img; ?>" alt="<?php $p2txt = get_option('stylewp_p2txt'); echo $p2txt; ?>" align="top" border="0" style="padding: 0px; margin: 0px 0px 0px 0px;width: 147px; height: 80px;"/></a>
<h1 class="splititem"><a href="<?php $p2url = get_option('stylewp_p2url'); echo $p2url; ?>"><?php $p2h1 = get_option('stylewp_p2h1'); echo $p2h1; ?></a></h1>
<p><?php $p2txt = get_option('stylewp_p2txt'); echo $p2txt; ?></p>
</div>
</div>
<div style="clear:both;"></div>
<h1 class="sponsors"><?php $sponsoredby = get_option('stylewp_sponsoredby'); echo $sponsoredby; ?></h1>
<div class="ad300b">
<?php $banner5 = get_option('stylewp_banner5'); echo stripslashes($banner5); ?>
</div>
</div>
<div class="homecol3">
<?php if (function_exists('vote_poll') && !in_pollarchive()): ?>
<div class="poll">
<?php get_poll();?>
</div>
<?php endif; ?>
<?php if ( $showvideo = get_option('stylewp_showvideo') ) { ?>
<div class="video">
<div style="background: #FFFFFF;
border: 1px solid #C8C8C8;
-moz-border-radius: 10px 0;
-webkit-border-radius: 10px 0;
-khtml-border-radius: 10px 0;
border-radius: 10px 0;
-moz-box-shadow: 2px 2px 7px #464646;
-webkit-box-shadow: 2px 2px 7px #464646;
-khtml-box-shadow: 2px 2px 7px #464646;
box-shadow: 2px 2px 7px #464646;
padding: 0px 7px 0px 7px;">
<div class="contenthead"><br />Featured Video</div>
<br />
<center><?php $featuredvideo = get_option('stylewp_featuredvideo'); echo stripslashes($featuredvideo); ?></center>
<br />
</div>
</div>
<?php } else { ?>
<?php } ?>
<?php if ( $showpages = get_option('stylewp_showpages') ) { ?>
<div style="background: #FFFFFF;
border: 1px solid #C8C8C8;
-moz-border-radius: 10px 0;
-webkit-border-radius: 10px 0;
-khtml-border-radius: 10px 0;
border-radius: 10px 0;
-moz-box-shadow: 2px 2px 7px #464646;
-webkit-box-shadow: 2px 2px 7px #464646;
-khtml-box-shadow: 2px 2px 7px #464646;
box-shadow: 2px 2px 7px #464646;
padding: 0px 7px 0px 7px;">
<div class="contenthead"><br />Stay connected</div>
<?php if ( $showfb = get_option('stylewp_showfb') ) { ?>
</br>
<center><a href="<?php $fbpage = get_option('stylewp_fbpage'); echo $fbpage; ?>"><img src="http://www.cricpak.5gigs.net/images/find_us_on_facebook.jpg" alt="Find us on Facebook" style="border:0; width: 220px; height: 65px;" /></a></center>
<br />
<?php } else { ?>
<?php } ?>
<?php if ( $showtw = get_option('stylewp_showtw') ) { ?>
<br />
<center><a href="<?php $twpage = get_option('stylewp_twpage'); echo $twpage; ?>"><img src="http://www.cricpak.5gigs.net/images/follow twitter.jpg" alt="Follow us on Twitter" style="border:0; width: 220px; height: 65px;" /></a></center>
<br />
<?php } else { ?>
<?php } ?>
</div>
<br />
<?php } else { ?>
<?php } ?>
<div style="background: #ffffff;
border: 1px solid #C8C8C8;
-moz-border-radius: 5px 5px 5px 5px;
-webkit-border-radius: 5px 5px 5px 5px;
-khtml-border-radius: 5px 5px 5px 5px;
border-radius: 5px 5px 5px 5px;
padding: 5px 3px 5px 3px;">
<script type='text/javascript' src="http://www.conduit-banners.com/Chat/?ctid=CT1871326&BannerType=chat_4&setup=true&culture=en"></script>
</div>
<br />
<?php if ( $show10 = get_option('stylewp_show10') ) { ?>
<div class="col3promo">
<?php $banner10 = get_option('stylewp_banner10'); echo stripslashes($banner10); ?>
</div>
<br />
<?php } else { ?>
<?php } ?>
<div style="background: #ffffff;
border: 1px solid #C8C8C8;
-moz-border-radius: 5px 5px 5px 5px;
-webkit-border-radius: 5px 5px 5px 5px;
-khtml-border-radius: 5px 5px 5px 5px;
border-radius: 5px 5px 5px 5px;
padding: 7px 3px 7px 3px;">
<center><?php $banner12 = get_option('stylewp_banner12'); echo stripslashes($banner12); ?></center>
</div>
<br />
<div style="background: #FFFFFF;
border: 1px solid #C8C8C8;
-moz-border-radius: 10px 0;
-webkit-border-radius: 10px 0;
-khtml-border-radius: 10px 0;
border-radius: 10px 0;
-moz-box-shadow: 2px 2px 7px #464646;
-webkit-box-shadow: 2px 2px 7px #464646;
-khtml-box-shadow: 2px 2px 7px #464646;
box-shadow: 2px 2px 7px #464646;
padding: 0px 15px 0px 15px;">
<div class="contenthead"><br />Poll</div>
<?php upm_polls() ?>
</div>
</div>
<br />
<table style="font-size: 9px; color: #888888; text-decoration: none; font-family: Verdana"><tr><td><script type='text/javascript' src="http://www.conduit-banners.com/Standard/?ctid=CT1871326&BannerType=horizontal_234X60_6&setup=true&culture=en&version=2"></script></td></tr></table>
<br />
<center><?php sfc_activity_feed(); ?></center>
</div>
<?php get_footer(); ?>
First of all, try to do with main post. First, I know I have to get category name by php. But, the problem is that I'm learner of PHP
HELP ME...!!!
__________________
"Think 100 times before you take a decision, But once that decision is taken, stand by it as one man." - Quaid-e-Azam
|
|
|
|
12-20-2010, 04:32 AM
|
Re: New Category Page Designing : Wordpress
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
You need to specify that you only want posts belonging to that category in the WP_Query constructor.
http://codex.wordpress.org/Template_...ory_Parameters
Note that the query_posts function and the constructor for WP_Query take the same arguments.
Assuming the id of the category is 1 you would need to change this:
PHP Code:
<?php $my_query = new WP_Query('showposts=1&offset=0'); ?>
to
PHP Code:
<?php $my_query = new WP_Query('posts_per_page=1&cat=1'); ?>
Notice that I changed showposts to posts_per_page. showposts is deprecated. I also removed offset since you don't need to specify if the offset is 0.
|
|
|
|
12-20-2010, 06:13 AM
|
Re: New Category Page Designing : Wordpress
|
Posts: 173
Name: Abdullah Saleem
|
@Null Pointer : It'd return the post of cat=1
I want the category to get id itself and show that category's posts.
__________________
"Think 100 times before you take a decision, But once that decision is taken, stand by it as one man." - Quaid-e-Azam
|
|
|
|
12-20-2010, 06:20 AM
|
Re: New Category Page Designing : Wordpress
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
So you want to set your homepage to a specific category page, but you don't want to specify the category?
Either there is something I'm missing or this isn't possible. The only way wordpress knows to fetch posts from a particular category is if the category is explicitly specified in the code (as I demonstrated) or if the category is specified in the url (which wouldn't be the case for the homepage).
|
|
|
|
12-20-2010, 06:31 AM
|
Re: New Category Page Designing : Wordpress
|
Posts: 173
Name: Abdullah Saleem
|
No, I don't want to change my homepage main post. As, title of the post suggests, that I'm designing a new category page. That's why, I'm asking you that it should get category id on its own.
I want to post category posts in category page(not the HomePage).
__________________
"Think 100 times before you take a decision, But once that decision is taken, stand by it as one man." - Quaid-e-Azam
|
|
|
|
12-20-2010, 06:55 AM
|
Re: New Category Page Designing : Wordpress
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
Quote:
Originally Posted by asmalik12
No, I don't want to change my homepage main post. As, title of the post suggests, that I'm designing a new category page. That's why, I'm asking you that it should get category id on its own.
I want to post category posts in category page(not the HomePage).
|
I was going off of what you said here:
Quote:
Originally Posted by asmalik12
I'm trying to design my category page as my homepage
|
Wordpress generates the query for you based on the url. If for whatever reason you need to modify the query you can get the current category by calling:
PHP Code:
get_the_category()
prior to creating a new query object (or calling query_posts).
Alternatively you can get the current query from the existing wp_query object and adjust it as needed:
PHP Code:
global $wp_query;
$query = $wp_query->query_vars;
$query['showposts'] = 1;
query_posts($query);
Here is some documentation:
http://codex.wordpress.org/Function_...ce/query_posts
http://codex.wordpress.org/Function_Reference/WP_Query
http://codex.wordpress.org/Function_...t_the_category
Last edited by NullPointer; 12-20-2010 at 07:10 AM..
|
|
|
|
12-20-2010, 09:23 AM
|
Re: New Category Page Designing : Wordpress
|
Posts: 173
Name: Abdullah Saleem
|
@NullPointer : Kindly adjust it for me as I'm not a PHP expert.
How to use get_the_category ($id) ?
Kindly do it for the first post, I'll try it for others.
Should I post the current code (I'm using currently), here? Would it be helpful?
PHP Code:
<?php get_header(); ?>
<div id="content_inner">
<h1 class="inneritem"><?php single_cat_title(''); ?> News</h1>
<div style="border-bottom:1px solid #dddddd; margin: 0px 13px 0px 35px; clear:both;"></div>
<div class="innercol1">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1 class="cat_item"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>
<div id="toolbox">
<div class="tools_date">
<p><?php $publishedon = get_option('stylewp_publishedon'); echo $publishedon; ?> <?php the_time('F j, Y'); ?></p>
</div>
<div class="tools_options">
<p>
<img src="<?php bloginfo('template_directory'); ?>/images/icon_comment.gif" alt="comment" style="vertical-align:middle;border:0;margin: 0px 2px 4px 0px;"><?php comments_number('No Comments','1 Comment','% Comments'); ?>
</p>
</div>
</div>
<?php if ( get_post_meta($post->ID, 'Image', true) ) { ?>
<img src="<?php echo get_post_meta($post->ID, "Image", true); ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?> <?php _e('thumbnail'); ?>" align="right" style="border-left: 1px solid #cccccc; padding: 0px 0px 0px 20px; margin: 10px 0px 10px 20px;width: 300px; height: 169px;"/>
<?php } else { ?>
<?php } ?>
<?php the_excerpt(__('Keep Reading'));?><br />
<div style="border-bottom:1px solid #dddddd; margin-bottom:5px; padding:0px 0px 10px 0px; clear:both;"></div>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<p><?php posts_nav_link(' — ', __('« Previous Page'), __('Next Page »')); ?></p>
</div>
<div class="innercol2">
<div class="ad300">
<?php $banner4 = get_option('stylewp_banner4'); echo stripslashes($banner4); ?>
</div>
<h1 class="sidetitle"><?php $sidelatest = get_option('stylewp_sidelatest'); echo $sidelatest; ?></h1>
<ul>
<?php
$sidebarlatest = get_option('stylewp_sidebarlatest');
$the_query = new WP_Query('showposts=' . $sidebarlatest . '&offset=0&orderby=post_date&order=desc');
$counter = 0;
while ($the_query->have_posts()) : $the_query->the_post(); $do_not_duplicate = $post->ID;
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
</div>
</div>
<?php get_footer(); ?>
__________________
"Think 100 times before you take a decision, But once that decision is taken, stand by it as one man." - Quaid-e-Azam
Last edited by asmalik12; 12-20-2010 at 09:25 AM..
|
|
|
|
12-20-2010, 09:30 AM
|
Re: New Category Page Designing : Wordpress
|
Posts: 457
Name: Randy
Location: Northern Wisconsin
|
Quote:
|
No, I don't want to change my homepage main post. As, title of the post suggests, that I'm designing a new category page. That's why, I'm asking you that it should get category id on its own.
|
If you are looking to design a page for a specific category you can alternately create a "category-(your-category-slug).php" file OR "category-(the cat ID).php.
For instance, a category page file name for "Piano Lessons" could be:
category-piano-lessons.php
Wordpress knows then to use that template file(see link below) as the template for that category. Therefore, you don't need to "tell" it to look for a specific cat ID, etc. before pulling the posts data.
Otherwise, as NullPointer pointed out, wordpress needs something to tell it what to get from the database.
See here for template hierarchy info:
http://codex.wordpress.org/Template_Hierarchy
|
|
|
|
12-20-2010, 10:25 AM
|
Re: New Category Page Designing : Wordpress
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
If you replace
PHP Code:
$my_query = new WP_Query('showposts=1&offset=0');
with
PHP Code:
global $wp_query;
$query = $wp_query->query_vars;
$query['showposts'] = 1;
$query['offset'] = 0;
$my_query = new WP_Query($query);
it should work.
I noticed that you're creating a new query object for each post. In other words you're executing a separate query for every post.
I recommend you go over some of the documentation:
http://codex.wordpress.org/The_Loop
|
|
|
|
12-22-2010, 05:26 AM
|
Re: New Category Page Designing : Wordpress
|
Posts: 173
Name: Abdullah Saleem
|
Thanks, Null Pointer, It worked. 
__________________
"Think 100 times before you take a decision, But once that decision is taken, stand by it as one man." - Quaid-e-Azam
|
|
|
|
|
« Reply to New Category Page Designing : Wordpress
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|