individuelles und professionelles Webdesign, Programmierung und Internetmarketing

List some pages with content in WordPress

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

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

ALWAYS BACKUP YOUR ORIGINAL FILES BEFORE MODIFYING!!

Related posts:

  1. List one latest post per category on frontpage view
    I will give you here a code to list only...
  2. list pages custom styling in arthemia category bar
    Some users of of arthemia theme would like to display...
  3. Category view in Arthemia optimized
    Question: Can you display headline & featured block to each...
  4. Add Adsense between some Posts in WordPress
    In WordPress on the frontpage you have normally a flow...
  5. List subcategories in category bar of arthemia theme
    In the WordPress theme Arthemia theme by Michael Jubel is...
11. January 2009 • Kategorie: Wordpress Tips Tags: , ,
These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Facebook
  • LinkedIn
  • TwitThis

JW ist Freelance Webdeveloper

Website Questions? Please ask in Webdesign Forum


You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

3 Kommentare »

  1. Thank you for this, it is exactly what I needed.

    As pages do not support excerpts like posts do, is there anyway to control what is displayed on the index page other than using the More tag?

  2. an easy way to truncate the_content would be:

    <?php echo substr(strip_tags($post->post_content), 0, 150);?>

    eg: strip all formatting and display just (here) 150 characters

    more possibilities you could find here:

    http://www.go41.de/218/anzahl-der-worte-in-the_excerpt-andern/

    or: you could also use a custom field ‘pagedesc’ and look up the content of this field in your query..

  3. Thank you.

Kommentieren

Interessante Links zu query pages with content

Add dynamic content to a page - SharePoint Server - Microsoft ...

You can customize the query that defines what content is displayed, and can customize the view ... After you add the Content Query Web Part to a page, you edit the Web Part to ...

Tags: dynamic, content, sharepoint, server,
Advanced Query Page (AQP)

The Advanced Query Page is a Conversant page type designed for two purposes, to allow ... This will be replaced with a link to each page of found messages. ...

Tags: advanced, query,
API:Query - Properties - MediaWiki

<api> <query> <pages> <page pageid="1191" ns="0" title="API" ... what was that for?"> ...content... </rev> </revisions> </page> </pages> </query> </api> ...

Tags: query, properties, mediawiki,
Highlight Search Terms Using jQuery

One way to spice up the search page is to highlight the search terms within the search results. The way described in this tutorial is using jQuery and will highlight both title and post content. Another way is not to use jQuery or using wordpress plugins which will not be describe in this tutorial.

Tags: highlight, search, terms, using,
20 awesome jQuery Examples to make website more interactive

Jquery example tutorial and source code for page navigation, content slider, form to make website more interactive and attractive

Tags: awesome, jquery, examples, website,
Austin Web Application Development - PHP, MySQL, & jQuery

Custom Website Applications I have developed everything from small one-page brochure style websites to complex content management systems for high traffic. Austin Web Design, website development, web development, hosting, austin web site design, Web Design Austin, austin web design, Austin Application Development, web software, application develop

Tags: austin, application, development, mysql,
WP 2.9 Sidebar ausblenden? / Seitentitel als Logo

...equiv="Content-Type" content="<?php ... php the_search_query(); ?>" name ... list_pages('sort_column=menu_order...

Tags: sidebar, ausblenden, seitentitel,
Meta Daten erstellen Teil 2 (CMS)

...dbpraefix;      $res = mysql_query("SELECT name, content ... res = mysql_query("UPDATE ".$dbpraefix."pages

Tags: daten, erstellen,
KINDERFAHRRAD 18" RAD FAHRRAD FLOTTE BIENE 434-FB-...

<HEAD> <TITLE>Version1</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> </HEAD>...

Tags: kinderfahrrad, fahrrad, flotte, biene,