WordPressに関する情報や技術紹介です

Una vista única de cada artículo subcategoría

Se examinaron, porque queríamos mostrar el estado de la actualización de un conjunto de artículos cada subcategoría de la página de la categoría principal.
( Página traté de practicar aquí. )

Sacar el artículo para especificar una subcategoría se encontró que la siguiente etiqueta en la plantilla.

query_posts ('argumento')

Capacidad para recuperar los datos para esa condición lo hace dando un argumento a la etiqueta anterior.

posts_per_page (entero)
Número de páginas para recuperar
cat (entero)
(Puede especificar varios valores separados por comas) categoría de identificación para obtener

Hay otro omitido.
Intentado utilizar efectivamente como se describe a continuación.

<ul>
<?php if (have_posts()) : query_posts('posts_per_page=ページ数&amp;cat=カテゴリID&amp;orderby=並べる基準の項目&amp;order=並び順');  ?>
<?php while (have_posts()) : the_post(); ?>
	ループ内の処理
<?php endwhile; endif; wp_reset_query(); ?>
</ul>

不満はカテゴリIDを直接指定しなくてはいけない事。
出来ればサブカテゴリのIDを全て取得→ループさせながら上記のhtmlを出力、というのが理想だったけどサブカテゴリのID取得方法が分からず断念・・・。

上記解決方法 追記

(2008年8月18日 追記:上記方法は、 こちらの記事でで試してみた。一応成功。)

解決方法 追記-end

それが出来ればサブカテゴリが増えても自動で追加されるから便利なんだけど・・・。
仕方ないので一つずつカテゴリIDを指定して出力(サブカテゴリの数だけ同じものを書かなくてはいけない)。
以下が実際のソース。

<h3><a href="<?php bloginfo('wpurl') ?>/install">インストール</a></h3>
<ul>
<?php if (have_posts()) :  query_posts('posts_per_page=5&amp;cat=4&amp;orderby=ID&amp;order=desc');  ?>
<?php while (have_posts()) : the_post(); ?>
	<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
</ul>

<h3><a href="<?php bloginfo('wpurl') ?>/setting">ブログ設定</a></h3>
<ul>
<?php if (have_posts()) :  query_posts('posts_per_page=5&amp;cat=5&amp;orderby=ID&amp;order=desc');  ?>
<?php while (have_posts()) : the_post(); ?>
	<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
</ul>

<h3><a href="<?php bloginfo('wpurl') ?>/design">デザイン</a></h3>
<ul>
<?php if (have_posts()) :  query_posts('posts_per_page=5&amp;cat=7&amp;orderby=ID&amp;order=desc');  ?>
<?php while (have_posts()) : the_post(); ?>
	<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
</ul>

<h3><a href="<?php bloginfo('wpurl') ?>/template-tag">テンプレートタグ</a></h3>
<ul>
<?php if (have_posts()) :  query_posts('posts_per_page=5&amp;cat=8&amp;orderby=ID&amp;order=desc');  ?>
<?php while (have_posts()) : the_post(); ?>
	<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
</ul>

ダラダラ書いてるけど違うのは「cat=XX」の箇所だけ。あとサブカテゴリのタイトルかな。

タグ
, ,
トラックバックURL

Leave a Reply

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

*

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

ページTOPに戻る