I am new to wordpress and i'm creating a site using wordpress.
You can see the mock up page here http://www.site2preview.com/veejata/ver1/index.html
And i've changed the index.php as
<?php
get_header();
//get_template_part( 'loop', 'index' );
?>
<div class="flt_left">
//dummy welcome text ..
</div>
<div class="flt_left">
//dummy latest post..
</div>
<?php get_sidebar(); ?>
<?php get_advt(); ?>
<?php get_footer(); ?>
Now i want to know how to create a custom page or block and how can i include them in the index.page..
Also i want the user should be able to edit the dummy welcome text from the admin panel..
In general i want to how to split the contents in the wordpress and how to make them editable by admin and how to include them in the pages...
This is what you should have in your simple index.php file (from wordpress classic theme):
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_date('','<h2>','</h2>'); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?></a></h3>
<div class="meta"><?php _e("Filed under:"); ?> <?php the_category(',') ?>
— <?php the_tags(__('Tags: '), ', ', ' — '); ?>
<?php the_author() ?> #
<?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>
<div class="storycontent">
<?php the_content(__('(more...)')); ?>
</div>
<div class="feedback">
<?php wp_link_pages(); ?>
<?php comments_popup_link(__('Comments (0)'),
__('Comments (1)'), __('Comments (%)')); ?>
</div>
</div>
<?php comments_template(); // Get wp-comments.php template ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
I would suggest you to read this first: http://codex.wordpress.org/Theme_Development
Related
I'm using the following page template to display the posts in a single category and plan to format the first post differently than the others. This works as desired but I have the category_name hard coded in the template. I want to use this template for several different categories and would like to learn how to pass the category_name to the template from a link.
For example, the link to the desired page using the special template is http://wildcatweb.net/5th/ and '5th' is also the category_name. How do I tell the template to get the category_name from the URL and use it in the template?
<?php
/*
Template Name: pageAssignments
*/ ?>
<?php get_header(); ?>
<div class="small-12 large-8 columns" id="content" role="main">
<header>
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<!-- show latest post FULL -->
<?php query_posts('showposts=1&category_name=5th'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="lastest-post">
<h2 class="pagetitle"><?php the_title(); ?></h2>
<?php the_content(); ?>
</div><!--close .latest-post -->
<?php endwhile; endif; ?><!-- end lastest post -->
<!-- show older post excerpts -->
<?php query_posts('showposts=5&offset=1&category_name=5th'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="older-post">
<h3 class="pagetitle"><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
</div><!--.older-post -->
<?php endwhile; endif; ?><!-- end past-entry -->
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
try this :
$current_url = $_SERVER['PHP_SELF'];
$category_name = explode ('',$current_url);
$category_name = $category_name['3'];
query_posts('showposts=1&category_name='. $category_name);
I am currently using wordpress in creating my websites. And i really find a problem regarding pagination. So basically to be able for you to understand what is really my problem, I will post two codes:
This is the first code:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<?php include (TEMPLATEPATH.'/inc/meta.php'); ?>
<div class="entry">
<?php
the_excerpt();
?>
</div>
<br/><br/>
<h3>Read More...</h3>
</div>
<?php
endwhile;
?>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
In this lines of code, I used the regular loop in querying a post. Actually I did not modify the code. I also installed a plugin WP-PageNavi. There is no problem, pagination is working properly.
But when i put this line of code, about the regular loop. Pagination is not working properly. I put this line of code " " because I want only to show post in this said category.
2nd code:
Line of code
<?php query_posts('cat=8'); ?>
End line of code
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
<div class="entry">
<?php the_excerpt(); ?>
</div>
<br/><br/>
<h3>Read More...</h3>
</div>
<?php endwhile; ?>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
My question is: What should I do in order for the pagination to worked properly? I really need some help with this.
I think the problem is the because of the two The Loop(i.e while and endwhile loop) in a page.
instead of while use foreach loop. below is the example
<?php
$args = array('category' => '8');
$postArr = get_posts($args);
if($postArr){
foreach($postArr as $details){
?>
div <?php post_class() ?> id="post-<?php echo $details->ID; ?>">
<h2><?php echo $details->post_title; ?></h2>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
<div class="entry">
<?php echo $details->post_excerpt(); ?>
</div>
<br/><br/>
<h3>Read More...</h3>
</div>
<?php
}
}else{
?>
<h2>Not Found</h2>
<?php
}
?>
Note Code not tested...
What kind of WordPress function do you use to show the page contents?
I used the_content to show the post contents, but what about the page contents?
I have tried everything, but I haven't found a function that displays the page contents of WordPress.
Also, I have created a basic page.php file, and in the file I have:
<div id="pages">
<li><?php wp_list_pages() ?></li>
</div>
Now, why do my index.php have my list of pages even though I didn't use the inlcude or require function?
Keep in mind I created my own theme and site, and I'm trying to put it in WordPress for the first time.
Thanks!!
The function wp_list_pages() lists all the pages. If you want to list all the recent posts you should use
index.php
<?php get_header(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2 class="entry-title"><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; // end of the loop. ?>
<?php get_sidebar(); // If you have sidebar ?>
<?php get_footer(); ?>
page.php
<?php get_header(); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2 class="entry-title"><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; // end of the loop. ?>
<?php get_sidebar(); // If you have sidebar ?>
<?php get_footer(); ?>
Make sure you check the default twentyeleven and twentyten themes to get idea of how to code WordPress Themes.
I'm building a Wordpress template from an HTML page.
I currently have
<?php $queried_post = get_post( $_GET['id'], $output ); ?>
Then I use ...
<?php echo $queried_post->post_title; ?>
Which works fine for echoing the post title.
Then I try to echo the author with...
<?php echo $queried_post->post_author; ?>
I get back '1' which is not the author name. How is this done correctly?
Try this code:
<?php the_author($_GET['id']); ?>
Codex entry: http://codex.wordpress.org/Function_Reference/the_author
My single.php file:
<?php get_header(); ?>
<?php if (have_posts()): ?>
<?php while (have_posts()): the_post(); ?>
<div class="post post-single">
<h1 class="post-title">
<?php the_title(); ?>
<?php edit_post_link('Edit', '', ''); ?>
</h1>
<div class="content"><?php the_content(); ?></div>
</div>
<?php endwhile; else: ?>
There are no posts to display.
<?php endif; ?>
<?php get_footer(); ?>
I've created a custom page and it is set as my homepage, within this custom page I am pulling out the latest post from a specific category, I've also created a form of pagination which when clicked upon will take the user to single.php. My intention for the single.php is to have two custom loops.
Custom loop one
I want single.php to distinguish that it has came from the homepage and loop through all of the posts tagged with the same category as the one on the homepage.
Some of these posts will have to be tagged with more than one category, so the loop will have to know to ignore the other categories and just pay attention to the category in question. Does that make sense?
Custom loop two
If the user hasn't arrived from the homepage, single.php will just act as it normally does i.e, if the user comes from index.php (the blog) they will be taken to this second loop (blog post)
However I don't seem to be able to make the distinction between the two loops, I might be over complicating matters, as I've got a loop which wraps everything together and then I have a loop for my custom pagination.
Here is the code below to show you what I'm talking about
custompage.php (set to home) - This works just fine but I'll post it just incase anyone is able to tidy it up
<?php query_posts('cat=1'); ?>
<?php
$myPosts = new WP_Query();
$myPosts->query('showposts=1');
if (have_posts()) :
while ($myPosts->have_posts()) : $myPosts->the_post();
?>
<script type="text/javascript">$.backstretch("<?php $key="image"; echo get_post_meta($post->ID, $key, true);?>");</script>
<div id="post-<?php the_ID(); ?>" class="info">
<h2><?php the_title(); ?></h2>
<ul class="nav">
<?php query_posts('posts_per_page=1&offset=1'); the_post(); ?>
<li class="prev">Previous</li>
<?php wp_reset_query(); ?>
<li class="next"></li>
</ul>
</div>
<!-- end .info -->
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
single.php - Currently broken
<?php if( in_category('1') ) { ?>
<!-- start -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" class="info">
<script type="text/javascript">$.backstretch("<?php $key="image"; echo get_post_meta($post->ID, $key, true);?>");</script>
<h2><?php the_title(); ?></h2>
<ul class="nav">
<li class="prev"><?php previous_post_link('%link', ' ', 'true', '1') ?></li>
<li class="next"><?php next_post_link('%link', ' ', 'true', '1'); ?></li>
<!--li class="prev"><?php //previous_post_link('%link', '%title;', 'true', '1') ?></li>
<li class="next"><?php //next_post_link('%link', '%title;', 'true', '1'); ?></li-->
</ul>
</div>
<!-- end .info -->
<?php endwhile; else: ?>
<?php endif; ?>
<!-- end -->
<?php }else{ ?>
<div id="content" class="widecolumn" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_content('<p class="serif">Read the rest of this entry »</p>'); ?>
</div>
</div>
<?php comments_template(); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
</div>
<?php } ?>
The problem I seem to be running into is when a post has been tagged with two categories, wordpress doesn't seem to be able to make the distinction between the two categories and instead of carrying on to the next category it breaks and defaults to the second loop.
how about this?
HOMEPAGE
<?php
$myPosts = new WP_Query();
$myPosts->query('showposts=1&cat=1');
if (have_posts()) :
while ($myPosts->have_posts()) : $myPosts->the_post();
?>
<script type="text/javascript">$.backstretch("<?php $key="image"; echo get_post_meta($post->ID, $key, true);?>");</script>
<div id="post-<?php the_ID(); ?>" class="info">
<h2><?php the_title(); ?></h2>
<ul class="nav">
<?php query_posts('posts_per_page=1&offset=1'); the_post(); ?>
<li class="prev">Previous</li>
<?php wp_reset_query(); ?> <-- not sure if this will reset the overall query
<li class="next"></li>
</ul>
</div>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
the queryposts('cat=1') at the top of your query wont run with that category, the category would have to be set inside your custom query
$myPosts->query('showposts=1&cat=1');
the 2nd page (SINGLE.PHP) with 2 loops..
if the user is coming from the homepage to a single page you want to attach the current category to the query, without this wordpress (while on the singles page will default to loop through all posts)
so for the singles page would the below be any good?
<?php if( in_category('1') ) { ?>
<!-- your selected category -->
<!-- start -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" class="info">
<script type="text/javascript">$.backstretch("<?php $key="image"; echo get_post_meta($post->ID, $key, true);?>");</script>
<h2><?php the_title(); ?></h2>
<ul>
<php global $post;
$my_query = get_posts('numberposts=1&cat=1&offset=-1');
foreach($my_query as $post) :
setup_postdata($post);
$link = get_post_meta($post->ID, 'site-url', true); ?>
<li>
<php the_title(); ?>
</li>
<php endforeach; ?>
<php global $post;
$my_other_query = get_posts('numberposts=1&cat=1&offset=1');
foreach($my_other_query as $post) :
setup_postdata($post);
$link = get_post_meta($post->ID, 'site-url', true); ?>
<li>
<php the_title(); ?>
</li>
<php endforeach; ?>
</ul>
</div>
<!-- end .info -->
<?php endwhile; else: ?>
<?php endif; ?>
<!-- end -->
<?php }else{
include('standard-wp-singles-page-stuff.php');
} ?>
then once your singles page loads it will check for the current category in that post, if its in category 1, then it will load your custom loop, then it will loop through 2 posts, in the same category? giving you 2 links to other posts. also using an offset on that query should give you a link forward and a link backwards?
hope that helps..
fixing code layout.. didnt work too well :P