go41

List some pages with content in WordPress

von Joern am 11. Jan. 2009 | Keine Kommentare

To list pages in WordPress you normally take this: <?php wp_list_pages(); ?>

But how to display some pages with the_content or the_excerpt?

I didn’t find a way to query specified pages by page_id and run a foreach loop, so we are going to get the pages one by one in separate queries and loops for each page.

Important is to rewind the query after the run by inserting this: <?php rewind_posts();?>

A simple query for three different pages plus title and including the excerpt I show you here:

<?php
$my_page = new WP_Query("page_id=2"); //replace the ID of the page you want to show
$my_page->the_post();?>
<a href="<?php the_permalink() ?>" rel="bookmark" ><?php the_title(); ?></a>
<?php the_excerpt(); ?>
<?php rewind_posts();?>
<?php
$my_page = new WP_Query("page_id=41"); //replace the ID of the page you want to show
$my_page->the_post();?>
<a href="<?php the_permalink() ?>" rel="bookmark" ><?php the_title(); ?></a>
<?php the_excerpt(); ?>
<?php rewind_posts();?>
<?php
$my_page = new WP_Query("page_id=42"); //replace the ID of the page you want to show
$my_page->the_post();?>
<a href="<?php the_permalink() ?>" rel="bookmark" ><?php the_title(); ?></a>
<?php the_excerpt(); ?>
<?php rewind_posts();?>

Now, let’s say you want to display in Arthemia theme by Michael Jubel some pages in the featured section instead of featured posts, you have to modify index.php and replace the query for category Featured (ie:query_posts(„showposts=4&category_name=Featured“);) with a query for pages.

Just sime lines of code how it could look like:
<!– first new query start, here page_id=2, put your page ID ******************************* –>
<?php
$my_page = new WP_Query(„page_id=2″); //replace the 2 with the ID of the page you want to show
$my_page->the_post(); ?>

<div class=“clearfloat“>
<?php $values = get_post_custom_values(„Image“);
if (isset($values[0])) { ?>
<a href=“<?php the_permalink() ?>“ rel=“bookmark“ title=“Permanent Link to <?php the_title(); ?>“>
<img src=“<?php echo bloginfo(‚template_url‘); ?>/scripts/timthumb.php?src=<?php echo get_option(‚home‘); ?>/<?php
$values = get_post_custom_values(„Image“); echo $values[0]; ?>&w=100&h=65&zc=1&q=100″
alt=“<?php the_title(); ?>“ class=“left“ width=“100px“ height=“65px“ /></a>
<?php } ?>
<div class=“info“><a href=“<?php the_permalink() ?>“ rel=“bookmark“ class=“title“><?php the_title(); ?></a>
<?php the_excerpt(); ?>
</div>
</div>

<?php rewind_posts();?>
<!– next query start, put your page ID –>
<?php
$my_page = new WP_Query(„page_id=41″); //replace the ID of the page you want to show
$my_page->the_post(); ?>

<div class=“clearfloat“>
<?php $values = get_post_custom_values(„Image“);
if (isset($values[0])) { ?>
<a href=“<?php the_permalink() ?>“ rel=“bookmark“ title=“Permanent Link to <?php the_title(); ?>“>
<img src=“<?php echo bloginfo(‚template_url‘); ?>/scripts/timthumb.php?src=<?php echo get_option(‚home‘); ?>/<?php
$values = get_post_custom_values(„Image“); echo $values[0]; ?>&w=100&h=65&zc=1&q=100″
alt=“<?php the_title(); ?>“ class=“left“ width=“100px“ height=“65px“ /></a>
<?php } ?>
<div class=“info“><a href=“<?php the_permalink() ?>“ rel=“bookmark“ class=“title“><?php the_title(); ?></a>
<?php the_excerpt(); ?>
</div>
</div>

<?php rewind_posts();?>

<!– next query start, put your page ID –>

I give you a complete modified index.php for Arthemia theme here to download:

arthemia index.php modified to dispay pages in featured section (file removed from server…)

Take the parts in div id=“featured“ or use the whole file as index.php replacement.

ALWAYS BACKUP YOUR ORIGINAL FILES BEFORE MODIFYING!!

query pages with content In standard English, a query means a request for information. In computer programming, it refers to the same thing, except the information is retrieved from a database. However, writing a query requires a set of query La requête, sous la forme d'une chaîne de caractères . Avertissement Avertissement de Sécurité : injection SQL Si la requête contiens des variables d'entrées alors des déclarations préparées paramétrisées devrait être utilisé à la Microsoft Power pour Excel est un nouvel complément qui offre une expérience transparente pour la découverte et la transformation de données, et un enrichissement pour les utilisateurs professionnels, les professionnels BI et d'autres utilisateurs Query - definition of query 1. A question; an inquiry. 2. A doubt in the mind; a mental reservation. 3. A notation, usually a question mark, calling attention to an item in order to question its validity or accuracy. tr.v. Tags: query, definition, query, PDO::() prépare et exécute une requête SQL en un seul appel de fonction, retournant la requête en tant qu'objet PDOStatement. Pour une requête que vous devez exécuter plusieurs fois, vous réaliserez de meilleures performances si

Autor:

Du findest mich auch auf Twitter und Facebook!

Schreibe einen Kommentar

Pflichtfelder sind mit * markiert.


Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.