2012-01-30 23 views
0

我想知道的是,我如何實現我已經制作的index.php文件來將自定義帖子應用到它。 (見下文)如何在WordPress中爲假人制作自定義帖子?

我想要完成的任務:

Display all posts(already accomplished in index.php) 
--> show normal post a.k.a 'Article' (already accomplished in index.php) 

If category/or post type 'Aside' is used, don't apply a <a> tag, make title lighter(can figure it out in CSS) 
-->show text for the 'Aside' marked post 

If category/or post type 'Link' is used, wrap title in <a> tag linking to a site(<-- how would I do that in WordPress?) 
-->show text for info about the link 

If category/or post type 'Photo' is used, don't wrap title in a <a> tag 
-->show attached image in post, and post text as a caption 

我知道這可能看起來很多,但我敢肯定,這很容易做到,能。

一些源代碼可能無法幫助我一路,所以我有我下面的index.php來看看你能不能幫我落實到它:

<?php get_header(); ?> 


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

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

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

      <article> 
      <!-- <p><span class="metaCat"><?php the_category(', '); ?></span></p> --> 
      <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h1> 
      <p><span class="meta"><?php the_time('F jS, Y') ?></span></p> 
      <hr /> 
      <div class="entry"> 
       <?php the_content('Read the rest of this entry &raquo;'); ?> 
      </div> 

     </div> 
</article> 
     <hr class="big" /> 
    <?php endwhile; ?> 



<?php else : ?> 

    <h2 class="center">Not Found</h2> 
    <p class="center">Sorry, but you are looking for something that isn't here.</p> 
    <?php include (TEMPLATEPATH . "/searchform.php"); ?> 

<?php endif; ?> 

如果你可以輸入所需代碼到一個可行的index.php文件中,你會得到一些思考布朗尼點!

謝謝,歡迎所有幫助!

回答

0

我終於明白你的意思了。這很容易使用get_post_format()函數完成。只是這裏替換標題:

<?php 
$format = get_post_format(get_the_ID()); 
if ($format == 'link') { ?> 
<h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h1> 
<?php }else{ ?> 
    <h1><?php the_title(); ?></h1> 
<?php } ?> 

其他一些有關鏈接到網站雖然,我不知道要如何實現這一目標。你指的是博客嗎?

「鏈接」帖子格式的最佳選擇是使用自定義的metabox /自定義字段。將您的密鑰添加爲「URL」,然後在值字段中輸入地址。

使用get_post_meta()獲取網址並在href中使用該網址而不是the_permalink()

+0

我沒有打擾回答,因爲大部分的話題都是在第一時間完成的。它不會花費太多的精力來完成那些寫在那裏的東西,並根據他們的需求來調整它們......更不用說對他們的查詢做出正確迴應了。我離題了 - 因爲第一個期望被破壞了,所以第二個期望會被破壞。您的回覆是準確的,但是缺少關於帖子格式鏈接到外部URI的部分。 (這將需要一些get_post_custom(get_the_ID())shenanigans)。 – 2012-01-30 15:21:47

+0

至於URL部分......我想要完成的是Tumblr基本上已經完成的工作。將網站/文章的鏈接作爲帖子的標題,就像我通過帖子分享它,並附上我的書面評論。 – 2012-01-31 01:39:47

相關問題